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 51540Skini * Common Development and Distribution License (the "License"). 61540Skini * 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 /* 226313Skrishnae * Copyright 2008 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 #include <sys/types.h> 290Sstevel@tonic-gate #include <sys/kmem.h> 300Sstevel@tonic-gate #include <sys/conf.h> 310Sstevel@tonic-gate #include <sys/ddi.h> 320Sstevel@tonic-gate #include <sys/sunddi.h> 336313Skrishnae #include <sys/sunndi.h> 3427Sjchu #include <sys/fm/protocol.h> 3527Sjchu #include <sys/fm/util.h> 360Sstevel@tonic-gate #include <sys/modctl.h> 370Sstevel@tonic-gate #include <sys/disp.h> 380Sstevel@tonic-gate #include <sys/stat.h> 390Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 400Sstevel@tonic-gate #include <sys/vmem.h> 410Sstevel@tonic-gate #include <sys/iommutsb.h> 420Sstevel@tonic-gate #include <sys/cpuvar.h> 4327Sjchu #include <sys/ivintr.h> 44383Set142600 #include <sys/byteorder.h> 451531Skini #include <sys/hotplug/pci/pciehpc.h> 463623Sjchu #include <sys/spl.h> 470Sstevel@tonic-gate #include <px_obj.h> 480Sstevel@tonic-gate #include <pcie_pwr.h> 491772Sjl139090 #include "px_tools_var.h" 500Sstevel@tonic-gate #include <px_regs.h> 510Sstevel@tonic-gate #include <px_csr.h> 5227Sjchu #include <sys/machsystm.h> 530Sstevel@tonic-gate #include "px_lib4u.h" 5427Sjchu #include "px_err.h" 551772Sjl139090 #include "oberon_regs.h" 560Sstevel@tonic-gate 570Sstevel@tonic-gate #pragma weak jbus_stst_order 580Sstevel@tonic-gate 590Sstevel@tonic-gate extern void jbus_stst_order(); 600Sstevel@tonic-gate 610Sstevel@tonic-gate ulong_t px_mmu_dvma_end = 0xfffffffful; 620Sstevel@tonic-gate uint_t px_ranges_phi_mask = 0xfffffffful; 631772Sjl139090 uint64_t *px_oberon_ubc_scratch_regs; 642276Sschwartz uint64_t px_paddr_mask; 650Sstevel@tonic-gate 660Sstevel@tonic-gate static int px_goto_l23ready(px_t *px_p); 67118Sjchu static int px_goto_l0(px_t *px_p); 68118Sjchu static int px_pre_pwron_check(px_t *px_p); 692426Sschwartz static uint32_t px_identity_init(px_t *px_p); 70435Sjchu static boolean_t px_cpr_callb(void *arg, int code); 711648Sjchu static uint_t px_cb_intr(caddr_t arg); 7227Sjchu 7327Sjchu /* 7427Sjchu * px_lib_map_registers 7527Sjchu * 7627Sjchu * This function is called from the attach routine to map the registers 7727Sjchu * accessed by this driver. 7827Sjchu * 7927Sjchu * used by: px_attach() 8027Sjchu * 8127Sjchu * return value: DDI_FAILURE on failure 8227Sjchu */ 8327Sjchu int 8427Sjchu px_lib_map_regs(pxu_t *pxu_p, dev_info_t *dip) 8527Sjchu { 8627Sjchu ddi_device_acc_attr_t attr; 8727Sjchu px_reg_bank_t reg_bank = PX_REG_CSR; 8827Sjchu 8927Sjchu DBG(DBG_ATTACH, dip, "px_lib_map_regs: pxu_p:0x%p, dip 0x%p\n", 906313Skrishnae pxu_p, dip); 9127Sjchu 9227Sjchu attr.devacc_attr_version = DDI_DEVICE_ATTR_V0; 9327Sjchu attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC; 9427Sjchu attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC; 9527Sjchu 9627Sjchu /* 9727Sjchu * PCI CSR Base 9827Sjchu */ 9927Sjchu if (ddi_regs_map_setup(dip, reg_bank, &pxu_p->px_address[reg_bank], 10027Sjchu 0, 0, &attr, &pxu_p->px_ac[reg_bank]) != DDI_SUCCESS) { 10127Sjchu goto fail; 10227Sjchu } 10327Sjchu 10427Sjchu reg_bank++; 10527Sjchu 10627Sjchu /* 10727Sjchu * XBUS CSR Base 10827Sjchu */ 10927Sjchu if (ddi_regs_map_setup(dip, reg_bank, &pxu_p->px_address[reg_bank], 11027Sjchu 0, 0, &attr, &pxu_p->px_ac[reg_bank]) != DDI_SUCCESS) { 11127Sjchu goto fail; 11227Sjchu } 11327Sjchu 11427Sjchu pxu_p->px_address[reg_bank] -= FIRE_CONTROL_STATUS; 11527Sjchu 11627Sjchu done: 11727Sjchu for (; reg_bank >= PX_REG_CSR; reg_bank--) { 11827Sjchu DBG(DBG_ATTACH, dip, "reg_bank 0x%x address 0x%p\n", 11927Sjchu reg_bank, pxu_p->px_address[reg_bank]); 12027Sjchu } 12127Sjchu 12227Sjchu return (DDI_SUCCESS); 12327Sjchu 12427Sjchu fail: 12527Sjchu cmn_err(CE_WARN, "%s%d: unable to map reg entry %d\n", 12627Sjchu ddi_driver_name(dip), ddi_get_instance(dip), reg_bank); 12727Sjchu 12827Sjchu for (reg_bank--; reg_bank >= PX_REG_CSR; reg_bank--) { 12927Sjchu pxu_p->px_address[reg_bank] = NULL; 13027Sjchu ddi_regs_map_free(&pxu_p->px_ac[reg_bank]); 13127Sjchu } 13227Sjchu 13327Sjchu return (DDI_FAILURE); 13427Sjchu } 13527Sjchu 13627Sjchu /* 13727Sjchu * px_lib_unmap_regs: 13827Sjchu * 13927Sjchu * This routine unmaps the registers mapped by map_px_registers. 14027Sjchu * 14127Sjchu * used by: px_detach(), and error conditions in px_attach() 14227Sjchu * 14327Sjchu * return value: none 14427Sjchu */ 14527Sjchu void 14627Sjchu px_lib_unmap_regs(pxu_t *pxu_p) 14727Sjchu { 14827Sjchu int i; 14927Sjchu 15027Sjchu for (i = 0; i < PX_REG_MAX; i++) { 15127Sjchu if (pxu_p->px_ac[i]) 15227Sjchu ddi_regs_map_free(&pxu_p->px_ac[i]); 15327Sjchu } 15427Sjchu } 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate int 1570Sstevel@tonic-gate px_lib_dev_init(dev_info_t *dip, devhandle_t *dev_hdl) 1580Sstevel@tonic-gate { 1592509Sschwartz 1602509Sschwartz caddr_t xbc_csr_base, csr_base; 1610Sstevel@tonic-gate px_dvma_range_prop_t px_dvma_range; 1622509Sschwartz pxu_t *pxu_p; 1632509Sschwartz uint8_t chip_mask; 1642509Sschwartz px_t *px_p = DIP_TO_STATE(dip); 1652509Sschwartz px_chip_type_t chip_type = px_identity_init(px_p); 1660Sstevel@tonic-gate 1672426Sschwartz DBG(DBG_ATTACH, dip, "px_lib_dev_init: dip 0x%p", dip); 1682426Sschwartz 1692426Sschwartz if (chip_type == PX_CHIP_UNIDENTIFIED) { 1702426Sschwartz cmn_err(CE_WARN, "%s%d: Unrecognized Hardware Version\n", 1712426Sschwartz NAMEINST(dip)); 1720Sstevel@tonic-gate return (DDI_FAILURE); 1730Sstevel@tonic-gate } 1740Sstevel@tonic-gate 1752509Sschwartz chip_mask = BITMASK(chip_type); 1762426Sschwartz px_paddr_mask = (chip_type == PX_CHIP_FIRE) ? MMU_FIRE_PADDR_MASK : 1772426Sschwartz MMU_OBERON_PADDR_MASK; 1782426Sschwartz 1790Sstevel@tonic-gate /* 1800Sstevel@tonic-gate * Allocate platform specific structure and link it to 1810Sstevel@tonic-gate * the px state structure. 1820Sstevel@tonic-gate */ 1830Sstevel@tonic-gate pxu_p = kmem_zalloc(sizeof (pxu_t), KM_SLEEP); 1842426Sschwartz pxu_p->chip_type = chip_type; 1850Sstevel@tonic-gate pxu_p->portid = ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 1860Sstevel@tonic-gate "portid", -1); 1870Sstevel@tonic-gate 18827Sjchu /* Map in the registers */ 18927Sjchu if (px_lib_map_regs(pxu_p, dip) == DDI_FAILURE) { 19027Sjchu kmem_free(pxu_p, sizeof (pxu_t)); 19127Sjchu 19227Sjchu return (DDI_FAILURE); 19327Sjchu } 19427Sjchu 19527Sjchu xbc_csr_base = (caddr_t)pxu_p->px_address[PX_REG_XBC]; 19627Sjchu csr_base = (caddr_t)pxu_p->px_address[PX_REG_CSR]; 19727Sjchu 1980Sstevel@tonic-gate pxu_p->tsb_cookie = iommu_tsb_alloc(pxu_p->portid); 1990Sstevel@tonic-gate pxu_p->tsb_size = iommu_tsb_cookie_to_size(pxu_p->tsb_cookie); 2000Sstevel@tonic-gate pxu_p->tsb_vaddr = iommu_tsb_cookie_to_va(pxu_p->tsb_cookie); 2010Sstevel@tonic-gate 2021772Sjl139090 pxu_p->tsb_paddr = va_to_pa(pxu_p->tsb_vaddr); 2031772Sjl139090 2040Sstevel@tonic-gate /* 2050Sstevel@tonic-gate * Create "virtual-dma" property to support child devices 2060Sstevel@tonic-gate * needing to know DVMA range. 2070Sstevel@tonic-gate */ 2080Sstevel@tonic-gate px_dvma_range.dvma_base = (uint32_t)px_mmu_dvma_end + 1 2090Sstevel@tonic-gate - ((pxu_p->tsb_size >> 3) << MMU_PAGE_SHIFT); 2100Sstevel@tonic-gate px_dvma_range.dvma_len = (uint32_t) 2110Sstevel@tonic-gate px_mmu_dvma_end - px_dvma_range.dvma_base + 1; 2120Sstevel@tonic-gate 2135328Sdanice (void) ddi_prop_update_int_array(DDI_DEV_T_NONE, dip, 2145328Sdanice "virtual-dma", (int *)&px_dvma_range, 2155328Sdanice sizeof (px_dvma_range_prop_t) / sizeof (int)); 2160Sstevel@tonic-gate /* 2170Sstevel@tonic-gate * Initilize all fire hardware specific blocks. 2180Sstevel@tonic-gate */ 2190Sstevel@tonic-gate hvio_cb_init(xbc_csr_base, pxu_p); 2200Sstevel@tonic-gate hvio_ib_init(csr_base, pxu_p); 2210Sstevel@tonic-gate hvio_pec_init(csr_base, pxu_p); 2220Sstevel@tonic-gate hvio_mmu_init(csr_base, pxu_p); 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate px_p->px_plat_p = (void *)pxu_p; 2250Sstevel@tonic-gate 22627Sjchu /* 22727Sjchu * Initialize all the interrupt handlers 22827Sjchu */ 2291772Sjl139090 switch (PX_CHIP_TYPE(pxu_p)) { 2301772Sjl139090 case PX_CHIP_OBERON: 2312044Sjj156685 /* 2322044Sjj156685 * Oberon hotplug uses SPARE3 field in ILU Error Log Enable 2332044Sjj156685 * register to indicate the status of leaf reset, 2342044Sjj156685 * we need to preserve the value of this bit, and keep it in 2352044Sjj156685 * px_ilu_log_mask to reflect the state of the bit 2362044Sjj156685 */ 2372044Sjj156685 if (CSR_BR(csr_base, ILU_ERROR_LOG_ENABLE, SPARE3)) 2382044Sjj156685 px_ilu_log_mask |= (1ull << 2392044Sjj156685 ILU_ERROR_LOG_ENABLE_SPARE3); 2402044Sjj156685 else 2412044Sjj156685 px_ilu_log_mask &= ~(1ull << 2422044Sjj156685 ILU_ERROR_LOG_ENABLE_SPARE3); 2432509Sschwartz 2442509Sschwartz px_err_reg_setup_pcie(chip_mask, csr_base, PX_ERR_ENABLE); 2451772Sjl139090 break; 2461772Sjl139090 2471772Sjl139090 case PX_CHIP_FIRE: 2482509Sschwartz px_err_reg_setup_pcie(chip_mask, csr_base, PX_ERR_ENABLE); 2491772Sjl139090 break; 2502509Sschwartz 2511772Sjl139090 default: 2521772Sjl139090 cmn_err(CE_WARN, "%s%d: PX primary bus Unknown\n", 2531772Sjl139090 ddi_driver_name(dip), ddi_get_instance(dip)); 2541772Sjl139090 return (DDI_FAILURE); 2551772Sjl139090 } 25627Sjchu 2570Sstevel@tonic-gate /* Initilize device handle */ 2580Sstevel@tonic-gate *dev_hdl = (devhandle_t)csr_base; 2590Sstevel@tonic-gate 2600Sstevel@tonic-gate DBG(DBG_ATTACH, dip, "px_lib_dev_init: dev_hdl 0x%llx\n", *dev_hdl); 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate return (DDI_SUCCESS); 2630Sstevel@tonic-gate } 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate int 2660Sstevel@tonic-gate px_lib_dev_fini(dev_info_t *dip) 2670Sstevel@tonic-gate { 2682509Sschwartz caddr_t csr_base; 2692509Sschwartz uint8_t chip_mask; 2702509Sschwartz px_t *px_p = DIP_TO_STATE(dip); 2712509Sschwartz pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate DBG(DBG_DETACH, dip, "px_lib_dev_fini: dip 0x%p\n", dip); 2740Sstevel@tonic-gate 27527Sjchu /* 27627Sjchu * Deinitialize all the interrupt handlers 27727Sjchu */ 2781772Sjl139090 switch (PX_CHIP_TYPE(pxu_p)) { 2791772Sjl139090 case PX_CHIP_OBERON: 2802509Sschwartz case PX_CHIP_FIRE: 2812509Sschwartz chip_mask = BITMASK(PX_CHIP_TYPE(pxu_p)); 2822509Sschwartz csr_base = (caddr_t)pxu_p->px_address[PX_REG_CSR]; 2832509Sschwartz px_err_reg_setup_pcie(chip_mask, csr_base, PX_ERR_DISABLE); 2841772Sjl139090 break; 2852509Sschwartz 2861772Sjl139090 default: 2871772Sjl139090 cmn_err(CE_WARN, "%s%d: PX primary bus Unknown\n", 2881772Sjl139090 ddi_driver_name(dip), ddi_get_instance(dip)); 2891772Sjl139090 return (DDI_FAILURE); 2901772Sjl139090 } 29127Sjchu 2920Sstevel@tonic-gate iommu_tsb_free(pxu_p->tsb_cookie); 2930Sstevel@tonic-gate 29427Sjchu px_lib_unmap_regs((pxu_t *)px_p->px_plat_p); 29527Sjchu kmem_free(px_p->px_plat_p, sizeof (pxu_t)); 2960Sstevel@tonic-gate px_p->px_plat_p = NULL; 2975328Sdanice (void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "virtual-dma"); 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate return (DDI_SUCCESS); 3000Sstevel@tonic-gate } 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate /*ARGSUSED*/ 3030Sstevel@tonic-gate int 3040Sstevel@tonic-gate px_lib_intr_devino_to_sysino(dev_info_t *dip, devino_t devino, 3050Sstevel@tonic-gate sysino_t *sysino) 3060Sstevel@tonic-gate { 3070Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 3080Sstevel@tonic-gate pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 3090Sstevel@tonic-gate uint64_t ret; 3100Sstevel@tonic-gate 3110Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_devino_to_sysino: dip 0x%p " 3120Sstevel@tonic-gate "devino 0x%x\n", dip, devino); 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate if ((ret = hvio_intr_devino_to_sysino(DIP_TO_HANDLE(dip), 3150Sstevel@tonic-gate pxu_p, devino, sysino)) != H_EOK) { 3160Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, 3170Sstevel@tonic-gate "hvio_intr_devino_to_sysino failed, ret 0x%lx\n", ret); 3180Sstevel@tonic-gate return (DDI_FAILURE); 3190Sstevel@tonic-gate } 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_devino_to_sysino: sysino 0x%llx\n", 3220Sstevel@tonic-gate *sysino); 3230Sstevel@tonic-gate 3240Sstevel@tonic-gate return (DDI_SUCCESS); 3250Sstevel@tonic-gate } 3260Sstevel@tonic-gate 3270Sstevel@tonic-gate /*ARGSUSED*/ 3280Sstevel@tonic-gate int 3290Sstevel@tonic-gate px_lib_intr_getvalid(dev_info_t *dip, sysino_t sysino, 3300Sstevel@tonic-gate intr_valid_state_t *intr_valid_state) 3310Sstevel@tonic-gate { 3320Sstevel@tonic-gate uint64_t ret; 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_getvalid: dip 0x%p sysino 0x%llx\n", 3350Sstevel@tonic-gate dip, sysino); 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate if ((ret = hvio_intr_getvalid(DIP_TO_HANDLE(dip), 3380Sstevel@tonic-gate sysino, intr_valid_state)) != H_EOK) { 3390Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "hvio_intr_getvalid failed, ret 0x%lx\n", 3400Sstevel@tonic-gate ret); 3410Sstevel@tonic-gate return (DDI_FAILURE); 3420Sstevel@tonic-gate } 3430Sstevel@tonic-gate 3440Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_getvalid: intr_valid_state 0x%x\n", 3450Sstevel@tonic-gate *intr_valid_state); 3460Sstevel@tonic-gate 3470Sstevel@tonic-gate return (DDI_SUCCESS); 3480Sstevel@tonic-gate } 3490Sstevel@tonic-gate 3500Sstevel@tonic-gate /*ARGSUSED*/ 3510Sstevel@tonic-gate int 3520Sstevel@tonic-gate px_lib_intr_setvalid(dev_info_t *dip, sysino_t sysino, 3530Sstevel@tonic-gate intr_valid_state_t intr_valid_state) 3540Sstevel@tonic-gate { 3550Sstevel@tonic-gate uint64_t ret; 3560Sstevel@tonic-gate 3570Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_setvalid: dip 0x%p sysino 0x%llx " 3580Sstevel@tonic-gate "intr_valid_state 0x%x\n", dip, sysino, intr_valid_state); 3590Sstevel@tonic-gate 3600Sstevel@tonic-gate if ((ret = hvio_intr_setvalid(DIP_TO_HANDLE(dip), 3610Sstevel@tonic-gate sysino, intr_valid_state)) != H_EOK) { 3620Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "hvio_intr_setvalid failed, ret 0x%lx\n", 3630Sstevel@tonic-gate ret); 3640Sstevel@tonic-gate return (DDI_FAILURE); 3650Sstevel@tonic-gate } 3660Sstevel@tonic-gate 3670Sstevel@tonic-gate return (DDI_SUCCESS); 3680Sstevel@tonic-gate } 3690Sstevel@tonic-gate 3700Sstevel@tonic-gate /*ARGSUSED*/ 3710Sstevel@tonic-gate int 3720Sstevel@tonic-gate px_lib_intr_getstate(dev_info_t *dip, sysino_t sysino, 3730Sstevel@tonic-gate intr_state_t *intr_state) 3740Sstevel@tonic-gate { 3750Sstevel@tonic-gate uint64_t ret; 3760Sstevel@tonic-gate 3770Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_getstate: dip 0x%p sysino 0x%llx\n", 3780Sstevel@tonic-gate dip, sysino); 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate if ((ret = hvio_intr_getstate(DIP_TO_HANDLE(dip), 3810Sstevel@tonic-gate sysino, intr_state)) != H_EOK) { 3820Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "hvio_intr_getstate failed, ret 0x%lx\n", 3830Sstevel@tonic-gate ret); 3840Sstevel@tonic-gate return (DDI_FAILURE); 3850Sstevel@tonic-gate } 3860Sstevel@tonic-gate 3870Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_getstate: intr_state 0x%x\n", 3880Sstevel@tonic-gate *intr_state); 3890Sstevel@tonic-gate 3900Sstevel@tonic-gate return (DDI_SUCCESS); 3910Sstevel@tonic-gate } 3920Sstevel@tonic-gate 3930Sstevel@tonic-gate /*ARGSUSED*/ 3940Sstevel@tonic-gate int 3950Sstevel@tonic-gate px_lib_intr_setstate(dev_info_t *dip, sysino_t sysino, 3960Sstevel@tonic-gate intr_state_t intr_state) 3970Sstevel@tonic-gate { 3980Sstevel@tonic-gate uint64_t ret; 3990Sstevel@tonic-gate 4000Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_setstate: dip 0x%p sysino 0x%llx " 4010Sstevel@tonic-gate "intr_state 0x%x\n", dip, sysino, intr_state); 4020Sstevel@tonic-gate 4030Sstevel@tonic-gate if ((ret = hvio_intr_setstate(DIP_TO_HANDLE(dip), 4040Sstevel@tonic-gate sysino, intr_state)) != H_EOK) { 4050Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "hvio_intr_setstate failed, ret 0x%lx\n", 4060Sstevel@tonic-gate ret); 4070Sstevel@tonic-gate return (DDI_FAILURE); 4080Sstevel@tonic-gate } 4090Sstevel@tonic-gate 4100Sstevel@tonic-gate return (DDI_SUCCESS); 4110Sstevel@tonic-gate } 4120Sstevel@tonic-gate 4130Sstevel@tonic-gate /*ARGSUSED*/ 4140Sstevel@tonic-gate int 4150Sstevel@tonic-gate px_lib_intr_gettarget(dev_info_t *dip, sysino_t sysino, cpuid_t *cpuid) 4160Sstevel@tonic-gate { 4171772Sjl139090 px_t *px_p = DIP_TO_STATE(dip); 4181772Sjl139090 pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 4190Sstevel@tonic-gate uint64_t ret; 4200Sstevel@tonic-gate 4210Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_gettarget: dip 0x%p sysino 0x%llx\n", 4220Sstevel@tonic-gate dip, sysino); 4230Sstevel@tonic-gate 4241772Sjl139090 if ((ret = hvio_intr_gettarget(DIP_TO_HANDLE(dip), pxu_p, 4250Sstevel@tonic-gate sysino, cpuid)) != H_EOK) { 4260Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "hvio_intr_gettarget failed, ret 0x%lx\n", 4270Sstevel@tonic-gate ret); 4280Sstevel@tonic-gate return (DDI_FAILURE); 4290Sstevel@tonic-gate } 4300Sstevel@tonic-gate 4310Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_gettarget: cpuid 0x%x\n", cpuid); 4320Sstevel@tonic-gate 4330Sstevel@tonic-gate return (DDI_SUCCESS); 4340Sstevel@tonic-gate } 4350Sstevel@tonic-gate 4360Sstevel@tonic-gate /*ARGSUSED*/ 4370Sstevel@tonic-gate int 4380Sstevel@tonic-gate px_lib_intr_settarget(dev_info_t *dip, sysino_t sysino, cpuid_t cpuid) 4390Sstevel@tonic-gate { 4401772Sjl139090 px_t *px_p = DIP_TO_STATE(dip); 4411772Sjl139090 pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 4420Sstevel@tonic-gate uint64_t ret; 4430Sstevel@tonic-gate 4440Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_settarget: dip 0x%p sysino 0x%llx " 4450Sstevel@tonic-gate "cpuid 0x%x\n", dip, sysino, cpuid); 4460Sstevel@tonic-gate 4471772Sjl139090 if ((ret = hvio_intr_settarget(DIP_TO_HANDLE(dip), pxu_p, 4480Sstevel@tonic-gate sysino, cpuid)) != H_EOK) { 4490Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "hvio_intr_settarget failed, ret 0x%lx\n", 4500Sstevel@tonic-gate ret); 4510Sstevel@tonic-gate return (DDI_FAILURE); 4520Sstevel@tonic-gate } 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate return (DDI_SUCCESS); 4550Sstevel@tonic-gate } 4560Sstevel@tonic-gate 4570Sstevel@tonic-gate /*ARGSUSED*/ 4580Sstevel@tonic-gate int 4590Sstevel@tonic-gate px_lib_intr_reset(dev_info_t *dip) 4600Sstevel@tonic-gate { 4610Sstevel@tonic-gate devino_t ino; 4620Sstevel@tonic-gate sysino_t sysino; 4630Sstevel@tonic-gate 4640Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_reset: dip 0x%p\n", dip); 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate /* Reset all Interrupts */ 4670Sstevel@tonic-gate for (ino = 0; ino < INTERRUPT_MAPPING_ENTRIES; ino++) { 4680Sstevel@tonic-gate if (px_lib_intr_devino_to_sysino(dip, ino, 4690Sstevel@tonic-gate &sysino) != DDI_SUCCESS) 4700Sstevel@tonic-gate return (BF_FATAL); 4710Sstevel@tonic-gate 4720Sstevel@tonic-gate if (px_lib_intr_setstate(dip, sysino, 4730Sstevel@tonic-gate INTR_IDLE_STATE) != DDI_SUCCESS) 4740Sstevel@tonic-gate return (BF_FATAL); 4750Sstevel@tonic-gate } 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate return (BF_NONE); 4780Sstevel@tonic-gate } 4790Sstevel@tonic-gate 4800Sstevel@tonic-gate /*ARGSUSED*/ 4810Sstevel@tonic-gate int 4820Sstevel@tonic-gate px_lib_iommu_map(dev_info_t *dip, tsbid_t tsbid, pages_t pages, 4831617Sgovinda io_attributes_t attr, void *addr, size_t pfn_index, int flags) 4840Sstevel@tonic-gate { 4850Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 4860Sstevel@tonic-gate pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 4870Sstevel@tonic-gate uint64_t ret; 4880Sstevel@tonic-gate 4890Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip, "px_lib_iommu_map: dip 0x%p tsbid 0x%llx " 4901617Sgovinda "pages 0x%x attr 0x%x addr 0x%p pfn_index 0x%llx flags 0x%x\n", 4911617Sgovinda dip, tsbid, pages, attr, addr, pfn_index, flags); 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate if ((ret = hvio_iommu_map(px_p->px_dev_hdl, pxu_p, tsbid, pages, 4941617Sgovinda attr, addr, pfn_index, flags)) != H_EOK) { 4950Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip, 4960Sstevel@tonic-gate "px_lib_iommu_map failed, ret 0x%lx\n", ret); 4970Sstevel@tonic-gate return (DDI_FAILURE); 4980Sstevel@tonic-gate } 4990Sstevel@tonic-gate 5000Sstevel@tonic-gate return (DDI_SUCCESS); 5010Sstevel@tonic-gate } 5020Sstevel@tonic-gate 5030Sstevel@tonic-gate /*ARGSUSED*/ 5040Sstevel@tonic-gate int 5050Sstevel@tonic-gate px_lib_iommu_demap(dev_info_t *dip, tsbid_t tsbid, pages_t pages) 5060Sstevel@tonic-gate { 5070Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 5080Sstevel@tonic-gate pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 5090Sstevel@tonic-gate uint64_t ret; 5100Sstevel@tonic-gate 5110Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip, "px_lib_iommu_demap: dip 0x%p tsbid 0x%llx " 5120Sstevel@tonic-gate "pages 0x%x\n", dip, tsbid, pages); 5130Sstevel@tonic-gate 5140Sstevel@tonic-gate if ((ret = hvio_iommu_demap(px_p->px_dev_hdl, pxu_p, tsbid, pages)) 5150Sstevel@tonic-gate != H_EOK) { 5160Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip, 5170Sstevel@tonic-gate "px_lib_iommu_demap failed, ret 0x%lx\n", ret); 5180Sstevel@tonic-gate 5190Sstevel@tonic-gate return (DDI_FAILURE); 5200Sstevel@tonic-gate } 5210Sstevel@tonic-gate 5220Sstevel@tonic-gate return (DDI_SUCCESS); 5230Sstevel@tonic-gate } 5240Sstevel@tonic-gate 5250Sstevel@tonic-gate /*ARGSUSED*/ 5260Sstevel@tonic-gate int 5271617Sgovinda px_lib_iommu_getmap(dev_info_t *dip, tsbid_t tsbid, io_attributes_t *attr_p, 5281617Sgovinda r_addr_t *r_addr_p) 5290Sstevel@tonic-gate { 5300Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 5310Sstevel@tonic-gate pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 5320Sstevel@tonic-gate uint64_t ret; 5330Sstevel@tonic-gate 5340Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip, "px_lib_iommu_getmap: dip 0x%p tsbid 0x%llx\n", 5350Sstevel@tonic-gate dip, tsbid); 5360Sstevel@tonic-gate 5370Sstevel@tonic-gate if ((ret = hvio_iommu_getmap(DIP_TO_HANDLE(dip), pxu_p, tsbid, 5381617Sgovinda attr_p, r_addr_p)) != H_EOK) { 5390Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip, 5400Sstevel@tonic-gate "hvio_iommu_getmap failed, ret 0x%lx\n", ret); 5410Sstevel@tonic-gate 5420Sstevel@tonic-gate return ((ret == H_ENOMAP) ? DDI_DMA_NOMAPPING:DDI_FAILURE); 5430Sstevel@tonic-gate } 5440Sstevel@tonic-gate 5450Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip, "px_lib_iommu_getmap: attr 0x%x r_addr 0x%llx\n", 5461617Sgovinda *attr_p, *r_addr_p); 5470Sstevel@tonic-gate 5480Sstevel@tonic-gate return (DDI_SUCCESS); 5490Sstevel@tonic-gate } 5500Sstevel@tonic-gate 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate /* 5530Sstevel@tonic-gate * Checks dma attributes against system bypass ranges 5540Sstevel@tonic-gate * The bypass range is determined by the hardware. Return them so the 5550Sstevel@tonic-gate * common code can do generic checking against them. 5560Sstevel@tonic-gate */ 5570Sstevel@tonic-gate /*ARGSUSED*/ 5580Sstevel@tonic-gate int 5591772Sjl139090 px_lib_dma_bypass_rngchk(dev_info_t *dip, ddi_dma_attr_t *attr_p, 5601772Sjl139090 uint64_t *lo_p, uint64_t *hi_p) 5610Sstevel@tonic-gate { 5621772Sjl139090 px_t *px_p = DIP_TO_STATE(dip); 5631772Sjl139090 pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 5641772Sjl139090 5651772Sjl139090 *lo_p = hvio_get_bypass_base(pxu_p); 5661772Sjl139090 *hi_p = hvio_get_bypass_end(pxu_p); 5670Sstevel@tonic-gate 5680Sstevel@tonic-gate return (DDI_SUCCESS); 5690Sstevel@tonic-gate } 5700Sstevel@tonic-gate 5710Sstevel@tonic-gate 5720Sstevel@tonic-gate /*ARGSUSED*/ 5730Sstevel@tonic-gate int 5741617Sgovinda px_lib_iommu_getbypass(dev_info_t *dip, r_addr_t ra, io_attributes_t attr, 5751617Sgovinda io_addr_t *io_addr_p) 5760Sstevel@tonic-gate { 5770Sstevel@tonic-gate uint64_t ret; 5781772Sjl139090 px_t *px_p = DIP_TO_STATE(dip); 5791772Sjl139090 pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 5800Sstevel@tonic-gate 5810Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip, "px_lib_iommu_getbypass: dip 0x%p ra 0x%llx " 5821617Sgovinda "attr 0x%x\n", dip, ra, attr); 5830Sstevel@tonic-gate 5841772Sjl139090 if ((ret = hvio_iommu_getbypass(DIP_TO_HANDLE(dip), pxu_p, ra, 5851772Sjl139090 attr, io_addr_p)) != H_EOK) { 5860Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip, 5870Sstevel@tonic-gate "hvio_iommu_getbypass failed, ret 0x%lx\n", ret); 5880Sstevel@tonic-gate return (DDI_FAILURE); 5890Sstevel@tonic-gate } 5900Sstevel@tonic-gate 5910Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip, "px_lib_iommu_getbypass: io_addr 0x%llx\n", 5920Sstevel@tonic-gate *io_addr_p); 5930Sstevel@tonic-gate 5940Sstevel@tonic-gate return (DDI_SUCCESS); 5950Sstevel@tonic-gate } 5960Sstevel@tonic-gate 5970Sstevel@tonic-gate /* 5980Sstevel@tonic-gate * bus dma sync entry point. 5990Sstevel@tonic-gate */ 6000Sstevel@tonic-gate /*ARGSUSED*/ 6010Sstevel@tonic-gate int 6020Sstevel@tonic-gate px_lib_dma_sync(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle, 6031617Sgovinda off_t off, size_t len, uint_t cache_flags) 6040Sstevel@tonic-gate { 6050Sstevel@tonic-gate ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle; 6061772Sjl139090 px_t *px_p = DIP_TO_STATE(dip); 6071772Sjl139090 pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 6080Sstevel@tonic-gate 6090Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip, "px_lib_dma_sync: dip 0x%p rdip 0x%p " 6100Sstevel@tonic-gate "handle 0x%llx off 0x%x len 0x%x flags 0x%x\n", 6110Sstevel@tonic-gate dip, rdip, handle, off, len, cache_flags); 6120Sstevel@tonic-gate 6130Sstevel@tonic-gate /* 6141772Sjl139090 * No flush needed for Oberon 6151772Sjl139090 */ 6161772Sjl139090 if (PX_CHIP_TYPE(pxu_p) == PX_CHIP_OBERON) 6171772Sjl139090 return (DDI_SUCCESS); 6181772Sjl139090 6191772Sjl139090 /* 6200Sstevel@tonic-gate * jbus_stst_order is found only in certain cpu modules. 6210Sstevel@tonic-gate * Just return success if not present. 6220Sstevel@tonic-gate */ 6230Sstevel@tonic-gate if (&jbus_stst_order == NULL) 6240Sstevel@tonic-gate return (DDI_SUCCESS); 6250Sstevel@tonic-gate 626909Segillett if (!(mp->dmai_flags & PX_DMAI_FLAGS_INUSE)) { 62727Sjchu cmn_err(CE_WARN, "%s%d: Unbound dma handle %p.", 62827Sjchu ddi_driver_name(rdip), ddi_get_instance(rdip), (void *)mp); 62927Sjchu 6300Sstevel@tonic-gate return (DDI_FAILURE); 6310Sstevel@tonic-gate } 6320Sstevel@tonic-gate 633909Segillett if (mp->dmai_flags & PX_DMAI_FLAGS_NOSYNC) 6340Sstevel@tonic-gate return (DDI_SUCCESS); 6350Sstevel@tonic-gate 6360Sstevel@tonic-gate /* 6370Sstevel@tonic-gate * No flush needed when sending data from memory to device. 6380Sstevel@tonic-gate * Nothing to do to "sync" memory to what device would already see. 6390Sstevel@tonic-gate */ 6400Sstevel@tonic-gate if (!(mp->dmai_rflags & DDI_DMA_READ) || 6410Sstevel@tonic-gate ((cache_flags & PX_DMA_SYNC_DDI_FLAGS) == DDI_DMA_SYNC_FORDEV)) 6420Sstevel@tonic-gate return (DDI_SUCCESS); 6430Sstevel@tonic-gate 6440Sstevel@tonic-gate /* 6450Sstevel@tonic-gate * Perform necessary cpu workaround to ensure jbus ordering. 6460Sstevel@tonic-gate * CPU's internal "invalidate FIFOs" are flushed. 6470Sstevel@tonic-gate */ 6480Sstevel@tonic-gate 6490Sstevel@tonic-gate #if !defined(lint) 6500Sstevel@tonic-gate kpreempt_disable(); 6510Sstevel@tonic-gate #endif 6520Sstevel@tonic-gate jbus_stst_order(); 6530Sstevel@tonic-gate #if !defined(lint) 6540Sstevel@tonic-gate kpreempt_enable(); 6550Sstevel@tonic-gate #endif 6560Sstevel@tonic-gate return (DDI_SUCCESS); 6570Sstevel@tonic-gate } 6580Sstevel@tonic-gate 6590Sstevel@tonic-gate /* 6600Sstevel@tonic-gate * MSIQ Functions: 6610Sstevel@tonic-gate */ 6620Sstevel@tonic-gate /*ARGSUSED*/ 6630Sstevel@tonic-gate int 6640Sstevel@tonic-gate px_lib_msiq_init(dev_info_t *dip) 6650Sstevel@tonic-gate { 6660Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 6670Sstevel@tonic-gate pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 6680Sstevel@tonic-gate px_msiq_state_t *msiq_state_p = &px_p->px_ib_p->ib_msiq_state; 6690Sstevel@tonic-gate px_dvma_addr_t pg_index; 6700Sstevel@tonic-gate size_t size; 6710Sstevel@tonic-gate int ret; 6720Sstevel@tonic-gate 6730Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_init: dip 0x%p\n", dip); 6740Sstevel@tonic-gate 6750Sstevel@tonic-gate /* 6760Sstevel@tonic-gate * Map the EQ memory into the Fire MMU (has to be 512KB aligned) 6770Sstevel@tonic-gate * and then initialize the base address register. 6780Sstevel@tonic-gate * 6790Sstevel@tonic-gate * Allocate entries from Fire IOMMU so that the resulting address 6800Sstevel@tonic-gate * is properly aligned. Calculate the index of the first allocated 6810Sstevel@tonic-gate * entry. Note: The size of the mapping is assumed to be a multiple 6820Sstevel@tonic-gate * of the page size. 6830Sstevel@tonic-gate */ 6840Sstevel@tonic-gate size = msiq_state_p->msiq_cnt * 6850Sstevel@tonic-gate msiq_state_p->msiq_rec_cnt * sizeof (msiq_rec_t); 6860Sstevel@tonic-gate 6870Sstevel@tonic-gate pxu_p->msiq_mapped_p = vmem_xalloc(px_p->px_mmu_p->mmu_dvma_map, 6880Sstevel@tonic-gate size, (512 * 1024), 0, 0, NULL, NULL, VM_NOSLEEP | VM_BESTFIT); 6890Sstevel@tonic-gate 6900Sstevel@tonic-gate if (pxu_p->msiq_mapped_p == NULL) 6910Sstevel@tonic-gate return (DDI_FAILURE); 6920Sstevel@tonic-gate 6930Sstevel@tonic-gate pg_index = MMU_PAGE_INDEX(px_p->px_mmu_p, 6940Sstevel@tonic-gate MMU_BTOP((ulong_t)pxu_p->msiq_mapped_p)); 6950Sstevel@tonic-gate 6960Sstevel@tonic-gate if ((ret = px_lib_iommu_map(px_p->px_dip, PCI_TSBID(0, pg_index), 6972755Segillett MMU_BTOP(size), PCI_MAP_ATTR_WRITE, msiq_state_p->msiq_buf_p, 6982755Segillett 0, MMU_MAP_BUF)) != DDI_SUCCESS) { 6990Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, 7006983Sanbui "px_lib_msiq_init: px_lib_iommu_map failed, " 7016983Sanbui "ret 0x%lx\n", ret); 7020Sstevel@tonic-gate 7030Sstevel@tonic-gate (void) px_lib_msiq_fini(dip); 7040Sstevel@tonic-gate return (DDI_FAILURE); 7050Sstevel@tonic-gate } 7060Sstevel@tonic-gate 707*7124Sanbui if ((ret = hvio_msiq_init(DIP_TO_HANDLE(dip), 708*7124Sanbui pxu_p)) != H_EOK) { 709*7124Sanbui DBG(DBG_LIB_MSIQ, dip, 710*7124Sanbui "hvio_msiq_init failed, ret 0x%lx\n", ret); 711*7124Sanbui 712*7124Sanbui (void) px_lib_msiq_fini(dip); 713*7124Sanbui return (DDI_FAILURE); 714*7124Sanbui } 7150Sstevel@tonic-gate 7160Sstevel@tonic-gate return (DDI_SUCCESS); 7170Sstevel@tonic-gate } 7180Sstevel@tonic-gate 7190Sstevel@tonic-gate /*ARGSUSED*/ 7200Sstevel@tonic-gate int 7210Sstevel@tonic-gate px_lib_msiq_fini(dev_info_t *dip) 7220Sstevel@tonic-gate { 7230Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 7240Sstevel@tonic-gate pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 7250Sstevel@tonic-gate px_msiq_state_t *msiq_state_p = &px_p->px_ib_p->ib_msiq_state; 7260Sstevel@tonic-gate px_dvma_addr_t pg_index; 7270Sstevel@tonic-gate size_t size; 7280Sstevel@tonic-gate 7290Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_fini: dip 0x%p\n", dip); 7300Sstevel@tonic-gate 7310Sstevel@tonic-gate /* 7320Sstevel@tonic-gate * Unmap and free the EQ memory that had been mapped 7330Sstevel@tonic-gate * into the Fire IOMMU. 7340Sstevel@tonic-gate */ 7350Sstevel@tonic-gate size = msiq_state_p->msiq_cnt * 7360Sstevel@tonic-gate msiq_state_p->msiq_rec_cnt * sizeof (msiq_rec_t); 7370Sstevel@tonic-gate 7380Sstevel@tonic-gate pg_index = MMU_PAGE_INDEX(px_p->px_mmu_p, 7390Sstevel@tonic-gate MMU_BTOP((ulong_t)pxu_p->msiq_mapped_p)); 7400Sstevel@tonic-gate 7410Sstevel@tonic-gate (void) px_lib_iommu_demap(px_p->px_dip, 7420Sstevel@tonic-gate PCI_TSBID(0, pg_index), MMU_BTOP(size)); 7430Sstevel@tonic-gate 7440Sstevel@tonic-gate /* Free the entries from the Fire MMU */ 7450Sstevel@tonic-gate vmem_xfree(px_p->px_mmu_p->mmu_dvma_map, 7460Sstevel@tonic-gate (void *)pxu_p->msiq_mapped_p, size); 7470Sstevel@tonic-gate 7480Sstevel@tonic-gate return (DDI_SUCCESS); 7490Sstevel@tonic-gate } 7500Sstevel@tonic-gate 7510Sstevel@tonic-gate /*ARGSUSED*/ 7520Sstevel@tonic-gate int 7530Sstevel@tonic-gate px_lib_msiq_info(dev_info_t *dip, msiqid_t msiq_id, r_addr_t *ra_p, 7540Sstevel@tonic-gate uint_t *msiq_rec_cnt_p) 7550Sstevel@tonic-gate { 7560Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 7570Sstevel@tonic-gate px_msiq_state_t *msiq_state_p = &px_p->px_ib_p->ib_msiq_state; 7580Sstevel@tonic-gate size_t msiq_size; 7590Sstevel@tonic-gate 7600Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_msiq_info: dip 0x%p msiq_id 0x%x\n", 7610Sstevel@tonic-gate dip, msiq_id); 7620Sstevel@tonic-gate 7630Sstevel@tonic-gate msiq_size = msiq_state_p->msiq_rec_cnt * sizeof (msiq_rec_t); 7642755Segillett ra_p = (r_addr_t *)((caddr_t)msiq_state_p->msiq_buf_p + 7652755Segillett (msiq_id * msiq_size)); 7660Sstevel@tonic-gate 7670Sstevel@tonic-gate *msiq_rec_cnt_p = msiq_state_p->msiq_rec_cnt; 7680Sstevel@tonic-gate 7690Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_msiq_info: ra_p 0x%p msiq_rec_cnt 0x%x\n", 7700Sstevel@tonic-gate ra_p, *msiq_rec_cnt_p); 7710Sstevel@tonic-gate 7720Sstevel@tonic-gate return (DDI_SUCCESS); 7730Sstevel@tonic-gate } 7740Sstevel@tonic-gate 7750Sstevel@tonic-gate /*ARGSUSED*/ 7760Sstevel@tonic-gate int 7770Sstevel@tonic-gate px_lib_msiq_getvalid(dev_info_t *dip, msiqid_t msiq_id, 7780Sstevel@tonic-gate pci_msiq_valid_state_t *msiq_valid_state) 7790Sstevel@tonic-gate { 7800Sstevel@tonic-gate uint64_t ret; 7810Sstevel@tonic-gate 7820Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_getvalid: dip 0x%p msiq_id 0x%x\n", 7830Sstevel@tonic-gate dip, msiq_id); 7840Sstevel@tonic-gate 7850Sstevel@tonic-gate if ((ret = hvio_msiq_getvalid(DIP_TO_HANDLE(dip), 7860Sstevel@tonic-gate msiq_id, msiq_valid_state)) != H_EOK) { 7870Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, 7880Sstevel@tonic-gate "hvio_msiq_getvalid failed, ret 0x%lx\n", ret); 7890Sstevel@tonic-gate return (DDI_FAILURE); 7900Sstevel@tonic-gate } 7910Sstevel@tonic-gate 7920Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_getvalid: msiq_valid_state 0x%x\n", 7930Sstevel@tonic-gate *msiq_valid_state); 7940Sstevel@tonic-gate 7950Sstevel@tonic-gate return (DDI_SUCCESS); 7960Sstevel@tonic-gate } 7970Sstevel@tonic-gate 7980Sstevel@tonic-gate /*ARGSUSED*/ 7990Sstevel@tonic-gate int 8000Sstevel@tonic-gate px_lib_msiq_setvalid(dev_info_t *dip, msiqid_t msiq_id, 8010Sstevel@tonic-gate pci_msiq_valid_state_t msiq_valid_state) 8020Sstevel@tonic-gate { 8030Sstevel@tonic-gate uint64_t ret; 8040Sstevel@tonic-gate 8050Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_setvalid: dip 0x%p msiq_id 0x%x " 8060Sstevel@tonic-gate "msiq_valid_state 0x%x\n", dip, msiq_id, msiq_valid_state); 8070Sstevel@tonic-gate 8080Sstevel@tonic-gate if ((ret = hvio_msiq_setvalid(DIP_TO_HANDLE(dip), 8090Sstevel@tonic-gate msiq_id, msiq_valid_state)) != H_EOK) { 8100Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, 8110Sstevel@tonic-gate "hvio_msiq_setvalid failed, ret 0x%lx\n", ret); 8120Sstevel@tonic-gate return (DDI_FAILURE); 8130Sstevel@tonic-gate } 8140Sstevel@tonic-gate 8150Sstevel@tonic-gate return (DDI_SUCCESS); 8160Sstevel@tonic-gate } 8170Sstevel@tonic-gate 8180Sstevel@tonic-gate /*ARGSUSED*/ 8190Sstevel@tonic-gate int 8200Sstevel@tonic-gate px_lib_msiq_getstate(dev_info_t *dip, msiqid_t msiq_id, 8210Sstevel@tonic-gate pci_msiq_state_t *msiq_state) 8220Sstevel@tonic-gate { 8230Sstevel@tonic-gate uint64_t ret; 8240Sstevel@tonic-gate 8250Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_getstate: dip 0x%p msiq_id 0x%x\n", 8260Sstevel@tonic-gate dip, msiq_id); 8270Sstevel@tonic-gate 8280Sstevel@tonic-gate if ((ret = hvio_msiq_getstate(DIP_TO_HANDLE(dip), 8290Sstevel@tonic-gate msiq_id, msiq_state)) != H_EOK) { 8300Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, 8310Sstevel@tonic-gate "hvio_msiq_getstate failed, ret 0x%lx\n", ret); 8320Sstevel@tonic-gate return (DDI_FAILURE); 8330Sstevel@tonic-gate } 8340Sstevel@tonic-gate 8350Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_getstate: msiq_state 0x%x\n", 8360Sstevel@tonic-gate *msiq_state); 8370Sstevel@tonic-gate 8380Sstevel@tonic-gate return (DDI_SUCCESS); 8390Sstevel@tonic-gate } 8400Sstevel@tonic-gate 8410Sstevel@tonic-gate /*ARGSUSED*/ 8420Sstevel@tonic-gate int 8430Sstevel@tonic-gate px_lib_msiq_setstate(dev_info_t *dip, msiqid_t msiq_id, 8440Sstevel@tonic-gate pci_msiq_state_t msiq_state) 8450Sstevel@tonic-gate { 8460Sstevel@tonic-gate uint64_t ret; 8470Sstevel@tonic-gate 8480Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_setstate: dip 0x%p msiq_id 0x%x " 8490Sstevel@tonic-gate "msiq_state 0x%x\n", dip, msiq_id, msiq_state); 8500Sstevel@tonic-gate 8510Sstevel@tonic-gate if ((ret = hvio_msiq_setstate(DIP_TO_HANDLE(dip), 8520Sstevel@tonic-gate msiq_id, msiq_state)) != H_EOK) { 8530Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, 8540Sstevel@tonic-gate "hvio_msiq_setstate failed, ret 0x%lx\n", ret); 8550Sstevel@tonic-gate return (DDI_FAILURE); 8560Sstevel@tonic-gate } 8570Sstevel@tonic-gate 8580Sstevel@tonic-gate return (DDI_SUCCESS); 8590Sstevel@tonic-gate } 8600Sstevel@tonic-gate 8610Sstevel@tonic-gate /*ARGSUSED*/ 8620Sstevel@tonic-gate int 8630Sstevel@tonic-gate px_lib_msiq_gethead(dev_info_t *dip, msiqid_t msiq_id, 8640Sstevel@tonic-gate msiqhead_t *msiq_head) 8650Sstevel@tonic-gate { 8660Sstevel@tonic-gate uint64_t ret; 8670Sstevel@tonic-gate 8680Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_gethead: dip 0x%p msiq_id 0x%x\n", 8690Sstevel@tonic-gate dip, msiq_id); 8700Sstevel@tonic-gate 8710Sstevel@tonic-gate if ((ret = hvio_msiq_gethead(DIP_TO_HANDLE(dip), 8720Sstevel@tonic-gate msiq_id, msiq_head)) != H_EOK) { 8730Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, 8740Sstevel@tonic-gate "hvio_msiq_gethead failed, ret 0x%lx\n", ret); 8750Sstevel@tonic-gate return (DDI_FAILURE); 8760Sstevel@tonic-gate } 8770Sstevel@tonic-gate 8780Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_gethead: msiq_head 0x%x\n", 8790Sstevel@tonic-gate *msiq_head); 8800Sstevel@tonic-gate 8810Sstevel@tonic-gate return (DDI_SUCCESS); 8820Sstevel@tonic-gate } 8830Sstevel@tonic-gate 8840Sstevel@tonic-gate /*ARGSUSED*/ 8850Sstevel@tonic-gate int 8860Sstevel@tonic-gate px_lib_msiq_sethead(dev_info_t *dip, msiqid_t msiq_id, 8870Sstevel@tonic-gate msiqhead_t msiq_head) 8880Sstevel@tonic-gate { 8890Sstevel@tonic-gate uint64_t ret; 8900Sstevel@tonic-gate 8910Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_sethead: dip 0x%p msiq_id 0x%x " 8920Sstevel@tonic-gate "msiq_head 0x%x\n", dip, msiq_id, msiq_head); 8930Sstevel@tonic-gate 8940Sstevel@tonic-gate if ((ret = hvio_msiq_sethead(DIP_TO_HANDLE(dip), 8950Sstevel@tonic-gate msiq_id, msiq_head)) != H_EOK) { 8960Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, 8970Sstevel@tonic-gate "hvio_msiq_sethead failed, ret 0x%lx\n", ret); 8980Sstevel@tonic-gate return (DDI_FAILURE); 8990Sstevel@tonic-gate } 9000Sstevel@tonic-gate 9010Sstevel@tonic-gate return (DDI_SUCCESS); 9020Sstevel@tonic-gate } 9030Sstevel@tonic-gate 9040Sstevel@tonic-gate /*ARGSUSED*/ 9050Sstevel@tonic-gate int 9060Sstevel@tonic-gate px_lib_msiq_gettail(dev_info_t *dip, msiqid_t msiq_id, 9070Sstevel@tonic-gate msiqtail_t *msiq_tail) 9080Sstevel@tonic-gate { 9090Sstevel@tonic-gate uint64_t ret; 9100Sstevel@tonic-gate 9110Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_gettail: dip 0x%p msiq_id 0x%x\n", 9120Sstevel@tonic-gate dip, msiq_id); 9130Sstevel@tonic-gate 9140Sstevel@tonic-gate if ((ret = hvio_msiq_gettail(DIP_TO_HANDLE(dip), 9150Sstevel@tonic-gate msiq_id, msiq_tail)) != H_EOK) { 9160Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, 9170Sstevel@tonic-gate "hvio_msiq_gettail failed, ret 0x%lx\n", ret); 9180Sstevel@tonic-gate return (DDI_FAILURE); 9190Sstevel@tonic-gate } 9200Sstevel@tonic-gate 9210Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_gettail: msiq_tail 0x%x\n", 9220Sstevel@tonic-gate *msiq_tail); 9230Sstevel@tonic-gate 9240Sstevel@tonic-gate return (DDI_SUCCESS); 9250Sstevel@tonic-gate } 9260Sstevel@tonic-gate 9270Sstevel@tonic-gate /*ARGSUSED*/ 9280Sstevel@tonic-gate void 9292588Segillett px_lib_get_msiq_rec(dev_info_t *dip, msiqhead_t *msiq_head_p, 9302588Segillett msiq_rec_t *msiq_rec_p) 9310Sstevel@tonic-gate { 9322588Segillett eq_rec_t *eq_rec_p = (eq_rec_t *)msiq_head_p; 9330Sstevel@tonic-gate 9340Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_get_msiq_rec: dip 0x%p eq_rec_p 0x%p\n", 9350Sstevel@tonic-gate dip, eq_rec_p); 9360Sstevel@tonic-gate 937287Smg140465 if (!eq_rec_p->eq_rec_fmt_type) { 938287Smg140465 /* Set msiq_rec_type to zero */ 939287Smg140465 msiq_rec_p->msiq_rec_type = 0; 9400Sstevel@tonic-gate 9410Sstevel@tonic-gate return; 9420Sstevel@tonic-gate } 9430Sstevel@tonic-gate 9440Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_get_msiq_rec: EQ RECORD, " 9450Sstevel@tonic-gate "eq_rec_rid 0x%llx eq_rec_fmt_type 0x%llx " 9460Sstevel@tonic-gate "eq_rec_len 0x%llx eq_rec_addr0 0x%llx " 9470Sstevel@tonic-gate "eq_rec_addr1 0x%llx eq_rec_data0 0x%llx " 9480Sstevel@tonic-gate "eq_rec_data1 0x%llx\n", eq_rec_p->eq_rec_rid, 9490Sstevel@tonic-gate eq_rec_p->eq_rec_fmt_type, eq_rec_p->eq_rec_len, 9500Sstevel@tonic-gate eq_rec_p->eq_rec_addr0, eq_rec_p->eq_rec_addr1, 9510Sstevel@tonic-gate eq_rec_p->eq_rec_data0, eq_rec_p->eq_rec_data1); 9520Sstevel@tonic-gate 9530Sstevel@tonic-gate /* 9540Sstevel@tonic-gate * Only upper 4 bits of eq_rec_fmt_type is used 9550Sstevel@tonic-gate * to identify the EQ record type. 9560Sstevel@tonic-gate */ 9570Sstevel@tonic-gate switch (eq_rec_p->eq_rec_fmt_type >> 3) { 9580Sstevel@tonic-gate case EQ_REC_MSI32: 9590Sstevel@tonic-gate msiq_rec_p->msiq_rec_type = MSI32_REC; 9600Sstevel@tonic-gate 961225Sess msiq_rec_p->msiq_rec_data.msi.msi_data = 962225Sess eq_rec_p->eq_rec_data0; 9630Sstevel@tonic-gate break; 9640Sstevel@tonic-gate case EQ_REC_MSI64: 9650Sstevel@tonic-gate msiq_rec_p->msiq_rec_type = MSI64_REC; 9660Sstevel@tonic-gate 967225Sess msiq_rec_p->msiq_rec_data.msi.msi_data = 968225Sess eq_rec_p->eq_rec_data0; 9690Sstevel@tonic-gate break; 9700Sstevel@tonic-gate case EQ_REC_MSG: 9710Sstevel@tonic-gate msiq_rec_p->msiq_rec_type = MSG_REC; 9720Sstevel@tonic-gate 9730Sstevel@tonic-gate msiq_rec_p->msiq_rec_data.msg.msg_route = 9740Sstevel@tonic-gate eq_rec_p->eq_rec_fmt_type & 7; 9750Sstevel@tonic-gate msiq_rec_p->msiq_rec_data.msg.msg_targ = eq_rec_p->eq_rec_rid; 9760Sstevel@tonic-gate msiq_rec_p->msiq_rec_data.msg.msg_code = eq_rec_p->eq_rec_data0; 9770Sstevel@tonic-gate break; 9780Sstevel@tonic-gate default: 9790Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: px_lib_get_msiq_rec: " 980671Skrishnae "0x%x is an unknown EQ record type", 9810Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), 982671Skrishnae (int)eq_rec_p->eq_rec_fmt_type); 9830Sstevel@tonic-gate break; 9840Sstevel@tonic-gate } 9850Sstevel@tonic-gate 9860Sstevel@tonic-gate msiq_rec_p->msiq_rec_rid = eq_rec_p->eq_rec_rid; 9870Sstevel@tonic-gate msiq_rec_p->msiq_rec_msi_addr = ((eq_rec_p->eq_rec_addr1 << 16) | 9880Sstevel@tonic-gate (eq_rec_p->eq_rec_addr0 << 2)); 9892973Sgovinda } 9902973Sgovinda 9912973Sgovinda /*ARGSUSED*/ 9922973Sgovinda void 9932973Sgovinda px_lib_clr_msiq_rec(dev_info_t *dip, msiqhead_t *msiq_head_p) 9942973Sgovinda { 9952973Sgovinda eq_rec_t *eq_rec_p = (eq_rec_t *)msiq_head_p; 9962973Sgovinda 9972973Sgovinda DBG(DBG_LIB_MSIQ, dip, "px_lib_clr_msiq_rec: dip 0x%p eq_rec_p 0x%p\n", 9982973Sgovinda dip, eq_rec_p); 9992973Sgovinda 10002973Sgovinda if (eq_rec_p->eq_rec_fmt_type) { 10012973Sgovinda /* Zero out eq_rec_fmt_type field */ 10022973Sgovinda eq_rec_p->eq_rec_fmt_type = 0; 10032973Sgovinda } 10040Sstevel@tonic-gate } 10050Sstevel@tonic-gate 10060Sstevel@tonic-gate /* 10070Sstevel@tonic-gate * MSI Functions: 10080Sstevel@tonic-gate */ 10090Sstevel@tonic-gate /*ARGSUSED*/ 10100Sstevel@tonic-gate int 10110Sstevel@tonic-gate px_lib_msi_init(dev_info_t *dip) 10120Sstevel@tonic-gate { 10130Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 10140Sstevel@tonic-gate px_msi_state_t *msi_state_p = &px_p->px_ib_p->ib_msi_state; 10150Sstevel@tonic-gate uint64_t ret; 10160Sstevel@tonic-gate 10170Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_init: dip 0x%p\n", dip); 10180Sstevel@tonic-gate 10190Sstevel@tonic-gate if ((ret = hvio_msi_init(DIP_TO_HANDLE(dip), 10200Sstevel@tonic-gate msi_state_p->msi_addr32, msi_state_p->msi_addr64)) != H_EOK) { 10210Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msi_init failed, ret 0x%lx\n", 10220Sstevel@tonic-gate ret); 10230Sstevel@tonic-gate return (DDI_FAILURE); 10240Sstevel@tonic-gate } 10250Sstevel@tonic-gate 10260Sstevel@tonic-gate return (DDI_SUCCESS); 10270Sstevel@tonic-gate } 10280Sstevel@tonic-gate 10290Sstevel@tonic-gate /*ARGSUSED*/ 10300Sstevel@tonic-gate int 10310Sstevel@tonic-gate px_lib_msi_getmsiq(dev_info_t *dip, msinum_t msi_num, 10320Sstevel@tonic-gate msiqid_t *msiq_id) 10330Sstevel@tonic-gate { 10340Sstevel@tonic-gate uint64_t ret; 10350Sstevel@tonic-gate 10360Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_getmsiq: dip 0x%p msi_num 0x%x\n", 10370Sstevel@tonic-gate dip, msi_num); 10380Sstevel@tonic-gate 10390Sstevel@tonic-gate if ((ret = hvio_msi_getmsiq(DIP_TO_HANDLE(dip), 10400Sstevel@tonic-gate msi_num, msiq_id)) != H_EOK) { 10410Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, 10420Sstevel@tonic-gate "hvio_msi_getmsiq failed, ret 0x%lx\n", ret); 10430Sstevel@tonic-gate return (DDI_FAILURE); 10440Sstevel@tonic-gate } 10450Sstevel@tonic-gate 10460Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_getmsiq: msiq_id 0x%x\n", 10470Sstevel@tonic-gate *msiq_id); 10480Sstevel@tonic-gate 10490Sstevel@tonic-gate return (DDI_SUCCESS); 10500Sstevel@tonic-gate } 10510Sstevel@tonic-gate 10520Sstevel@tonic-gate /*ARGSUSED*/ 10530Sstevel@tonic-gate int 10540Sstevel@tonic-gate px_lib_msi_setmsiq(dev_info_t *dip, msinum_t msi_num, 10550Sstevel@tonic-gate msiqid_t msiq_id, msi_type_t msitype) 10560Sstevel@tonic-gate { 10570Sstevel@tonic-gate uint64_t ret; 10580Sstevel@tonic-gate 10590Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_setmsiq: dip 0x%p msi_num 0x%x " 10600Sstevel@tonic-gate "msq_id 0x%x\n", dip, msi_num, msiq_id); 10610Sstevel@tonic-gate 10620Sstevel@tonic-gate if ((ret = hvio_msi_setmsiq(DIP_TO_HANDLE(dip), 10630Sstevel@tonic-gate msi_num, msiq_id)) != H_EOK) { 10640Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, 10650Sstevel@tonic-gate "hvio_msi_setmsiq failed, ret 0x%lx\n", ret); 10660Sstevel@tonic-gate return (DDI_FAILURE); 10670Sstevel@tonic-gate } 10680Sstevel@tonic-gate 10690Sstevel@tonic-gate return (DDI_SUCCESS); 10700Sstevel@tonic-gate } 10710Sstevel@tonic-gate 10720Sstevel@tonic-gate /*ARGSUSED*/ 10730Sstevel@tonic-gate int 10740Sstevel@tonic-gate px_lib_msi_getvalid(dev_info_t *dip, msinum_t msi_num, 10750Sstevel@tonic-gate pci_msi_valid_state_t *msi_valid_state) 10760Sstevel@tonic-gate { 10770Sstevel@tonic-gate uint64_t ret; 10780Sstevel@tonic-gate 10790Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_getvalid: dip 0x%p msi_num 0x%x\n", 10800Sstevel@tonic-gate dip, msi_num); 10810Sstevel@tonic-gate 10820Sstevel@tonic-gate if ((ret = hvio_msi_getvalid(DIP_TO_HANDLE(dip), 10830Sstevel@tonic-gate msi_num, msi_valid_state)) != H_EOK) { 10840Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, 10850Sstevel@tonic-gate "hvio_msi_getvalid failed, ret 0x%lx\n", ret); 10860Sstevel@tonic-gate return (DDI_FAILURE); 10870Sstevel@tonic-gate } 10880Sstevel@tonic-gate 10890Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_getvalid: msiq_id 0x%x\n", 10900Sstevel@tonic-gate *msi_valid_state); 10910Sstevel@tonic-gate 10920Sstevel@tonic-gate return (DDI_SUCCESS); 10930Sstevel@tonic-gate } 10940Sstevel@tonic-gate 10950Sstevel@tonic-gate /*ARGSUSED*/ 10960Sstevel@tonic-gate int 10970Sstevel@tonic-gate px_lib_msi_setvalid(dev_info_t *dip, msinum_t msi_num, 10980Sstevel@tonic-gate pci_msi_valid_state_t msi_valid_state) 10990Sstevel@tonic-gate { 11000Sstevel@tonic-gate uint64_t ret; 11010Sstevel@tonic-gate 11020Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_setvalid: dip 0x%p msi_num 0x%x " 11030Sstevel@tonic-gate "msi_valid_state 0x%x\n", dip, msi_num, msi_valid_state); 11040Sstevel@tonic-gate 11050Sstevel@tonic-gate if ((ret = hvio_msi_setvalid(DIP_TO_HANDLE(dip), 11060Sstevel@tonic-gate msi_num, msi_valid_state)) != H_EOK) { 11070Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, 11080Sstevel@tonic-gate "hvio_msi_setvalid failed, ret 0x%lx\n", ret); 11090Sstevel@tonic-gate return (DDI_FAILURE); 11100Sstevel@tonic-gate } 11110Sstevel@tonic-gate 11120Sstevel@tonic-gate return (DDI_SUCCESS); 11130Sstevel@tonic-gate } 11140Sstevel@tonic-gate 11150Sstevel@tonic-gate /*ARGSUSED*/ 11160Sstevel@tonic-gate int 11170Sstevel@tonic-gate px_lib_msi_getstate(dev_info_t *dip, msinum_t msi_num, 11180Sstevel@tonic-gate pci_msi_state_t *msi_state) 11190Sstevel@tonic-gate { 11200Sstevel@tonic-gate uint64_t ret; 11210Sstevel@tonic-gate 11220Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_getstate: dip 0x%p msi_num 0x%x\n", 11230Sstevel@tonic-gate dip, msi_num); 11240Sstevel@tonic-gate 11250Sstevel@tonic-gate if ((ret = hvio_msi_getstate(DIP_TO_HANDLE(dip), 11260Sstevel@tonic-gate msi_num, msi_state)) != H_EOK) { 11270Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, 11280Sstevel@tonic-gate "hvio_msi_getstate failed, ret 0x%lx\n", ret); 11290Sstevel@tonic-gate return (DDI_FAILURE); 11300Sstevel@tonic-gate } 11310Sstevel@tonic-gate 11320Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_getstate: msi_state 0x%x\n", 11330Sstevel@tonic-gate *msi_state); 11340Sstevel@tonic-gate 11350Sstevel@tonic-gate return (DDI_SUCCESS); 11360Sstevel@tonic-gate } 11370Sstevel@tonic-gate 11380Sstevel@tonic-gate /*ARGSUSED*/ 11390Sstevel@tonic-gate int 11400Sstevel@tonic-gate px_lib_msi_setstate(dev_info_t *dip, msinum_t msi_num, 11410Sstevel@tonic-gate pci_msi_state_t msi_state) 11420Sstevel@tonic-gate { 11430Sstevel@tonic-gate uint64_t ret; 11440Sstevel@tonic-gate 11450Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_setstate: dip 0x%p msi_num 0x%x " 11460Sstevel@tonic-gate "msi_state 0x%x\n", dip, msi_num, msi_state); 11470Sstevel@tonic-gate 11480Sstevel@tonic-gate if ((ret = hvio_msi_setstate(DIP_TO_HANDLE(dip), 11490Sstevel@tonic-gate msi_num, msi_state)) != H_EOK) { 11500Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, 11510Sstevel@tonic-gate "hvio_msi_setstate failed, ret 0x%lx\n", ret); 11520Sstevel@tonic-gate return (DDI_FAILURE); 11530Sstevel@tonic-gate } 11540Sstevel@tonic-gate 11550Sstevel@tonic-gate return (DDI_SUCCESS); 11560Sstevel@tonic-gate } 11570Sstevel@tonic-gate 11580Sstevel@tonic-gate /* 11590Sstevel@tonic-gate * MSG Functions: 11600Sstevel@tonic-gate */ 11610Sstevel@tonic-gate /*ARGSUSED*/ 11620Sstevel@tonic-gate int 11630Sstevel@tonic-gate px_lib_msg_getmsiq(dev_info_t *dip, pcie_msg_type_t msg_type, 11640Sstevel@tonic-gate msiqid_t *msiq_id) 11650Sstevel@tonic-gate { 11660Sstevel@tonic-gate uint64_t ret; 11670Sstevel@tonic-gate 11680Sstevel@tonic-gate DBG(DBG_LIB_MSG, dip, "px_lib_msg_getmsiq: dip 0x%p msg_type 0x%x\n", 11690Sstevel@tonic-gate dip, msg_type); 11700Sstevel@tonic-gate 11710Sstevel@tonic-gate if ((ret = hvio_msg_getmsiq(DIP_TO_HANDLE(dip), 11720Sstevel@tonic-gate msg_type, msiq_id)) != H_EOK) { 11730Sstevel@tonic-gate DBG(DBG_LIB_MSG, dip, 11740Sstevel@tonic-gate "hvio_msg_getmsiq failed, ret 0x%lx\n", ret); 11750Sstevel@tonic-gate return (DDI_FAILURE); 11760Sstevel@tonic-gate } 11770Sstevel@tonic-gate 11780Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msg_getmsiq: msiq_id 0x%x\n", 11790Sstevel@tonic-gate *msiq_id); 11800Sstevel@tonic-gate 11810Sstevel@tonic-gate return (DDI_SUCCESS); 11820Sstevel@tonic-gate } 11830Sstevel@tonic-gate 11840Sstevel@tonic-gate /*ARGSUSED*/ 11850Sstevel@tonic-gate int 11860Sstevel@tonic-gate px_lib_msg_setmsiq(dev_info_t *dip, pcie_msg_type_t msg_type, 11870Sstevel@tonic-gate msiqid_t msiq_id) 11880Sstevel@tonic-gate { 11890Sstevel@tonic-gate uint64_t ret; 11900Sstevel@tonic-gate 11910Sstevel@tonic-gate DBG(DBG_LIB_MSG, dip, "px_lib_msi_setstate: dip 0x%p msg_type 0x%x " 11920Sstevel@tonic-gate "msiq_id 0x%x\n", dip, msg_type, msiq_id); 11930Sstevel@tonic-gate 11940Sstevel@tonic-gate if ((ret = hvio_msg_setmsiq(DIP_TO_HANDLE(dip), 11950Sstevel@tonic-gate msg_type, msiq_id)) != H_EOK) { 11960Sstevel@tonic-gate DBG(DBG_LIB_MSG, dip, 11970Sstevel@tonic-gate "hvio_msg_setmsiq failed, ret 0x%lx\n", ret); 11980Sstevel@tonic-gate return (DDI_FAILURE); 11990Sstevel@tonic-gate } 12000Sstevel@tonic-gate 12010Sstevel@tonic-gate return (DDI_SUCCESS); 12020Sstevel@tonic-gate } 12030Sstevel@tonic-gate 12040Sstevel@tonic-gate /*ARGSUSED*/ 12050Sstevel@tonic-gate int 12060Sstevel@tonic-gate px_lib_msg_getvalid(dev_info_t *dip, pcie_msg_type_t msg_type, 12070Sstevel@tonic-gate pcie_msg_valid_state_t *msg_valid_state) 12080Sstevel@tonic-gate { 12090Sstevel@tonic-gate uint64_t ret; 12100Sstevel@tonic-gate 12110Sstevel@tonic-gate DBG(DBG_LIB_MSG, dip, "px_lib_msg_getvalid: dip 0x%p msg_type 0x%x\n", 12120Sstevel@tonic-gate dip, msg_type); 12130Sstevel@tonic-gate 12140Sstevel@tonic-gate if ((ret = hvio_msg_getvalid(DIP_TO_HANDLE(dip), msg_type, 12150Sstevel@tonic-gate msg_valid_state)) != H_EOK) { 12160Sstevel@tonic-gate DBG(DBG_LIB_MSG, dip, 12170Sstevel@tonic-gate "hvio_msg_getvalid failed, ret 0x%lx\n", ret); 12180Sstevel@tonic-gate return (DDI_FAILURE); 12190Sstevel@tonic-gate } 12200Sstevel@tonic-gate 12210Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msg_getvalid: msg_valid_state 0x%x\n", 12220Sstevel@tonic-gate *msg_valid_state); 12230Sstevel@tonic-gate 12240Sstevel@tonic-gate return (DDI_SUCCESS); 12250Sstevel@tonic-gate } 12260Sstevel@tonic-gate 12270Sstevel@tonic-gate /*ARGSUSED*/ 12280Sstevel@tonic-gate int 12290Sstevel@tonic-gate px_lib_msg_setvalid(dev_info_t *dip, pcie_msg_type_t msg_type, 12300Sstevel@tonic-gate pcie_msg_valid_state_t msg_valid_state) 12310Sstevel@tonic-gate { 12320Sstevel@tonic-gate uint64_t ret; 12330Sstevel@tonic-gate 12340Sstevel@tonic-gate DBG(DBG_LIB_MSG, dip, "px_lib_msg_setvalid: dip 0x%p msg_type 0x%x " 12350Sstevel@tonic-gate "msg_valid_state 0x%x\n", dip, msg_type, msg_valid_state); 12360Sstevel@tonic-gate 12370Sstevel@tonic-gate if ((ret = hvio_msg_setvalid(DIP_TO_HANDLE(dip), msg_type, 12380Sstevel@tonic-gate msg_valid_state)) != H_EOK) { 12390Sstevel@tonic-gate DBG(DBG_LIB_MSG, dip, 12400Sstevel@tonic-gate "hvio_msg_setvalid failed, ret 0x%lx\n", ret); 12410Sstevel@tonic-gate return (DDI_FAILURE); 12420Sstevel@tonic-gate } 12430Sstevel@tonic-gate 12440Sstevel@tonic-gate return (DDI_SUCCESS); 12450Sstevel@tonic-gate } 12460Sstevel@tonic-gate 12470Sstevel@tonic-gate /* 12480Sstevel@tonic-gate * Suspend/Resume Functions: 12490Sstevel@tonic-gate * Currently unsupported by hypervisor 12500Sstevel@tonic-gate */ 12510Sstevel@tonic-gate int 12520Sstevel@tonic-gate px_lib_suspend(dev_info_t *dip) 12530Sstevel@tonic-gate { 12540Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 12550Sstevel@tonic-gate pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 12561648Sjchu px_cb_t *cb_p = PX2CB(px_p); 12570Sstevel@tonic-gate devhandle_t dev_hdl, xbus_dev_hdl; 12581648Sjchu uint64_t ret = H_EOK; 12590Sstevel@tonic-gate 12600Sstevel@tonic-gate DBG(DBG_DETACH, dip, "px_lib_suspend: dip 0x%p\n", dip); 12610Sstevel@tonic-gate 126227Sjchu dev_hdl = (devhandle_t)pxu_p->px_address[PX_REG_CSR]; 126327Sjchu xbus_dev_hdl = (devhandle_t)pxu_p->px_address[PX_REG_XBC]; 12640Sstevel@tonic-gate 12651648Sjchu if ((ret = hvio_suspend(dev_hdl, pxu_p)) != H_EOK) 12661648Sjchu goto fail; 12671648Sjchu 12681648Sjchu if (--cb_p->attachcnt == 0) { 12691648Sjchu ret = hvio_cb_suspend(xbus_dev_hdl, pxu_p); 12701648Sjchu if (ret != H_EOK) 12711648Sjchu cb_p->attachcnt++; 12720Sstevel@tonic-gate } 12733274Set142600 pxu_p->cpr_flag = PX_ENTERED_CPR; 12740Sstevel@tonic-gate 12751648Sjchu fail: 12760Sstevel@tonic-gate return ((ret != H_EOK) ? DDI_FAILURE: DDI_SUCCESS); 12770Sstevel@tonic-gate } 12780Sstevel@tonic-gate 12790Sstevel@tonic-gate void 12800Sstevel@tonic-gate px_lib_resume(dev_info_t *dip) 12810Sstevel@tonic-gate { 12820Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 12830Sstevel@tonic-gate pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 12841648Sjchu px_cb_t *cb_p = PX2CB(px_p); 12850Sstevel@tonic-gate devhandle_t dev_hdl, xbus_dev_hdl; 12860Sstevel@tonic-gate devino_t pec_ino = px_p->px_inos[PX_INTR_PEC]; 12870Sstevel@tonic-gate devino_t xbc_ino = px_p->px_inos[PX_INTR_XBC]; 12880Sstevel@tonic-gate 12890Sstevel@tonic-gate DBG(DBG_ATTACH, dip, "px_lib_resume: dip 0x%p\n", dip); 12900Sstevel@tonic-gate 129127Sjchu dev_hdl = (devhandle_t)pxu_p->px_address[PX_REG_CSR]; 129227Sjchu xbus_dev_hdl = (devhandle_t)pxu_p->px_address[PX_REG_XBC]; 12930Sstevel@tonic-gate 12941648Sjchu if (++cb_p->attachcnt == 1) 12950Sstevel@tonic-gate hvio_cb_resume(dev_hdl, xbus_dev_hdl, xbc_ino, pxu_p); 12960Sstevel@tonic-gate 12971648Sjchu hvio_resume(dev_hdl, pec_ino, pxu_p); 12980Sstevel@tonic-gate } 12990Sstevel@tonic-gate 13001772Sjl139090 /* 13011772Sjl139090 * Generate a unique Oberon UBC ID based on the Logicial System Board and 13021772Sjl139090 * the IO Channel from the portid property field. 13031772Sjl139090 */ 13041772Sjl139090 static uint64_t 13051772Sjl139090 oberon_get_ubc_id(dev_info_t *dip) 13061772Sjl139090 { 13071772Sjl139090 px_t *px_p = DIP_TO_STATE(dip); 13081772Sjl139090 pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 13091772Sjl139090 uint64_t ubc_id; 13101772Sjl139090 13111772Sjl139090 /* 13121772Sjl139090 * Generate a unique 6 bit UBC ID using the 2 IO_Channel#[1:0] bits and 13131772Sjl139090 * the 4 LSB_ID[3:0] bits from the Oberon's portid property. 13141772Sjl139090 */ 13151772Sjl139090 ubc_id = (((pxu_p->portid >> OBERON_PORT_ID_IOC) & 13161772Sjl139090 OBERON_PORT_ID_IOC_MASK) | (((pxu_p->portid >> 13171772Sjl139090 OBERON_PORT_ID_LSB) & OBERON_PORT_ID_LSB_MASK) 13181772Sjl139090 << OBERON_UBC_ID_LSB)); 13191772Sjl139090 13201772Sjl139090 return (ubc_id); 13211772Sjl139090 } 13221772Sjl139090 13231772Sjl139090 /* 13241772Sjl139090 * Oberon does not have a UBC scratch register, so alloc an array of scratch 13251772Sjl139090 * registers when needed and use a unique UBC ID as an index. This code 13261772Sjl139090 * can be simplified if we use a pre-allocated array. They are currently 13271772Sjl139090 * being dynamically allocated because it's only needed by the Oberon. 13281772Sjl139090 */ 13291772Sjl139090 static void 13301772Sjl139090 oberon_set_cb(dev_info_t *dip, uint64_t val) 13311772Sjl139090 { 13321772Sjl139090 uint64_t ubc_id; 13331772Sjl139090 13341772Sjl139090 if (px_oberon_ubc_scratch_regs == NULL) 13351772Sjl139090 px_oberon_ubc_scratch_regs = 13361772Sjl139090 (uint64_t *)kmem_zalloc(sizeof (uint64_t)* 13371772Sjl139090 OBERON_UBC_ID_MAX, KM_SLEEP); 13381772Sjl139090 13391772Sjl139090 ubc_id = oberon_get_ubc_id(dip); 13401772Sjl139090 13411772Sjl139090 px_oberon_ubc_scratch_regs[ubc_id] = val; 13421772Sjl139090 13431772Sjl139090 /* 13441772Sjl139090 * Check if any scratch registers are still in use. If all scratch 13451772Sjl139090 * registers are currently set to zero, then deallocate the scratch 13461772Sjl139090 * register array. 13471772Sjl139090 */ 13481772Sjl139090 for (ubc_id = 0; ubc_id < OBERON_UBC_ID_MAX; ubc_id++) { 13491772Sjl139090 if (px_oberon_ubc_scratch_regs[ubc_id] != NULL) 13501772Sjl139090 return; 13511772Sjl139090 } 13521772Sjl139090 13531772Sjl139090 /* 13541772Sjl139090 * All scratch registers are set to zero so deallocate the scratch 13551772Sjl139090 * register array and set the pointer to NULL. 13561772Sjl139090 */ 13571772Sjl139090 kmem_free(px_oberon_ubc_scratch_regs, 13581772Sjl139090 (sizeof (uint64_t)*OBERON_UBC_ID_MAX)); 13591772Sjl139090 13601772Sjl139090 px_oberon_ubc_scratch_regs = NULL; 13611772Sjl139090 } 13621772Sjl139090 13631772Sjl139090 /* 13641772Sjl139090 * Oberon does not have a UBC scratch register, so use an allocated array of 13651772Sjl139090 * scratch registers and use the unique UBC ID as an index into that array. 13661772Sjl139090 */ 13671772Sjl139090 static uint64_t 13681772Sjl139090 oberon_get_cb(dev_info_t *dip) 13691772Sjl139090 { 13701772Sjl139090 uint64_t ubc_id; 13711772Sjl139090 13721772Sjl139090 if (px_oberon_ubc_scratch_regs == NULL) 13731772Sjl139090 return (0); 13741772Sjl139090 13751772Sjl139090 ubc_id = oberon_get_ubc_id(dip); 13761772Sjl139090 13771772Sjl139090 return (px_oberon_ubc_scratch_regs[ubc_id]); 13781772Sjl139090 } 13791772Sjl139090 13801772Sjl139090 /* 13811772Sjl139090 * Misc Functions: 13821772Sjl139090 * Currently unsupported by hypervisor 13831772Sjl139090 */ 13841772Sjl139090 static uint64_t 13851772Sjl139090 px_get_cb(dev_info_t *dip) 13861772Sjl139090 { 13871772Sjl139090 px_t *px_p = DIP_TO_STATE(dip); 13881772Sjl139090 pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 13891772Sjl139090 13901772Sjl139090 /* 13911772Sjl139090 * Oberon does not currently have Scratchpad registers. 13921772Sjl139090 */ 13931772Sjl139090 if (PX_CHIP_TYPE(pxu_p) == PX_CHIP_OBERON) 13941772Sjl139090 return (oberon_get_cb(dip)); 13951772Sjl139090 13961772Sjl139090 return (CSR_XR((caddr_t)pxu_p->px_address[PX_REG_XBC], JBUS_SCRATCH_1)); 13971772Sjl139090 } 13981772Sjl139090 13991772Sjl139090 static void 14001772Sjl139090 px_set_cb(dev_info_t *dip, uint64_t val) 14011772Sjl139090 { 14021772Sjl139090 px_t *px_p = DIP_TO_STATE(dip); 14031772Sjl139090 pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 14041772Sjl139090 14051772Sjl139090 /* 14061772Sjl139090 * Oberon does not currently have Scratchpad registers. 14071772Sjl139090 */ 14081772Sjl139090 if (PX_CHIP_TYPE(pxu_p) == PX_CHIP_OBERON) { 14091772Sjl139090 oberon_set_cb(dip, val); 14101772Sjl139090 return; 14111772Sjl139090 } 14121772Sjl139090 14131772Sjl139090 CSR_XS((caddr_t)pxu_p->px_address[PX_REG_XBC], JBUS_SCRATCH_1, val); 14141772Sjl139090 } 14151772Sjl139090 14160Sstevel@tonic-gate /*ARGSUSED*/ 14170Sstevel@tonic-gate int 14180Sstevel@tonic-gate px_lib_map_vconfig(dev_info_t *dip, 14190Sstevel@tonic-gate ddi_map_req_t *mp, pci_config_offset_t off, 14200Sstevel@tonic-gate pci_regspec_t *rp, caddr_t *addrp) 14210Sstevel@tonic-gate { 14220Sstevel@tonic-gate /* 14230Sstevel@tonic-gate * No special config space access services in this layer. 14240Sstevel@tonic-gate */ 14250Sstevel@tonic-gate return (DDI_FAILURE); 14260Sstevel@tonic-gate } 14270Sstevel@tonic-gate 1428624Sschwartz void 1429677Sjchu px_lib_map_attr_check(ddi_map_req_t *mp) 1430677Sjchu { 1431677Sjchu ddi_acc_hdl_t *hp = mp->map_handlep; 1432677Sjchu 1433677Sjchu /* fire does not accept byte masks from PIO store merge */ 1434677Sjchu if (hp->ah_acc.devacc_attr_dataorder == DDI_STORECACHING_OK_ACC) 1435677Sjchu hp->ah_acc.devacc_attr_dataorder = DDI_STRICTORDER_ACC; 1436677Sjchu } 1437677Sjchu 14383274Set142600 /* This function is called only by poke, caut put and pxtool poke. */ 1439677Sjchu void 14403274Set142600 px_lib_clr_errs(px_t *px_p, dev_info_t *rdip, uint64_t addr) 144127Sjchu { 1442624Sschwartz px_pec_t *pec_p = px_p->px_pec_p; 144327Sjchu dev_info_t *rpdip = px_p->px_dip; 14443274Set142600 int rc_err, fab_err, i; 144527Sjchu int acctype = pec_p->pec_safeacc_type; 144627Sjchu ddi_fm_error_t derr; 14473274Set142600 px_ranges_t *ranges_p; 14483274Set142600 int range_len; 14493274Set142600 uint32_t addr_high, addr_low; 14503274Set142600 pcie_req_id_t bdf = 0; 145127Sjchu 145227Sjchu /* Create the derr */ 145327Sjchu bzero(&derr, sizeof (ddi_fm_error_t)); 145427Sjchu derr.fme_version = DDI_FME_VERSION; 145527Sjchu derr.fme_ena = fm_ena_generate(0, FM_ENA_FMT1); 145627Sjchu derr.fme_flag = acctype; 145727Sjchu 145827Sjchu if (acctype == DDI_FM_ERR_EXPECTED) { 145927Sjchu derr.fme_status = DDI_FM_NONFATAL; 146027Sjchu ndi_fm_acc_err_set(pec_p->pec_acc_hdl, &derr); 146127Sjchu } 146227Sjchu 14636313Skrishnae if (px_fm_enter(px_p) != DDI_SUCCESS) 14646313Skrishnae return; 146527Sjchu 146627Sjchu /* send ereport/handle/clear fire registers */ 14673274Set142600 rc_err = px_err_cmn_intr(px_p, &derr, PX_LIB_CALL, PX_FM_BLOCK_ALL); 14683274Set142600 14693274Set142600 /* Figure out if this is a cfg or mem32 access */ 14703274Set142600 addr_high = (uint32_t)(addr >> 32); 14713274Set142600 addr_low = (uint32_t)addr; 14723274Set142600 range_len = px_p->px_ranges_length / sizeof (px_ranges_t); 14733274Set142600 i = 0; 14743274Set142600 for (ranges_p = px_p->px_ranges_p; i < range_len; i++, ranges_p++) { 14753274Set142600 if (ranges_p->parent_high == addr_high) { 14763274Set142600 switch (ranges_p->child_high & PCI_ADDR_MASK) { 14773274Set142600 case PCI_ADDR_CONFIG: 14783274Set142600 bdf = (pcie_req_id_t)(addr_low >> 12); 14793274Set142600 addr_low = 0; 14803274Set142600 break; 14813274Set142600 case PCI_ADDR_MEM32: 14823274Set142600 if (rdip) 14836313Skrishnae bdf = PCI_GET_BDF(rdip); 14843274Set142600 else 14853274Set142600 bdf = NULL; 14863274Set142600 break; 14873274Set142600 } 14883274Set142600 break; 14893274Set142600 } 14903274Set142600 } 14913274Set142600 14923274Set142600 px_rp_en_q(px_p, bdf, addr_low, NULL); 14933274Set142600 14943274Set142600 /* 14953274Set142600 * XXX - Current code scans the fabric for all px_tool accesses. 14963274Set142600 * In future, do not scan fabric for px_tool access to IO Root Nexus 14973274Set142600 */ 14986313Skrishnae fab_err = px_scan_fabric(px_p, rpdip, &derr); 14996313Skrishnae 15006313Skrishnae px_err_panic(rc_err, PX_RC, fab_err, B_TRUE); 15016313Skrishnae px_fm_exit(px_p); 15026313Skrishnae px_err_panic(rc_err, PX_RC, fab_err, B_FALSE); 150327Sjchu } 150427Sjchu 15050Sstevel@tonic-gate #ifdef DEBUG 15060Sstevel@tonic-gate int px_peekfault_cnt = 0; 15070Sstevel@tonic-gate int px_pokefault_cnt = 0; 15080Sstevel@tonic-gate #endif /* DEBUG */ 15090Sstevel@tonic-gate 15100Sstevel@tonic-gate /*ARGSUSED*/ 15110Sstevel@tonic-gate static int 15120Sstevel@tonic-gate px_lib_do_poke(dev_info_t *dip, dev_info_t *rdip, 15130Sstevel@tonic-gate peekpoke_ctlops_t *in_args) 15140Sstevel@tonic-gate { 15150Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 15160Sstevel@tonic-gate px_pec_t *pec_p = px_p->px_pec_p; 15170Sstevel@tonic-gate int err = DDI_SUCCESS; 15180Sstevel@tonic-gate on_trap_data_t otd; 15190Sstevel@tonic-gate 15200Sstevel@tonic-gate mutex_enter(&pec_p->pec_pokefault_mutex); 15210Sstevel@tonic-gate pec_p->pec_ontrap_data = &otd; 152227Sjchu pec_p->pec_safeacc_type = DDI_FM_ERR_POKE; 15230Sstevel@tonic-gate 15240Sstevel@tonic-gate /* Set up protected environment. */ 15250Sstevel@tonic-gate if (!on_trap(&otd, OT_DATA_ACCESS)) { 15260Sstevel@tonic-gate uintptr_t tramp = otd.ot_trampoline; 15270Sstevel@tonic-gate 15280Sstevel@tonic-gate otd.ot_trampoline = (uintptr_t)&poke_fault; 15290Sstevel@tonic-gate err = do_poke(in_args->size, (void *)in_args->dev_addr, 15300Sstevel@tonic-gate (void *)in_args->host_addr); 15310Sstevel@tonic-gate otd.ot_trampoline = tramp; 15320Sstevel@tonic-gate } else 15330Sstevel@tonic-gate err = DDI_FAILURE; 15340Sstevel@tonic-gate 15353274Set142600 px_lib_clr_errs(px_p, rdip, in_args->dev_addr); 153627Sjchu 15370Sstevel@tonic-gate if (otd.ot_trap & OT_DATA_ACCESS) 15380Sstevel@tonic-gate err = DDI_FAILURE; 15390Sstevel@tonic-gate 15400Sstevel@tonic-gate /* Take down protected environment. */ 15410Sstevel@tonic-gate no_trap(); 15420Sstevel@tonic-gate 15430Sstevel@tonic-gate pec_p->pec_ontrap_data = NULL; 154427Sjchu pec_p->pec_safeacc_type = DDI_FM_ERR_UNEXPECTED; 15450Sstevel@tonic-gate mutex_exit(&pec_p->pec_pokefault_mutex); 15460Sstevel@tonic-gate 15470Sstevel@tonic-gate #ifdef DEBUG 15480Sstevel@tonic-gate if (err == DDI_FAILURE) 15490Sstevel@tonic-gate px_pokefault_cnt++; 15500Sstevel@tonic-gate #endif 15510Sstevel@tonic-gate return (err); 15520Sstevel@tonic-gate } 15530Sstevel@tonic-gate 15540Sstevel@tonic-gate /*ARGSUSED*/ 15550Sstevel@tonic-gate static int 15560Sstevel@tonic-gate px_lib_do_caut_put(dev_info_t *dip, dev_info_t *rdip, 15570Sstevel@tonic-gate peekpoke_ctlops_t *cautacc_ctlops_arg) 15580Sstevel@tonic-gate { 15590Sstevel@tonic-gate size_t size = cautacc_ctlops_arg->size; 15600Sstevel@tonic-gate uintptr_t dev_addr = cautacc_ctlops_arg->dev_addr; 15610Sstevel@tonic-gate uintptr_t host_addr = cautacc_ctlops_arg->host_addr; 15620Sstevel@tonic-gate ddi_acc_impl_t *hp = (ddi_acc_impl_t *)cautacc_ctlops_arg->handle; 15630Sstevel@tonic-gate size_t repcount = cautacc_ctlops_arg->repcount; 15640Sstevel@tonic-gate uint_t flags = cautacc_ctlops_arg->flags; 15650Sstevel@tonic-gate 15660Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 15670Sstevel@tonic-gate px_pec_t *pec_p = px_p->px_pec_p; 15680Sstevel@tonic-gate int err = DDI_SUCCESS; 15690Sstevel@tonic-gate 157027Sjchu /* 157127Sjchu * Note that i_ndi_busop_access_enter ends up grabbing the pokefault 157227Sjchu * mutex. 157327Sjchu */ 15740Sstevel@tonic-gate i_ndi_busop_access_enter(hp->ahi_common.ah_dip, (ddi_acc_handle_t)hp); 15750Sstevel@tonic-gate 157627Sjchu pec_p->pec_ontrap_data = (on_trap_data_t *)hp->ahi_err->err_ontrap; 157727Sjchu pec_p->pec_safeacc_type = DDI_FM_ERR_EXPECTED; 157827Sjchu hp->ahi_err->err_expected = DDI_FM_ERR_EXPECTED; 15790Sstevel@tonic-gate 15800Sstevel@tonic-gate if (!i_ddi_ontrap((ddi_acc_handle_t)hp)) { 15810Sstevel@tonic-gate for (; repcount; repcount--) { 15820Sstevel@tonic-gate switch (size) { 15830Sstevel@tonic-gate 15840Sstevel@tonic-gate case sizeof (uint8_t): 15850Sstevel@tonic-gate i_ddi_put8(hp, (uint8_t *)dev_addr, 15860Sstevel@tonic-gate *(uint8_t *)host_addr); 15870Sstevel@tonic-gate break; 15880Sstevel@tonic-gate 15890Sstevel@tonic-gate case sizeof (uint16_t): 15900Sstevel@tonic-gate i_ddi_put16(hp, (uint16_t *)dev_addr, 15910Sstevel@tonic-gate *(uint16_t *)host_addr); 15920Sstevel@tonic-gate break; 15930Sstevel@tonic-gate 15940Sstevel@tonic-gate case sizeof (uint32_t): 15950Sstevel@tonic-gate i_ddi_put32(hp, (uint32_t *)dev_addr, 15960Sstevel@tonic-gate *(uint32_t *)host_addr); 15970Sstevel@tonic-gate break; 15980Sstevel@tonic-gate 15990Sstevel@tonic-gate case sizeof (uint64_t): 16000Sstevel@tonic-gate i_ddi_put64(hp, (uint64_t *)dev_addr, 16010Sstevel@tonic-gate *(uint64_t *)host_addr); 16020Sstevel@tonic-gate break; 16030Sstevel@tonic-gate } 16040Sstevel@tonic-gate 16050Sstevel@tonic-gate host_addr += size; 16060Sstevel@tonic-gate 16070Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR) 16080Sstevel@tonic-gate dev_addr += size; 16090Sstevel@tonic-gate 16103274Set142600 px_lib_clr_errs(px_p, rdip, dev_addr); 161127Sjchu 16120Sstevel@tonic-gate if (pec_p->pec_ontrap_data->ot_trap & OT_DATA_ACCESS) { 16130Sstevel@tonic-gate err = DDI_FAILURE; 16140Sstevel@tonic-gate #ifdef DEBUG 16150Sstevel@tonic-gate px_pokefault_cnt++; 16160Sstevel@tonic-gate #endif 16170Sstevel@tonic-gate break; 16180Sstevel@tonic-gate } 16190Sstevel@tonic-gate } 16200Sstevel@tonic-gate } 16210Sstevel@tonic-gate 16220Sstevel@tonic-gate i_ddi_notrap((ddi_acc_handle_t)hp); 16230Sstevel@tonic-gate pec_p->pec_ontrap_data = NULL; 162427Sjchu pec_p->pec_safeacc_type = DDI_FM_ERR_UNEXPECTED; 16250Sstevel@tonic-gate i_ndi_busop_access_exit(hp->ahi_common.ah_dip, (ddi_acc_handle_t)hp); 16260Sstevel@tonic-gate hp->ahi_err->err_expected = DDI_FM_ERR_UNEXPECTED; 16270Sstevel@tonic-gate 16280Sstevel@tonic-gate return (err); 16290Sstevel@tonic-gate } 16300Sstevel@tonic-gate 16310Sstevel@tonic-gate 16320Sstevel@tonic-gate int 16330Sstevel@tonic-gate px_lib_ctlops_poke(dev_info_t *dip, dev_info_t *rdip, 16340Sstevel@tonic-gate peekpoke_ctlops_t *in_args) 16350Sstevel@tonic-gate { 16360Sstevel@tonic-gate return (in_args->handle ? px_lib_do_caut_put(dip, rdip, in_args) : 16370Sstevel@tonic-gate px_lib_do_poke(dip, rdip, in_args)); 16380Sstevel@tonic-gate } 16390Sstevel@tonic-gate 16400Sstevel@tonic-gate 16410Sstevel@tonic-gate /*ARGSUSED*/ 16420Sstevel@tonic-gate static int 16430Sstevel@tonic-gate px_lib_do_peek(dev_info_t *dip, peekpoke_ctlops_t *in_args) 16440Sstevel@tonic-gate { 164527Sjchu px_t *px_p = DIP_TO_STATE(dip); 164627Sjchu px_pec_t *pec_p = px_p->px_pec_p; 16470Sstevel@tonic-gate int err = DDI_SUCCESS; 16480Sstevel@tonic-gate on_trap_data_t otd; 16490Sstevel@tonic-gate 165027Sjchu mutex_enter(&pec_p->pec_pokefault_mutex); 16516313Skrishnae if (px_fm_enter(px_p) != DDI_SUCCESS) 16526313Skrishnae return (DDI_FAILURE); 165327Sjchu pec_p->pec_safeacc_type = DDI_FM_ERR_PEEK; 16546313Skrishnae px_fm_exit(px_p); 165527Sjchu 16560Sstevel@tonic-gate if (!on_trap(&otd, OT_DATA_ACCESS)) { 16570Sstevel@tonic-gate uintptr_t tramp = otd.ot_trampoline; 16580Sstevel@tonic-gate 16590Sstevel@tonic-gate otd.ot_trampoline = (uintptr_t)&peek_fault; 16600Sstevel@tonic-gate err = do_peek(in_args->size, (void *)in_args->dev_addr, 16610Sstevel@tonic-gate (void *)in_args->host_addr); 16620Sstevel@tonic-gate otd.ot_trampoline = tramp; 16630Sstevel@tonic-gate } else 16640Sstevel@tonic-gate err = DDI_FAILURE; 16650Sstevel@tonic-gate 16660Sstevel@tonic-gate no_trap(); 166727Sjchu pec_p->pec_safeacc_type = DDI_FM_ERR_UNEXPECTED; 166827Sjchu mutex_exit(&pec_p->pec_pokefault_mutex); 16690Sstevel@tonic-gate 16700Sstevel@tonic-gate #ifdef DEBUG 16710Sstevel@tonic-gate if (err == DDI_FAILURE) 16720Sstevel@tonic-gate px_peekfault_cnt++; 16730Sstevel@tonic-gate #endif 16740Sstevel@tonic-gate return (err); 16750Sstevel@tonic-gate } 16760Sstevel@tonic-gate 16770Sstevel@tonic-gate 16780Sstevel@tonic-gate static int 16790Sstevel@tonic-gate px_lib_do_caut_get(dev_info_t *dip, peekpoke_ctlops_t *cautacc_ctlops_arg) 16800Sstevel@tonic-gate { 16810Sstevel@tonic-gate size_t size = cautacc_ctlops_arg->size; 16820Sstevel@tonic-gate uintptr_t dev_addr = cautacc_ctlops_arg->dev_addr; 16830Sstevel@tonic-gate uintptr_t host_addr = cautacc_ctlops_arg->host_addr; 16840Sstevel@tonic-gate ddi_acc_impl_t *hp = (ddi_acc_impl_t *)cautacc_ctlops_arg->handle; 16850Sstevel@tonic-gate size_t repcount = cautacc_ctlops_arg->repcount; 16860Sstevel@tonic-gate uint_t flags = cautacc_ctlops_arg->flags; 16870Sstevel@tonic-gate 16880Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 16890Sstevel@tonic-gate px_pec_t *pec_p = px_p->px_pec_p; 16900Sstevel@tonic-gate int err = DDI_SUCCESS; 16910Sstevel@tonic-gate 169227Sjchu /* 169327Sjchu * Note that i_ndi_busop_access_enter ends up grabbing the pokefault 169427Sjchu * mutex. 169527Sjchu */ 169627Sjchu i_ndi_busop_access_enter(hp->ahi_common.ah_dip, (ddi_acc_handle_t)hp); 169727Sjchu 169827Sjchu pec_p->pec_ontrap_data = (on_trap_data_t *)hp->ahi_err->err_ontrap; 169927Sjchu pec_p->pec_safeacc_type = DDI_FM_ERR_EXPECTED; 17000Sstevel@tonic-gate hp->ahi_err->err_expected = DDI_FM_ERR_EXPECTED; 17010Sstevel@tonic-gate 17020Sstevel@tonic-gate if (repcount == 1) { 17030Sstevel@tonic-gate if (!i_ddi_ontrap((ddi_acc_handle_t)hp)) { 17040Sstevel@tonic-gate i_ddi_caut_get(size, (void *)dev_addr, 17050Sstevel@tonic-gate (void *)host_addr); 17060Sstevel@tonic-gate } else { 17070Sstevel@tonic-gate int i; 17080Sstevel@tonic-gate uint8_t *ff_addr = (uint8_t *)host_addr; 17090Sstevel@tonic-gate for (i = 0; i < size; i++) 17100Sstevel@tonic-gate *ff_addr++ = 0xff; 17110Sstevel@tonic-gate 17120Sstevel@tonic-gate err = DDI_FAILURE; 17130Sstevel@tonic-gate #ifdef DEBUG 17140Sstevel@tonic-gate px_peekfault_cnt++; 17150Sstevel@tonic-gate #endif 17160Sstevel@tonic-gate } 17170Sstevel@tonic-gate } else { 17180Sstevel@tonic-gate if (!i_ddi_ontrap((ddi_acc_handle_t)hp)) { 17190Sstevel@tonic-gate for (; repcount; repcount--) { 17200Sstevel@tonic-gate i_ddi_caut_get(size, (void *)dev_addr, 17210Sstevel@tonic-gate (void *)host_addr); 17220Sstevel@tonic-gate 17230Sstevel@tonic-gate host_addr += size; 17240Sstevel@tonic-gate 17250Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR) 17260Sstevel@tonic-gate dev_addr += size; 17270Sstevel@tonic-gate } 17280Sstevel@tonic-gate } else { 17290Sstevel@tonic-gate err = DDI_FAILURE; 17300Sstevel@tonic-gate #ifdef DEBUG 17310Sstevel@tonic-gate px_peekfault_cnt++; 17320Sstevel@tonic-gate #endif 17330Sstevel@tonic-gate } 17340Sstevel@tonic-gate } 17350Sstevel@tonic-gate 17360Sstevel@tonic-gate i_ddi_notrap((ddi_acc_handle_t)hp); 17370Sstevel@tonic-gate pec_p->pec_ontrap_data = NULL; 173827Sjchu pec_p->pec_safeacc_type = DDI_FM_ERR_UNEXPECTED; 17390Sstevel@tonic-gate i_ndi_busop_access_exit(hp->ahi_common.ah_dip, (ddi_acc_handle_t)hp); 17400Sstevel@tonic-gate hp->ahi_err->err_expected = DDI_FM_ERR_UNEXPECTED; 17410Sstevel@tonic-gate 17420Sstevel@tonic-gate return (err); 17430Sstevel@tonic-gate } 17440Sstevel@tonic-gate 17450Sstevel@tonic-gate /*ARGSUSED*/ 17460Sstevel@tonic-gate int 17470Sstevel@tonic-gate px_lib_ctlops_peek(dev_info_t *dip, dev_info_t *rdip, 17480Sstevel@tonic-gate peekpoke_ctlops_t *in_args, void *result) 17490Sstevel@tonic-gate { 17500Sstevel@tonic-gate result = (void *)in_args->host_addr; 17510Sstevel@tonic-gate return (in_args->handle ? px_lib_do_caut_get(dip, in_args) : 17520Sstevel@tonic-gate px_lib_do_peek(dip, in_args)); 17530Sstevel@tonic-gate } 1754118Sjchu 17550Sstevel@tonic-gate /* 17560Sstevel@tonic-gate * implements PPM interface 17570Sstevel@tonic-gate */ 17580Sstevel@tonic-gate int 17590Sstevel@tonic-gate px_lib_pmctl(int cmd, px_t *px_p) 17600Sstevel@tonic-gate { 17610Sstevel@tonic-gate ASSERT((cmd & ~PPMREQ_MASK) == PPMREQ); 17620Sstevel@tonic-gate switch (cmd) { 17630Sstevel@tonic-gate case PPMREQ_PRE_PWR_OFF: 17640Sstevel@tonic-gate /* 17650Sstevel@tonic-gate * Currently there is no device power management for 17660Sstevel@tonic-gate * the root complex (fire). When there is we need to make 17670Sstevel@tonic-gate * sure that it is at full power before trying to send the 17680Sstevel@tonic-gate * PME_Turn_Off message. 17690Sstevel@tonic-gate */ 17700Sstevel@tonic-gate DBG(DBG_PWR, px_p->px_dip, 17710Sstevel@tonic-gate "ioctl: request to send PME_Turn_Off\n"); 17720Sstevel@tonic-gate return (px_goto_l23ready(px_p)); 17730Sstevel@tonic-gate 17740Sstevel@tonic-gate case PPMREQ_PRE_PWR_ON: 1775118Sjchu DBG(DBG_PWR, px_p->px_dip, "ioctl: PRE_PWR_ON request\n"); 1776118Sjchu return (px_pre_pwron_check(px_p)); 1777118Sjchu 17780Sstevel@tonic-gate case PPMREQ_POST_PWR_ON: 1779118Sjchu DBG(DBG_PWR, px_p->px_dip, "ioctl: POST_PWR_ON request\n"); 1780118Sjchu return (px_goto_l0(px_p)); 17810Sstevel@tonic-gate 17820Sstevel@tonic-gate default: 17830Sstevel@tonic-gate return (DDI_FAILURE); 17840Sstevel@tonic-gate } 17850Sstevel@tonic-gate } 17860Sstevel@tonic-gate 17870Sstevel@tonic-gate /* 17880Sstevel@tonic-gate * sends PME_Turn_Off message to put the link in L2/L3 ready state. 17890Sstevel@tonic-gate * called by px_ioctl. 17900Sstevel@tonic-gate * returns DDI_SUCCESS or DDI_FAILURE 17910Sstevel@tonic-gate * 1. Wait for link to be in L1 state (link status reg) 17920Sstevel@tonic-gate * 2. write to PME_Turn_off reg to boradcast 17930Sstevel@tonic-gate * 3. set timeout 17940Sstevel@tonic-gate * 4. If timeout, return failure. 17950Sstevel@tonic-gate * 5. If PM_TO_Ack, wait till link is in L2/L3 ready 17960Sstevel@tonic-gate */ 17970Sstevel@tonic-gate static int 17980Sstevel@tonic-gate px_goto_l23ready(px_t *px_p) 17990Sstevel@tonic-gate { 18000Sstevel@tonic-gate pcie_pwr_t *pwr_p; 180127Sjchu pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 180227Sjchu caddr_t csr_base = (caddr_t)pxu_p->px_address[PX_REG_CSR]; 18030Sstevel@tonic-gate int ret = DDI_SUCCESS; 18040Sstevel@tonic-gate clock_t end, timeleft; 1805118Sjchu int mutex_held = 1; 18060Sstevel@tonic-gate 18070Sstevel@tonic-gate /* If no PM info, return failure */ 18080Sstevel@tonic-gate if (!PCIE_PMINFO(px_p->px_dip) || 18090Sstevel@tonic-gate !(pwr_p = PCIE_NEXUS_PMINFO(px_p->px_dip))) 18100Sstevel@tonic-gate return (DDI_FAILURE); 18110Sstevel@tonic-gate 18120Sstevel@tonic-gate mutex_enter(&pwr_p->pwr_lock); 1813118Sjchu mutex_enter(&px_p->px_l23ready_lock); 18140Sstevel@tonic-gate /* Clear the PME_To_ACK receieved flag */ 1815118Sjchu px_p->px_pm_flags &= ~PX_PMETOACK_RECVD; 1816287Smg140465 /* 1817287Smg140465 * When P25 is the downstream device, after receiving 1818287Smg140465 * PME_To_ACK, fire will go to Detect state, which causes 1819287Smg140465 * the link down event. Inform FMA that this is expected. 1820287Smg140465 * In case of all other cards complaint with the pci express 1821287Smg140465 * spec, this will happen when the power is re-applied. FMA 1822287Smg140465 * code will clear this flag after one instance of LDN. Since 1823287Smg140465 * there will not be a LDN event for the spec compliant cards, 1824287Smg140465 * we need to clear the flag after receiving PME_To_ACK. 1825287Smg140465 */ 1826287Smg140465 px_p->px_pm_flags |= PX_LDN_EXPECTED; 18270Sstevel@tonic-gate if (px_send_pme_turnoff(csr_base) != DDI_SUCCESS) { 18280Sstevel@tonic-gate ret = DDI_FAILURE; 18290Sstevel@tonic-gate goto l23ready_done; 18300Sstevel@tonic-gate } 1831118Sjchu px_p->px_pm_flags |= PX_PME_TURNOFF_PENDING; 18320Sstevel@tonic-gate 18330Sstevel@tonic-gate end = ddi_get_lbolt() + drv_usectohz(px_pme_to_ack_timeout); 1834118Sjchu while (!(px_p->px_pm_flags & PX_PMETOACK_RECVD)) { 1835118Sjchu timeleft = cv_timedwait(&px_p->px_l23ready_cv, 1836118Sjchu &px_p->px_l23ready_lock, end); 18370Sstevel@tonic-gate /* 18380Sstevel@tonic-gate * if cv_timedwait returns -1, it is either 18390Sstevel@tonic-gate * 1) timed out or 18400Sstevel@tonic-gate * 2) there was a pre-mature wakeup but by the time 18410Sstevel@tonic-gate * cv_timedwait is called again end < lbolt i.e. 18420Sstevel@tonic-gate * end is in the past. 18430Sstevel@tonic-gate * 3) By the time we make first cv_timedwait call, 18440Sstevel@tonic-gate * end < lbolt is true. 18450Sstevel@tonic-gate */ 18460Sstevel@tonic-gate if (timeleft == -1) 18470Sstevel@tonic-gate break; 18480Sstevel@tonic-gate } 1849118Sjchu if (!(px_p->px_pm_flags & PX_PMETOACK_RECVD)) { 18500Sstevel@tonic-gate /* 18510Sstevel@tonic-gate * Either timedout or interrupt didn't get a 18520Sstevel@tonic-gate * chance to grab the mutex and set the flag. 18530Sstevel@tonic-gate * release the mutex and delay for sometime. 18540Sstevel@tonic-gate * This will 1) give a chance for interrupt to 18550Sstevel@tonic-gate * set the flag 2) creates a delay between two 18560Sstevel@tonic-gate * consequetive requests. 18570Sstevel@tonic-gate */ 1858118Sjchu mutex_exit(&px_p->px_l23ready_lock); 18591147Sjchu delay(drv_usectohz(50 * PX_MSEC_TO_USEC)); 1860118Sjchu mutex_held = 0; 1861118Sjchu if (!(px_p->px_pm_flags & PX_PMETOACK_RECVD)) { 18620Sstevel@tonic-gate ret = DDI_FAILURE; 18630Sstevel@tonic-gate DBG(DBG_PWR, px_p->px_dip, " Timed out while waiting" 18640Sstevel@tonic-gate " for PME_TO_ACK\n"); 18650Sstevel@tonic-gate } 18660Sstevel@tonic-gate } 1867287Smg140465 px_p->px_pm_flags &= 1868287Smg140465 ~(PX_PME_TURNOFF_PENDING | PX_PMETOACK_RECVD | PX_LDN_EXPECTED); 18690Sstevel@tonic-gate 18700Sstevel@tonic-gate l23ready_done: 1871118Sjchu if (mutex_held) 1872118Sjchu mutex_exit(&px_p->px_l23ready_lock); 1873118Sjchu /* 1874118Sjchu * Wait till link is in L1 idle, if sending PME_Turn_Off 1875118Sjchu * was succesful. 1876118Sjchu */ 1877118Sjchu if (ret == DDI_SUCCESS) { 1878118Sjchu if (px_link_wait4l1idle(csr_base) != DDI_SUCCESS) { 1879118Sjchu DBG(DBG_PWR, px_p->px_dip, " Link is not at L1" 1880287Smg140465 " even though we received PME_To_ACK.\n"); 1881287Smg140465 /* 1882287Smg140465 * Workaround for hardware bug with P25. 1883287Smg140465 * Due to a hardware bug with P25, link state 1884287Smg140465 * will be Detect state rather than L1 after 1885287Smg140465 * link is transitioned to L23Ready state. Since 1886287Smg140465 * we don't know whether link is L23ready state 1887287Smg140465 * without Fire's state being L1_idle, we delay 1888287Smg140465 * here just to make sure that we wait till link 1889287Smg140465 * is transitioned to L23Ready state. 1890287Smg140465 */ 18911147Sjchu delay(drv_usectohz(100 * PX_MSEC_TO_USEC)); 1892287Smg140465 } 1893287Smg140465 pwr_p->pwr_link_lvl = PM_LEVEL_L3; 1894118Sjchu 1895118Sjchu } 18960Sstevel@tonic-gate mutex_exit(&pwr_p->pwr_lock); 18970Sstevel@tonic-gate return (ret); 18980Sstevel@tonic-gate } 18990Sstevel@tonic-gate 1900118Sjchu /* 1901118Sjchu * Message interrupt handler intended to be shared for both 1902118Sjchu * PME and PME_TO_ACK msg handling, currently only handles 1903118Sjchu * PME_To_ACK message. 1904118Sjchu */ 1905118Sjchu uint_t 1906118Sjchu px_pmeq_intr(caddr_t arg) 1907118Sjchu { 1908118Sjchu px_t *px_p = (px_t *)arg; 1909118Sjchu 1910287Smg140465 DBG(DBG_PWR, px_p->px_dip, " PME_To_ACK received \n"); 1911118Sjchu mutex_enter(&px_p->px_l23ready_lock); 1912118Sjchu cv_broadcast(&px_p->px_l23ready_cv); 1913118Sjchu if (px_p->px_pm_flags & PX_PME_TURNOFF_PENDING) { 1914118Sjchu px_p->px_pm_flags |= PX_PMETOACK_RECVD; 1915118Sjchu } else { 1916118Sjchu /* 1917118Sjchu * This maybe the second ack received. If so then, 1918118Sjchu * we should be receiving it during wait4L1 stage. 1919118Sjchu */ 1920118Sjchu px_p->px_pmetoack_ignored++; 1921118Sjchu } 1922118Sjchu mutex_exit(&px_p->px_l23ready_lock); 1923118Sjchu return (DDI_INTR_CLAIMED); 1924118Sjchu } 1925118Sjchu 1926118Sjchu static int 1927118Sjchu px_pre_pwron_check(px_t *px_p) 1928118Sjchu { 1929118Sjchu pcie_pwr_t *pwr_p; 1930118Sjchu 1931118Sjchu /* If no PM info, return failure */ 1932118Sjchu if (!PCIE_PMINFO(px_p->px_dip) || 1933118Sjchu !(pwr_p = PCIE_NEXUS_PMINFO(px_p->px_dip))) 1934118Sjchu return (DDI_FAILURE); 1935118Sjchu 1936287Smg140465 /* 1937287Smg140465 * For the spec compliant downstream cards link down 1938287Smg140465 * is expected when the device is powered on. 1939287Smg140465 */ 1940287Smg140465 px_p->px_pm_flags |= PX_LDN_EXPECTED; 1941118Sjchu return (pwr_p->pwr_link_lvl == PM_LEVEL_L3 ? DDI_SUCCESS : DDI_FAILURE); 1942118Sjchu } 1943118Sjchu 1944118Sjchu static int 1945118Sjchu px_goto_l0(px_t *px_p) 1946118Sjchu { 1947118Sjchu pcie_pwr_t *pwr_p; 1948118Sjchu pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 1949118Sjchu caddr_t csr_base = (caddr_t)pxu_p->px_address[PX_REG_CSR]; 1950118Sjchu int ret = DDI_SUCCESS; 19511147Sjchu uint64_t time_spent = 0; 1952118Sjchu 1953118Sjchu /* If no PM info, return failure */ 1954118Sjchu if (!PCIE_PMINFO(px_p->px_dip) || 1955118Sjchu !(pwr_p = PCIE_NEXUS_PMINFO(px_p->px_dip))) 1956118Sjchu return (DDI_FAILURE); 1957118Sjchu 1958118Sjchu mutex_enter(&pwr_p->pwr_lock); 1959287Smg140465 /* 19601147Sjchu * The following link retrain activity will cause LDN and LUP event. 19611147Sjchu * Receiving LDN prior to receiving LUP is expected, not an error in 19621147Sjchu * this case. Receiving LUP indicates link is fully up to support 19631147Sjchu * powering up down stream device, and of course any further LDN and 19641147Sjchu * LUP outside this context will be error. 1965287Smg140465 */ 19661147Sjchu px_p->px_lup_pending = 1; 1967118Sjchu if (px_link_retrain(csr_base) != DDI_SUCCESS) { 1968118Sjchu ret = DDI_FAILURE; 1969118Sjchu goto l0_done; 1970118Sjchu } 1971118Sjchu 19721147Sjchu /* LUP event takes the order of 15ms amount of time to occur */ 19731147Sjchu for (; px_p->px_lup_pending && (time_spent < px_lup_poll_to); 19741147Sjchu time_spent += px_lup_poll_interval) 19751147Sjchu drv_usecwait(px_lup_poll_interval); 19761147Sjchu if (px_p->px_lup_pending) 19771147Sjchu ret = DDI_FAILURE; 1978118Sjchu l0_done: 1979287Smg140465 px_enable_detect_quiet(csr_base); 1980118Sjchu if (ret == DDI_SUCCESS) 1981287Smg140465 pwr_p->pwr_link_lvl = PM_LEVEL_L0; 1982118Sjchu mutex_exit(&pwr_p->pwr_lock); 1983118Sjchu return (ret); 1984118Sjchu } 1985118Sjchu 19860Sstevel@tonic-gate /* 19870Sstevel@tonic-gate * Extract the drivers binding name to identify which chip we're binding to. 19880Sstevel@tonic-gate * Whenever a new bus bridge is created, the driver alias entry should be 19890Sstevel@tonic-gate * added here to identify the device if needed. If a device isn't added, 19900Sstevel@tonic-gate * the identity defaults to PX_CHIP_UNIDENTIFIED. 19910Sstevel@tonic-gate */ 19920Sstevel@tonic-gate static uint32_t 19932426Sschwartz px_identity_init(px_t *px_p) 19940Sstevel@tonic-gate { 19950Sstevel@tonic-gate dev_info_t *dip = px_p->px_dip; 19960Sstevel@tonic-gate char *name = ddi_binding_name(dip); 19970Sstevel@tonic-gate uint32_t revision = 0; 19980Sstevel@tonic-gate 19990Sstevel@tonic-gate revision = ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 20000Sstevel@tonic-gate "module-revision#", 0); 20010Sstevel@tonic-gate 20020Sstevel@tonic-gate /* Check for Fire driver binding name */ 20032426Sschwartz if (strcmp(name, "pciex108e,80f0") == 0) { 20042426Sschwartz DBG(DBG_ATTACH, dip, "px_identity_init: %s%d: " 20052426Sschwartz "(FIRE), module-revision %d\n", NAMEINST(dip), 20062426Sschwartz revision); 20072426Sschwartz 20082426Sschwartz return ((revision >= FIRE_MOD_REV_20) ? 20092426Sschwartz PX_CHIP_FIRE : PX_CHIP_UNIDENTIFIED); 20100Sstevel@tonic-gate } 20110Sstevel@tonic-gate 20121772Sjl139090 /* Check for Oberon driver binding name */ 20131772Sjl139090 if (strcmp(name, "pciex108e,80f8") == 0) { 20142426Sschwartz DBG(DBG_ATTACH, dip, "px_identity_init: %s%d: " 20152426Sschwartz "(OBERON), module-revision %d\n", NAMEINST(dip), 20162426Sschwartz revision); 20172426Sschwartz 20182426Sschwartz return (PX_CHIP_OBERON); 20191772Sjl139090 } 20201772Sjl139090 20210Sstevel@tonic-gate DBG(DBG_ATTACH, dip, "%s%d: Unknown PCI Express Host bridge %s %x\n", 20220Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), name, revision); 20230Sstevel@tonic-gate 20240Sstevel@tonic-gate return (PX_CHIP_UNIDENTIFIED); 20250Sstevel@tonic-gate } 202627Sjchu 202727Sjchu int 202827Sjchu px_err_add_intr(px_fault_t *px_fault_p) 202927Sjchu { 203027Sjchu dev_info_t *dip = px_fault_p->px_fh_dip; 203127Sjchu px_t *px_p = DIP_TO_STATE(dip); 203227Sjchu 203327Sjchu VERIFY(add_ivintr(px_fault_p->px_fh_sysino, PX_ERR_PIL, 20342973Sgovinda (intrfunc)px_fault_p->px_err_func, (caddr_t)px_fault_p, 20352973Sgovinda NULL, NULL) == 0); 203627Sjchu 203727Sjchu px_ib_intr_enable(px_p, intr_dist_cpuid(), px_fault_p->px_intr_ino); 203827Sjchu 203927Sjchu return (DDI_SUCCESS); 204027Sjchu } 204127Sjchu 204227Sjchu void 204327Sjchu px_err_rem_intr(px_fault_t *px_fault_p) 204427Sjchu { 204527Sjchu dev_info_t *dip = px_fault_p->px_fh_dip; 204627Sjchu px_t *px_p = DIP_TO_STATE(dip); 204727Sjchu 204827Sjchu px_ib_intr_disable(px_p->px_ib_p, px_fault_p->px_intr_ino, 20496313Skrishnae IB_INTR_WAIT); 2050965Sgovinda 20512973Sgovinda VERIFY(rem_ivintr(px_fault_p->px_fh_sysino, PX_ERR_PIL) == 0); 205227Sjchu } 205327Sjchu 20541648Sjchu /* 20553623Sjchu * px_cb_intr_redist() - sun4u only, CB interrupt redistribution 20563623Sjchu */ 20573623Sjchu void 20583623Sjchu px_cb_intr_redist(void *arg) 20593623Sjchu { 20603623Sjchu px_cb_t *cb_p = (px_cb_t *)arg; 20613623Sjchu px_cb_list_t *pxl; 20623623Sjchu px_t *pxp = NULL; 20633623Sjchu px_fault_t *f_p = NULL; 20643623Sjchu uint32_t new_cpuid; 20653623Sjchu intr_valid_state_t enabled = 0; 20663623Sjchu 20673623Sjchu mutex_enter(&cb_p->cb_mutex); 20683623Sjchu 20693623Sjchu pxl = cb_p->pxl; 20703623Sjchu if (!pxl) 20713623Sjchu goto cb_done; 20723623Sjchu 20733623Sjchu pxp = pxl->pxp; 20743623Sjchu f_p = &pxp->px_cb_fault; 20753623Sjchu for (; pxl && (f_p->px_fh_sysino != cb_p->sysino); ) { 20763623Sjchu pxl = pxl->next; 20773623Sjchu pxp = pxl->pxp; 20783623Sjchu f_p = &pxp->px_cb_fault; 20793623Sjchu } 20803623Sjchu if (pxl == NULL) 20813623Sjchu goto cb_done; 20823623Sjchu 20833623Sjchu new_cpuid = intr_dist_cpuid(); 20843623Sjchu if (new_cpuid == cb_p->cpuid) 20853623Sjchu goto cb_done; 20863623Sjchu 20873623Sjchu if ((px_lib_intr_getvalid(pxp->px_dip, f_p->px_fh_sysino, &enabled) 20883623Sjchu != DDI_SUCCESS) || !enabled) { 20893623Sjchu DBG(DBG_IB, pxp->px_dip, "px_cb_intr_redist: CB not enabled, " 20903623Sjchu "sysino(0x%x)\n", f_p->px_fh_sysino); 20913623Sjchu goto cb_done; 20923623Sjchu } 20933623Sjchu 20943623Sjchu PX_INTR_DISABLE(pxp->px_dip, f_p->px_fh_sysino); 20953623Sjchu 20963623Sjchu cb_p->cpuid = new_cpuid; 20973623Sjchu cb_p->sysino = f_p->px_fh_sysino; 20983623Sjchu PX_INTR_ENABLE(pxp->px_dip, cb_p->sysino, cb_p->cpuid); 20993623Sjchu 21003623Sjchu cb_done: 21013623Sjchu mutex_exit(&cb_p->cb_mutex); 21023623Sjchu } 21033623Sjchu 21043623Sjchu /* 21051648Sjchu * px_cb_add_intr() - Called from attach(9E) to create CB if not yet 21061648Sjchu * created, to add CB interrupt vector always, but enable only once. 21071648Sjchu */ 21081648Sjchu int 21091648Sjchu px_cb_add_intr(px_fault_t *fault_p) 21101648Sjchu { 21111648Sjchu px_t *px_p = DIP_TO_STATE(fault_p->px_fh_dip); 21121648Sjchu pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 21131772Sjl139090 px_cb_t *cb_p = (px_cb_t *)px_get_cb(fault_p->px_fh_dip); 21141648Sjchu px_cb_list_t *pxl, *pxl_new; 21153623Sjchu boolean_t is_proxy = B_FALSE; 21163623Sjchu 21173623Sjchu /* create cb */ 21181648Sjchu if (cb_p == NULL) { 21191648Sjchu cb_p = kmem_zalloc(sizeof (px_cb_t), KM_SLEEP); 21203623Sjchu 21213623Sjchu mutex_init(&cb_p->cb_mutex, NULL, MUTEX_DRIVER, 21223623Sjchu (void *) ipltospl(FM_ERR_PIL)); 21233623Sjchu 21241648Sjchu cb_p->px_cb_func = px_cb_intr; 21251648Sjchu pxu_p->px_cb_p = cb_p; 21261772Sjl139090 px_set_cb(fault_p->px_fh_dip, (uint64_t)cb_p); 21272509Sschwartz 21282509Sschwartz /* px_lib_dev_init allows only FIRE and OBERON */ 21292509Sschwartz px_err_reg_enable( 21302509Sschwartz (pxu_p->chip_type == PX_CHIP_FIRE) ? 21316313Skrishnae PX_ERR_JBC : PX_ERR_UBC, 21322509Sschwartz pxu_p->px_address[PX_REG_XBC]); 21331648Sjchu } else 21341648Sjchu pxu_p->px_cb_p = cb_p; 21351648Sjchu 21363623Sjchu /* register cb interrupt */ 21371648Sjchu VERIFY(add_ivintr(fault_p->px_fh_sysino, PX_ERR_PIL, 21382973Sgovinda (intrfunc)cb_p->px_cb_func, (caddr_t)cb_p, NULL, NULL) == 0); 21391648Sjchu 21403623Sjchu 21413623Sjchu /* update cb list */ 21423623Sjchu mutex_enter(&cb_p->cb_mutex); 21431648Sjchu if (cb_p->pxl == NULL) { 21443623Sjchu is_proxy = B_TRUE; 21451648Sjchu pxl = kmem_zalloc(sizeof (px_cb_list_t), KM_SLEEP); 21461648Sjchu pxl->pxp = px_p; 21471648Sjchu cb_p->pxl = pxl; 21481648Sjchu cb_p->sysino = fault_p->px_fh_sysino; 21493623Sjchu cb_p->cpuid = intr_dist_cpuid(); 21501648Sjchu } else { 21511648Sjchu /* 21521648Sjchu * Find the last pxl or 21533623Sjchu * stop short at encountering a redundent entry, or 21541648Sjchu * both. 21551648Sjchu */ 21561648Sjchu pxl = cb_p->pxl; 21576313Skrishnae for (; !(pxl->pxp == px_p) && pxl->next; pxl = pxl->next) {}; 21583623Sjchu ASSERT(pxl->pxp != px_p); 21591648Sjchu 21601648Sjchu /* add to linked list */ 21611648Sjchu pxl_new = kmem_zalloc(sizeof (px_cb_list_t), KM_SLEEP); 21621648Sjchu pxl_new->pxp = px_p; 21631648Sjchu pxl->next = pxl_new; 21641648Sjchu } 21651648Sjchu cb_p->attachcnt++; 21661648Sjchu mutex_exit(&cb_p->cb_mutex); 21671648Sjchu 21683623Sjchu if (is_proxy) { 21693623Sjchu /* add to interrupt redistribution list */ 21703623Sjchu intr_dist_add(px_cb_intr_redist, cb_p); 21713623Sjchu 21723623Sjchu /* enable cb hw interrupt */ 21733623Sjchu px_ib_intr_enable(px_p, cb_p->cpuid, fault_p->px_intr_ino); 21743623Sjchu } 21753623Sjchu 21761648Sjchu return (DDI_SUCCESS); 21771648Sjchu } 21781648Sjchu 21791648Sjchu /* 21801648Sjchu * px_cb_rem_intr() - Called from detach(9E) to remove its CB 21811648Sjchu * interrupt vector, to shift proxy to the next available px, 21821648Sjchu * or disable CB interrupt when itself is the last. 21831648Sjchu */ 21841648Sjchu void 21851648Sjchu px_cb_rem_intr(px_fault_t *fault_p) 21861648Sjchu { 21871648Sjchu px_t *px_p = DIP_TO_STATE(fault_p->px_fh_dip), *pxp; 21881648Sjchu pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 21891648Sjchu px_cb_t *cb_p = PX2CB(px_p); 21901648Sjchu px_cb_list_t *pxl, *prev; 21911648Sjchu px_fault_t *f_p; 21921648Sjchu 21931648Sjchu ASSERT(cb_p->pxl); 21941648Sjchu 21953623Sjchu /* find and remove this px, and update cb list */ 21961648Sjchu mutex_enter(&cb_p->cb_mutex); 21971648Sjchu 21981648Sjchu pxl = cb_p->pxl; 21991648Sjchu if (pxl->pxp == px_p) { 22001648Sjchu cb_p->pxl = pxl->next; 22011648Sjchu } else { 22021648Sjchu prev = pxl; 22031648Sjchu pxl = pxl->next; 22046313Skrishnae for (; pxl && (pxl->pxp != px_p); prev = pxl, pxl = pxl->next) { 22056313Skrishnae }; 22061648Sjchu if (!pxl) { 22071648Sjchu cmn_err(CE_WARN, "px_cb_rem_intr: can't find px_p 0x%p " 22081650Sjchu "in registered CB list.", (void *)px_p); 22093623Sjchu mutex_exit(&cb_p->cb_mutex); 22101648Sjchu return; 22111648Sjchu } 22121648Sjchu prev->next = pxl->next; 22131648Sjchu } 22143623Sjchu pxu_p->px_cb_p = NULL; 22153623Sjchu cb_p->attachcnt--; 22161648Sjchu kmem_free(pxl, sizeof (px_cb_list_t)); 22173623Sjchu mutex_exit(&cb_p->cb_mutex); 22183623Sjchu 22193623Sjchu /* disable cb hw interrupt */ 22203623Sjchu if (fault_p->px_fh_sysino == cb_p->sysino) 22211648Sjchu px_ib_intr_disable(px_p->px_ib_p, fault_p->px_intr_ino, 22221648Sjchu IB_INTR_WAIT); 22231648Sjchu 22243623Sjchu /* if last px, remove from interrupt redistribution list */ 22253623Sjchu if (cb_p->pxl == NULL) 22263623Sjchu intr_dist_rem(px_cb_intr_redist, cb_p); 22273623Sjchu 22283623Sjchu /* de-register interrupt */ 22293623Sjchu VERIFY(rem_ivintr(fault_p->px_fh_sysino, PX_ERR_PIL) == 0); 22303623Sjchu 22313623Sjchu /* if not last px, assign next px to manage cb */ 22323623Sjchu mutex_enter(&cb_p->cb_mutex); 22333623Sjchu if (cb_p->pxl) { 22343623Sjchu if (fault_p->px_fh_sysino == cb_p->sysino) { 22351648Sjchu pxp = cb_p->pxl->pxp; 22361648Sjchu f_p = &pxp->px_cb_fault; 22371648Sjchu cb_p->sysino = f_p->px_fh_sysino; 22381648Sjchu 22391648Sjchu PX_INTR_ENABLE(pxp->px_dip, cb_p->sysino, cb_p->cpuid); 22401650Sjchu (void) px_lib_intr_setstate(pxp->px_dip, cb_p->sysino, 22411648Sjchu INTR_IDLE_STATE); 22421648Sjchu } 22431648Sjchu mutex_exit(&cb_p->cb_mutex); 22441648Sjchu return; 22451648Sjchu } 22463623Sjchu 22473623Sjchu /* clean up after the last px */ 22481648Sjchu mutex_exit(&cb_p->cb_mutex); 22491648Sjchu 22502509Sschwartz /* px_lib_dev_init allows only FIRE and OBERON */ 22512509Sschwartz px_err_reg_disable( 22522509Sschwartz (pxu_p->chip_type == PX_CHIP_FIRE) ? PX_ERR_JBC : PX_ERR_UBC, 22532509Sschwartz pxu_p->px_address[PX_REG_XBC]); 22542509Sschwartz 22551648Sjchu mutex_destroy(&cb_p->cb_mutex); 22561772Sjl139090 px_set_cb(fault_p->px_fh_dip, 0ull); 22571648Sjchu kmem_free(cb_p, sizeof (px_cb_t)); 22581648Sjchu } 22591648Sjchu 22601648Sjchu /* 22611648Sjchu * px_cb_intr() - sun4u only, CB interrupt dispatcher 22621648Sjchu */ 22631648Sjchu uint_t 22641648Sjchu px_cb_intr(caddr_t arg) 22651648Sjchu { 22661648Sjchu px_cb_t *cb_p = (px_cb_t *)arg; 22673623Sjchu px_t *pxp; 22683623Sjchu px_fault_t *f_p; 22693623Sjchu int ret; 22703354Sjl139090 22711648Sjchu mutex_enter(&cb_p->cb_mutex); 22721648Sjchu 22733623Sjchu if (!cb_p->pxl) { 22741648Sjchu mutex_exit(&cb_p->cb_mutex); 22753623Sjchu return (DDI_INTR_UNCLAIMED); 22761648Sjchu } 22771648Sjchu 22783623Sjchu pxp = cb_p->pxl->pxp; 22793623Sjchu f_p = &pxp->px_cb_fault; 22803623Sjchu 22813623Sjchu ret = f_p->px_err_func((caddr_t)f_p); 22821648Sjchu 22831648Sjchu mutex_exit(&cb_p->cb_mutex); 22843623Sjchu return (ret); 22851648Sjchu } 22861648Sjchu 22873623Sjchu #ifdef FMA 228827Sjchu void 228927Sjchu px_fill_rc_status(px_fault_t *px_fault_p, pciex_rc_error_regs_t *rc_status) 229027Sjchu { 229127Sjchu /* populate the rc_status by reading the registers - TBD */ 229227Sjchu } 229327Sjchu #endif /* FMA */ 2294383Set142600 2295383Set142600 /* 2296383Set142600 * Unprotected raw reads/writes of fabric device's config space. 2297383Set142600 * Only used for temporary PCI-E Fabric Error Handling. 2298383Set142600 */ 2299383Set142600 uint32_t 23001648Sjchu px_fab_get(px_t *px_p, pcie_req_id_t bdf, uint16_t offset) 23011648Sjchu { 2302383Set142600 px_ranges_t *rp = px_p->px_ranges_p; 2303383Set142600 uint64_t range_prop, base_addr; 2304383Set142600 int bank = PCI_REG_ADDR_G(PCI_ADDR_CONFIG); 2305383Set142600 uint32_t val; 2306383Set142600 2307383Set142600 /* Get Fire's Physical Base Address */ 23081772Sjl139090 range_prop = px_get_range_prop(px_p, rp, bank); 2309383Set142600 2310383Set142600 /* Get config space first. */ 2311383Set142600 base_addr = range_prop + PX_BDF_TO_CFGADDR(bdf, offset); 2312383Set142600 2313383Set142600 val = ldphysio(base_addr); 2314383Set142600 2315383Set142600 return (LE_32(val)); 2316383Set142600 } 2317383Set142600 2318383Set142600 void 2319383Set142600 px_fab_set(px_t *px_p, pcie_req_id_t bdf, uint16_t offset, 2320383Set142600 uint32_t val) { 2321383Set142600 px_ranges_t *rp = px_p->px_ranges_p; 2322383Set142600 uint64_t range_prop, base_addr; 2323383Set142600 int bank = PCI_REG_ADDR_G(PCI_ADDR_CONFIG); 2324383Set142600 2325383Set142600 /* Get Fire's Physical Base Address */ 23261772Sjl139090 range_prop = px_get_range_prop(px_p, rp, bank); 2327383Set142600 2328383Set142600 /* Get config space first. */ 2329383Set142600 base_addr = range_prop + PX_BDF_TO_CFGADDR(bdf, offset); 2330383Set142600 2331383Set142600 stphysio(base_addr, LE_32(val)); 2332383Set142600 } 2333435Sjchu 2334435Sjchu /* 2335435Sjchu * cpr callback 2336435Sjchu * 2337435Sjchu * disable fabric error msg interrupt prior to suspending 2338435Sjchu * all device drivers; re-enable fabric error msg interrupt 2339435Sjchu * after all devices are resumed. 2340435Sjchu */ 2341435Sjchu static boolean_t 2342435Sjchu px_cpr_callb(void *arg, int code) 2343435Sjchu { 2344435Sjchu px_t *px_p = (px_t *)arg; 2345435Sjchu px_ib_t *ib_p = px_p->px_ib_p; 2346435Sjchu px_pec_t *pec_p = px_p->px_pec_p; 2347435Sjchu pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 2348435Sjchu caddr_t csr_base; 2349435Sjchu devino_t ce_ino, nf_ino, f_ino; 23502973Sgovinda px_ino_t *ce_ino_p, *nf_ino_p, *f_ino_p; 2351435Sjchu uint64_t imu_log_enable, imu_intr_enable; 2352435Sjchu uint64_t imu_log_mask, imu_intr_mask; 2353435Sjchu 2354435Sjchu ce_ino = px_msiqid_to_devino(px_p, pec_p->pec_corr_msg_msiq_id); 2355435Sjchu nf_ino = px_msiqid_to_devino(px_p, pec_p->pec_non_fatal_msg_msiq_id); 2356435Sjchu f_ino = px_msiqid_to_devino(px_p, pec_p->pec_fatal_msg_msiq_id); 2357435Sjchu csr_base = (caddr_t)pxu_p->px_address[PX_REG_CSR]; 2358435Sjchu 2359435Sjchu imu_log_enable = CSR_XR(csr_base, IMU_ERROR_LOG_ENABLE); 2360435Sjchu imu_intr_enable = CSR_XR(csr_base, IMU_INTERRUPT_ENABLE); 2361435Sjchu 2362435Sjchu imu_log_mask = BITMASK(IMU_ERROR_LOG_ENABLE_FATAL_MES_NOT_EN_LOG_EN) | 2363435Sjchu BITMASK(IMU_ERROR_LOG_ENABLE_NONFATAL_MES_NOT_EN_LOG_EN) | 2364435Sjchu BITMASK(IMU_ERROR_LOG_ENABLE_COR_MES_NOT_EN_LOG_EN); 2365435Sjchu 2366435Sjchu imu_intr_mask = 2367435Sjchu BITMASK(IMU_INTERRUPT_ENABLE_FATAL_MES_NOT_EN_S_INT_EN) | 2368435Sjchu BITMASK(IMU_INTERRUPT_ENABLE_NONFATAL_MES_NOT_EN_S_INT_EN) | 2369435Sjchu BITMASK(IMU_INTERRUPT_ENABLE_COR_MES_NOT_EN_S_INT_EN) | 2370435Sjchu BITMASK(IMU_INTERRUPT_ENABLE_FATAL_MES_NOT_EN_P_INT_EN) | 2371435Sjchu BITMASK(IMU_INTERRUPT_ENABLE_NONFATAL_MES_NOT_EN_P_INT_EN) | 2372435Sjchu BITMASK(IMU_INTERRUPT_ENABLE_COR_MES_NOT_EN_P_INT_EN); 2373435Sjchu 2374435Sjchu switch (code) { 2375435Sjchu case CB_CODE_CPR_CHKPT: 2376435Sjchu /* disable imu rbne on corr/nonfatal/fatal errors */ 2377435Sjchu CSR_XS(csr_base, IMU_ERROR_LOG_ENABLE, 2378435Sjchu imu_log_enable & (~imu_log_mask)); 2379435Sjchu 2380435Sjchu CSR_XS(csr_base, IMU_INTERRUPT_ENABLE, 2381435Sjchu imu_intr_enable & (~imu_intr_mask)); 2382435Sjchu 2383435Sjchu /* disable CORR intr mapping */ 2384435Sjchu px_ib_intr_disable(ib_p, ce_ino, IB_INTR_NOWAIT); 2385435Sjchu 2386435Sjchu /* disable NON FATAL intr mapping */ 2387435Sjchu px_ib_intr_disable(ib_p, nf_ino, IB_INTR_NOWAIT); 2388435Sjchu 2389435Sjchu /* disable FATAL intr mapping */ 2390435Sjchu px_ib_intr_disable(ib_p, f_ino, IB_INTR_NOWAIT); 2391435Sjchu 2392435Sjchu break; 2393435Sjchu 2394435Sjchu case CB_CODE_CPR_RESUME: 23953274Set142600 pxu_p->cpr_flag = PX_NOT_CPR; 2396435Sjchu mutex_enter(&ib_p->ib_ino_lst_mutex); 2397435Sjchu 2398435Sjchu ce_ino_p = px_ib_locate_ino(ib_p, ce_ino); 2399435Sjchu nf_ino_p = px_ib_locate_ino(ib_p, nf_ino); 2400435Sjchu f_ino_p = px_ib_locate_ino(ib_p, f_ino); 2401435Sjchu 2402435Sjchu /* enable CORR intr mapping */ 2403435Sjchu if (ce_ino_p) 2404435Sjchu px_ib_intr_enable(px_p, ce_ino_p->ino_cpuid, ce_ino); 2405435Sjchu else 2406435Sjchu cmn_err(CE_WARN, "px_cpr_callb: RESUME unable to " 2407435Sjchu "reenable PCIe Correctable msg intr.\n"); 2408435Sjchu 2409435Sjchu /* enable NON FATAL intr mapping */ 2410435Sjchu if (nf_ino_p) 2411435Sjchu px_ib_intr_enable(px_p, nf_ino_p->ino_cpuid, nf_ino); 2412435Sjchu else 2413435Sjchu cmn_err(CE_WARN, "px_cpr_callb: RESUME unable to " 2414435Sjchu "reenable PCIe Non Fatal msg intr.\n"); 2415435Sjchu 2416435Sjchu /* enable FATAL intr mapping */ 2417435Sjchu if (f_ino_p) 2418435Sjchu px_ib_intr_enable(px_p, f_ino_p->ino_cpuid, f_ino); 2419435Sjchu else 2420435Sjchu cmn_err(CE_WARN, "px_cpr_callb: RESUME unable to " 2421435Sjchu "reenable PCIe Fatal msg intr.\n"); 2422435Sjchu 2423435Sjchu mutex_exit(&ib_p->ib_ino_lst_mutex); 2424435Sjchu 2425435Sjchu /* enable corr/nonfatal/fatal not enable error */ 2426435Sjchu CSR_XS(csr_base, IMU_ERROR_LOG_ENABLE, (imu_log_enable | 2427435Sjchu (imu_log_mask & px_imu_log_mask))); 2428435Sjchu CSR_XS(csr_base, IMU_INTERRUPT_ENABLE, (imu_intr_enable | 2429435Sjchu (imu_intr_mask & px_imu_intr_mask))); 2430435Sjchu 2431435Sjchu break; 2432435Sjchu } 2433435Sjchu 2434435Sjchu return (B_TRUE); 2435435Sjchu } 2436435Sjchu 24372053Sschwartz uint64_t 24382053Sschwartz px_get_rng_parent_hi_mask(px_t *px_p) 24392053Sschwartz { 24402053Sschwartz pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 24412053Sschwartz uint64_t mask; 24422053Sschwartz 24432053Sschwartz switch (PX_CHIP_TYPE(pxu_p)) { 24442053Sschwartz case PX_CHIP_OBERON: 24452053Sschwartz mask = OBERON_RANGE_PROP_MASK; 24462053Sschwartz break; 24472053Sschwartz case PX_CHIP_FIRE: 24482053Sschwartz mask = PX_RANGE_PROP_MASK; 24492053Sschwartz break; 24502053Sschwartz default: 24512053Sschwartz mask = PX_RANGE_PROP_MASK; 24522053Sschwartz } 24532053Sschwartz 24542053Sschwartz return (mask); 24552053Sschwartz } 24562053Sschwartz 2457435Sjchu /* 24581772Sjl139090 * fetch chip's range propery's value 24591772Sjl139090 */ 24601772Sjl139090 uint64_t 24611772Sjl139090 px_get_range_prop(px_t *px_p, px_ranges_t *rp, int bank) 24621772Sjl139090 { 24631772Sjl139090 uint64_t mask, range_prop; 24641772Sjl139090 24652053Sschwartz mask = px_get_rng_parent_hi_mask(px_p); 24661772Sjl139090 range_prop = (((uint64_t)(rp[bank].parent_high & mask)) << 32) | 24676313Skrishnae rp[bank].parent_low; 24681772Sjl139090 24691772Sjl139090 return (range_prop); 24701772Sjl139090 } 24711772Sjl139090 24721772Sjl139090 /* 2473435Sjchu * add cpr callback 2474435Sjchu */ 2475435Sjchu void 2476435Sjchu px_cpr_add_callb(px_t *px_p) 2477435Sjchu { 2478435Sjchu px_p->px_cprcb_id = callb_add(px_cpr_callb, (void *)px_p, 24796313Skrishnae CB_CL_CPR_POST_USER, "px_cpr"); 2480435Sjchu } 2481435Sjchu 2482435Sjchu /* 2483435Sjchu * remove cpr callback 2484435Sjchu */ 2485435Sjchu void 2486435Sjchu px_cpr_rem_callb(px_t *px_p) 2487435Sjchu { 2488435Sjchu (void) callb_delete(px_p->px_cprcb_id); 2489435Sjchu } 24901531Skini 24911531Skini /*ARGSUSED*/ 24921772Sjl139090 static uint_t 24931772Sjl139090 px_hp_intr(caddr_t arg1, caddr_t arg2) 24941772Sjl139090 { 24954701Sgovinda px_t *px_p = (px_t *)arg1; 24964701Sgovinda pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 24974701Sgovinda int rval; 24981772Sjl139090 24991772Sjl139090 rval = pciehpc_intr(px_p->px_dip); 25001772Sjl139090 25011772Sjl139090 #ifdef DEBUG 25021772Sjl139090 if (rval == DDI_INTR_UNCLAIMED) 25036313Skrishnae cmn_err(CE_WARN, "%s%d: UNCLAIMED intr\n", 25046313Skrishnae ddi_driver_name(px_p->px_dip), 25056313Skrishnae ddi_get_instance(px_p->px_dip)); 25061772Sjl139090 #endif 25071772Sjl139090 25084701Sgovinda /* Set the interrupt state to idle */ 25094701Sgovinda if (px_lib_intr_setstate(px_p->px_dip, 25104701Sgovinda pxu_p->hp_sysino, INTR_IDLE_STATE) != DDI_SUCCESS) 25114701Sgovinda return (DDI_INTR_UNCLAIMED); 25124701Sgovinda 25131772Sjl139090 return (rval); 25141772Sjl139090 } 25151772Sjl139090 25161531Skini int 25171531Skini px_lib_hotplug_init(dev_info_t *dip, void *arg) 25181531Skini { 25191772Sjl139090 px_t *px_p = DIP_TO_STATE(dip); 25204701Sgovinda pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 25211772Sjl139090 uint64_t ret; 25221772Sjl139090 25231772Sjl139090 if ((ret = hvio_hotplug_init(dip, arg)) == DDI_SUCCESS) { 25241772Sjl139090 if (px_lib_intr_devino_to_sysino(px_p->px_dip, 25254701Sgovinda px_p->px_inos[PX_INTR_HOTPLUG], &pxu_p->hp_sysino) != 25261772Sjl139090 DDI_SUCCESS) { 25271772Sjl139090 #ifdef DEBUG 25281772Sjl139090 cmn_err(CE_WARN, "%s%d: devino_to_sysino fails\n", 25291772Sjl139090 ddi_driver_name(px_p->px_dip), 25301772Sjl139090 ddi_get_instance(px_p->px_dip)); 25311772Sjl139090 #endif 25321772Sjl139090 return (DDI_FAILURE); 25331772Sjl139090 } 25341772Sjl139090 25354701Sgovinda VERIFY(add_ivintr(pxu_p->hp_sysino, PX_PCIEHP_PIL, 25362973Sgovinda (intrfunc)px_hp_intr, (caddr_t)px_p, NULL, NULL) == 0); 25373953Sscarter 25383953Sscarter px_ib_intr_enable(px_p, intr_dist_cpuid(), 25393953Sscarter px_p->px_inos[PX_INTR_HOTPLUG]); 25401772Sjl139090 } 25411772Sjl139090 25421772Sjl139090 return (ret); 25431531Skini } 25441531Skini 25451531Skini void 25461531Skini px_lib_hotplug_uninit(dev_info_t *dip) 25471531Skini { 25481772Sjl139090 if (hvio_hotplug_uninit(dip) == DDI_SUCCESS) { 25491772Sjl139090 px_t *px_p = DIP_TO_STATE(dip); 25504701Sgovinda pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 25511772Sjl139090 25523953Sscarter px_ib_intr_disable(px_p->px_ib_p, 25533953Sscarter px_p->px_inos[PX_INTR_HOTPLUG], IB_INTR_WAIT); 25543953Sscarter 25554701Sgovinda VERIFY(rem_ivintr(pxu_p->hp_sysino, PX_PCIEHP_PIL) == 0); 25561772Sjl139090 } 25571531Skini } 25582476Sdwoods 25593953Sscarter /* 25603953Sscarter * px_hp_intr_redist() - sun4u only, HP interrupt redistribution 25613953Sscarter */ 25623953Sscarter void 25633953Sscarter px_hp_intr_redist(px_t *px_p) 25643953Sscarter { 25653953Sscarter if (px_p && (px_p->px_dev_caps & PX_HOTPLUG_CAPABLE)) { 25663953Sscarter px_ib_intr_dist_en(px_p->px_dip, intr_dist_cpuid(), 25673953Sscarter px_p->px_inos[PX_INTR_HOTPLUG], B_FALSE); 25683953Sscarter } 25693953Sscarter } 25703953Sscarter 25712476Sdwoods boolean_t 25722476Sdwoods px_lib_is_in_drain_state(px_t *px_p) 25732476Sdwoods { 25742476Sdwoods pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 25752476Sdwoods caddr_t csr_base = (caddr_t)pxu_p->px_address[PX_REG_CSR]; 25762476Sdwoods uint64_t drain_status; 25772476Sdwoods 25782476Sdwoods if (PX_CHIP_TYPE(pxu_p) == PX_CHIP_OBERON) { 25792476Sdwoods drain_status = CSR_BR(csr_base, DRAIN_CONTROL_STATUS, DRAIN); 25802476Sdwoods } else { 25812476Sdwoods drain_status = CSR_BR(csr_base, TLU_STATUS, DRAIN); 25822476Sdwoods } 25832476Sdwoods 25842476Sdwoods return (drain_status); 25852476Sdwoods } 25863613Set142600 25873613Set142600 pcie_req_id_t 25883613Set142600 px_lib_get_bdf(px_t *px_p) 25893613Set142600 { 25903613Set142600 pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p; 25913613Set142600 caddr_t csr_base = (caddr_t)pxu_p->px_address[PX_REG_CSR]; 25923613Set142600 pcie_req_id_t bdf; 25933613Set142600 25943613Set142600 bdf = CSR_BR(csr_base, DMC_PCI_EXPRESS_CONFIGURATION, REQ_ID); 25953613Set142600 25963613Set142600 return (bdf); 25973613Set142600 } 2598