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 /*
22*12619Sandrew.rutz@sun.com * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate */
240Sstevel@tonic-gate
250Sstevel@tonic-gate #include <sys/types.h>
260Sstevel@tonic-gate #include <sys/kmem.h>
270Sstevel@tonic-gate #include <sys/conf.h>
280Sstevel@tonic-gate #include <sys/ddi.h>
290Sstevel@tonic-gate #include <sys/sunddi.h>
306313Skrishnae #include <sys/sunndi.h>
3127Sjchu #include <sys/fm/protocol.h>
3227Sjchu #include <sys/fm/util.h>
330Sstevel@tonic-gate #include <sys/modctl.h>
340Sstevel@tonic-gate #include <sys/disp.h>
350Sstevel@tonic-gate #include <sys/stat.h>
360Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
370Sstevel@tonic-gate #include <sys/vmem.h>
380Sstevel@tonic-gate #include <sys/iommutsb.h>
390Sstevel@tonic-gate #include <sys/cpuvar.h>
4027Sjchu #include <sys/ivintr.h>
41383Set142600 #include <sys/byteorder.h>
423623Sjchu #include <sys/spl.h>
430Sstevel@tonic-gate #include <px_obj.h>
4410187SKrishna.Elango@Sun.COM #include <sys/pcie_pwr.h>
451772Sjl139090 #include "px_tools_var.h"
460Sstevel@tonic-gate #include <px_regs.h>
470Sstevel@tonic-gate #include <px_csr.h>
4827Sjchu #include <sys/machsystm.h>
490Sstevel@tonic-gate #include "px_lib4u.h"
5027Sjchu #include "px_err.h"
511772Sjl139090 #include "oberon_regs.h"
5210923SEvan.Yan@Sun.COM #include <sys/hotplug/pci/pcie_hp.h>
530Sstevel@tonic-gate
540Sstevel@tonic-gate #pragma weak jbus_stst_order
550Sstevel@tonic-gate
560Sstevel@tonic-gate extern void jbus_stst_order();
570Sstevel@tonic-gate
580Sstevel@tonic-gate ulong_t px_mmu_dvma_end = 0xfffffffful;
590Sstevel@tonic-gate uint_t px_ranges_phi_mask = 0xfffffffful;
601772Sjl139090 uint64_t *px_oberon_ubc_scratch_regs;
612276Sschwartz uint64_t px_paddr_mask;
620Sstevel@tonic-gate
630Sstevel@tonic-gate static int px_goto_l23ready(px_t *px_p);
64118Sjchu static int px_goto_l0(px_t *px_p);
65118Sjchu static int px_pre_pwron_check(px_t *px_p);
662426Sschwartz static uint32_t px_identity_init(px_t *px_p);
67435Sjchu static boolean_t px_cpr_callb(void *arg, int code);
681648Sjchu static uint_t px_cb_intr(caddr_t arg);
6927Sjchu
7027Sjchu /*
717596SAlan.Adamson@Sun.COM * ACKNAK Latency Threshold Table.
727596SAlan.Adamson@Sun.COM * See Fire PRM 2.0 section 1.2.12.2, table 1-17.
737596SAlan.Adamson@Sun.COM */
747596SAlan.Adamson@Sun.COM int px_acknak_timer_table[LINK_MAX_PKT_ARR_SIZE][LINK_WIDTH_ARR_SIZE] = {
757596SAlan.Adamson@Sun.COM {0xED, 0x49, 0x43, 0x30},
767596SAlan.Adamson@Sun.COM {0x1A0, 0x76, 0x6B, 0x48},
777596SAlan.Adamson@Sun.COM {0x22F, 0x9A, 0x56, 0x56},
787596SAlan.Adamson@Sun.COM {0x42F, 0x11A, 0x96, 0x96},
797596SAlan.Adamson@Sun.COM {0x82F, 0x21A, 0x116, 0x116},
807596SAlan.Adamson@Sun.COM {0x102F, 0x41A, 0x216, 0x216}
817596SAlan.Adamson@Sun.COM };
827596SAlan.Adamson@Sun.COM
837596SAlan.Adamson@Sun.COM /*
847596SAlan.Adamson@Sun.COM * TxLink Replay Timer Latency Table
857596SAlan.Adamson@Sun.COM * See Fire PRM 2.0 sections 1.2.12.3, table 1-18.
867596SAlan.Adamson@Sun.COM */
877596SAlan.Adamson@Sun.COM int px_replay_timer_table[LINK_MAX_PKT_ARR_SIZE][LINK_WIDTH_ARR_SIZE] = {
887596SAlan.Adamson@Sun.COM {0x379, 0x112, 0xFC, 0xB4},
897596SAlan.Adamson@Sun.COM {0x618, 0x1BA, 0x192, 0x10E},
907596SAlan.Adamson@Sun.COM {0x831, 0x242, 0x143, 0x143},
917596SAlan.Adamson@Sun.COM {0xFB1, 0x422, 0x233, 0x233},
927596SAlan.Adamson@Sun.COM {0x1EB0, 0x7E1, 0x412, 0x412},
937596SAlan.Adamson@Sun.COM {0x3CB0, 0xF61, 0x7D2, 0x7D2}
947596SAlan.Adamson@Sun.COM };
957596SAlan.Adamson@Sun.COM /*
9627Sjchu * px_lib_map_registers
9727Sjchu *
9827Sjchu * This function is called from the attach routine to map the registers
9927Sjchu * accessed by this driver.
10027Sjchu *
10127Sjchu * used by: px_attach()
10227Sjchu *
10327Sjchu * return value: DDI_FAILURE on failure
10427Sjchu */
10527Sjchu int
px_lib_map_regs(pxu_t * pxu_p,dev_info_t * dip)10627Sjchu px_lib_map_regs(pxu_t *pxu_p, dev_info_t *dip)
10727Sjchu {
10827Sjchu ddi_device_acc_attr_t attr;
10927Sjchu px_reg_bank_t reg_bank = PX_REG_CSR;
11027Sjchu
11127Sjchu DBG(DBG_ATTACH, dip, "px_lib_map_regs: pxu_p:0x%p, dip 0x%p\n",
1126313Skrishnae pxu_p, dip);
11327Sjchu
11427Sjchu attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
11527Sjchu attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
11627Sjchu attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC;
11727Sjchu
11827Sjchu /*
11927Sjchu * PCI CSR Base
12027Sjchu */
12127Sjchu if (ddi_regs_map_setup(dip, reg_bank, &pxu_p->px_address[reg_bank],
12227Sjchu 0, 0, &attr, &pxu_p->px_ac[reg_bank]) != DDI_SUCCESS) {
12327Sjchu goto fail;
12427Sjchu }
12527Sjchu
12627Sjchu reg_bank++;
12727Sjchu
12827Sjchu /*
12927Sjchu * XBUS CSR Base
13027Sjchu */
13127Sjchu if (ddi_regs_map_setup(dip, reg_bank, &pxu_p->px_address[reg_bank],
13227Sjchu 0, 0, &attr, &pxu_p->px_ac[reg_bank]) != DDI_SUCCESS) {
13327Sjchu goto fail;
13427Sjchu }
13527Sjchu
13627Sjchu pxu_p->px_address[reg_bank] -= FIRE_CONTROL_STATUS;
13727Sjchu
13827Sjchu done:
13927Sjchu for (; reg_bank >= PX_REG_CSR; reg_bank--) {
14027Sjchu DBG(DBG_ATTACH, dip, "reg_bank 0x%x address 0x%p\n",
14127Sjchu reg_bank, pxu_p->px_address[reg_bank]);
14227Sjchu }
14327Sjchu
14427Sjchu return (DDI_SUCCESS);
14527Sjchu
14627Sjchu fail:
14727Sjchu cmn_err(CE_WARN, "%s%d: unable to map reg entry %d\n",
14827Sjchu ddi_driver_name(dip), ddi_get_instance(dip), reg_bank);
14927Sjchu
15027Sjchu for (reg_bank--; reg_bank >= PX_REG_CSR; reg_bank--) {
15127Sjchu pxu_p->px_address[reg_bank] = NULL;
15227Sjchu ddi_regs_map_free(&pxu_p->px_ac[reg_bank]);
15327Sjchu }
15427Sjchu
15527Sjchu return (DDI_FAILURE);
15627Sjchu }
15727Sjchu
15827Sjchu /*
15927Sjchu * px_lib_unmap_regs:
16027Sjchu *
16127Sjchu * This routine unmaps the registers mapped by map_px_registers.
16227Sjchu *
16327Sjchu * used by: px_detach(), and error conditions in px_attach()
16427Sjchu *
16527Sjchu * return value: none
16627Sjchu */
16727Sjchu void
px_lib_unmap_regs(pxu_t * pxu_p)16827Sjchu px_lib_unmap_regs(pxu_t *pxu_p)
16927Sjchu {
17027Sjchu int i;
17127Sjchu
17227Sjchu for (i = 0; i < PX_REG_MAX; i++) {
17327Sjchu if (pxu_p->px_ac[i])
17427Sjchu ddi_regs_map_free(&pxu_p->px_ac[i]);
17527Sjchu }
17627Sjchu }
1770Sstevel@tonic-gate
1780Sstevel@tonic-gate int
px_lib_dev_init(dev_info_t * dip,devhandle_t * dev_hdl)1790Sstevel@tonic-gate px_lib_dev_init(dev_info_t *dip, devhandle_t *dev_hdl)
1800Sstevel@tonic-gate {
1812509Sschwartz
1822509Sschwartz caddr_t xbc_csr_base, csr_base;
1830Sstevel@tonic-gate px_dvma_range_prop_t px_dvma_range;
1842509Sschwartz pxu_t *pxu_p;
1852509Sschwartz uint8_t chip_mask;
1862509Sschwartz px_t *px_p = DIP_TO_STATE(dip);
1872509Sschwartz px_chip_type_t chip_type = px_identity_init(px_p);
1880Sstevel@tonic-gate
1892426Sschwartz DBG(DBG_ATTACH, dip, "px_lib_dev_init: dip 0x%p", dip);
1902426Sschwartz
1912426Sschwartz if (chip_type == PX_CHIP_UNIDENTIFIED) {
1922426Sschwartz cmn_err(CE_WARN, "%s%d: Unrecognized Hardware Version\n",
1932426Sschwartz NAMEINST(dip));
1940Sstevel@tonic-gate return (DDI_FAILURE);
1950Sstevel@tonic-gate }
1960Sstevel@tonic-gate
1972509Sschwartz chip_mask = BITMASK(chip_type);
1982426Sschwartz px_paddr_mask = (chip_type == PX_CHIP_FIRE) ? MMU_FIRE_PADDR_MASK :
1992426Sschwartz MMU_OBERON_PADDR_MASK;
2002426Sschwartz
2010Sstevel@tonic-gate /*
2020Sstevel@tonic-gate * Allocate platform specific structure and link it to
2030Sstevel@tonic-gate * the px state structure.
2040Sstevel@tonic-gate */
2050Sstevel@tonic-gate pxu_p = kmem_zalloc(sizeof (pxu_t), KM_SLEEP);
2062426Sschwartz pxu_p->chip_type = chip_type;
2070Sstevel@tonic-gate pxu_p->portid = ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
2080Sstevel@tonic-gate "portid", -1);
2090Sstevel@tonic-gate
21027Sjchu /* Map in the registers */
21127Sjchu if (px_lib_map_regs(pxu_p, dip) == DDI_FAILURE) {
21227Sjchu kmem_free(pxu_p, sizeof (pxu_t));
21327Sjchu
21427Sjchu return (DDI_FAILURE);
21527Sjchu }
21627Sjchu
21727Sjchu xbc_csr_base = (caddr_t)pxu_p->px_address[PX_REG_XBC];
21827Sjchu csr_base = (caddr_t)pxu_p->px_address[PX_REG_CSR];
21927Sjchu
2200Sstevel@tonic-gate pxu_p->tsb_cookie = iommu_tsb_alloc(pxu_p->portid);
2210Sstevel@tonic-gate pxu_p->tsb_size = iommu_tsb_cookie_to_size(pxu_p->tsb_cookie);
2220Sstevel@tonic-gate pxu_p->tsb_vaddr = iommu_tsb_cookie_to_va(pxu_p->tsb_cookie);
2230Sstevel@tonic-gate
2241772Sjl139090 pxu_p->tsb_paddr = va_to_pa(pxu_p->tsb_vaddr);
2251772Sjl139090
2260Sstevel@tonic-gate /*
2270Sstevel@tonic-gate * Create "virtual-dma" property to support child devices
2280Sstevel@tonic-gate * needing to know DVMA range.
2290Sstevel@tonic-gate */
2300Sstevel@tonic-gate px_dvma_range.dvma_base = (uint32_t)px_mmu_dvma_end + 1
2310Sstevel@tonic-gate - ((pxu_p->tsb_size >> 3) << MMU_PAGE_SHIFT);
2320Sstevel@tonic-gate px_dvma_range.dvma_len = (uint32_t)
2330Sstevel@tonic-gate px_mmu_dvma_end - px_dvma_range.dvma_base + 1;
2340Sstevel@tonic-gate
2355328Sdanice (void) ddi_prop_update_int_array(DDI_DEV_T_NONE, dip,
2365328Sdanice "virtual-dma", (int *)&px_dvma_range,
2375328Sdanice sizeof (px_dvma_range_prop_t) / sizeof (int));
2380Sstevel@tonic-gate /*
2390Sstevel@tonic-gate * Initilize all fire hardware specific blocks.
2400Sstevel@tonic-gate */
2410Sstevel@tonic-gate hvio_cb_init(xbc_csr_base, pxu_p);
2420Sstevel@tonic-gate hvio_ib_init(csr_base, pxu_p);
2430Sstevel@tonic-gate hvio_pec_init(csr_base, pxu_p);
2440Sstevel@tonic-gate hvio_mmu_init(csr_base, pxu_p);
2450Sstevel@tonic-gate
2460Sstevel@tonic-gate px_p->px_plat_p = (void *)pxu_p;
2470Sstevel@tonic-gate
24827Sjchu /*
24927Sjchu * Initialize all the interrupt handlers
25027Sjchu */
2511772Sjl139090 switch (PX_CHIP_TYPE(pxu_p)) {
2521772Sjl139090 case PX_CHIP_OBERON:
2532044Sjj156685 /*
2542044Sjj156685 * Oberon hotplug uses SPARE3 field in ILU Error Log Enable
2552044Sjj156685 * register to indicate the status of leaf reset,
2562044Sjj156685 * we need to preserve the value of this bit, and keep it in
2572044Sjj156685 * px_ilu_log_mask to reflect the state of the bit
2582044Sjj156685 */
2592044Sjj156685 if (CSR_BR(csr_base, ILU_ERROR_LOG_ENABLE, SPARE3))
2602044Sjj156685 px_ilu_log_mask |= (1ull <<
2612044Sjj156685 ILU_ERROR_LOG_ENABLE_SPARE3);
2622044Sjj156685 else
2632044Sjj156685 px_ilu_log_mask &= ~(1ull <<
2642044Sjj156685 ILU_ERROR_LOG_ENABLE_SPARE3);
2652509Sschwartz
2662509Sschwartz px_err_reg_setup_pcie(chip_mask, csr_base, PX_ERR_ENABLE);
2671772Sjl139090 break;
2681772Sjl139090
2691772Sjl139090 case PX_CHIP_FIRE:
2702509Sschwartz px_err_reg_setup_pcie(chip_mask, csr_base, PX_ERR_ENABLE);
2711772Sjl139090 break;
2722509Sschwartz
2731772Sjl139090 default:
2741772Sjl139090 cmn_err(CE_WARN, "%s%d: PX primary bus Unknown\n",
2751772Sjl139090 ddi_driver_name(dip), ddi_get_instance(dip));
2761772Sjl139090 return (DDI_FAILURE);
2771772Sjl139090 }
27827Sjchu
2790Sstevel@tonic-gate /* Initilize device handle */
2800Sstevel@tonic-gate *dev_hdl = (devhandle_t)csr_base;
2810Sstevel@tonic-gate
2820Sstevel@tonic-gate DBG(DBG_ATTACH, dip, "px_lib_dev_init: dev_hdl 0x%llx\n", *dev_hdl);
2830Sstevel@tonic-gate
28411596SJason.Beloro@Sun.COM /* Sun4u always support fixed interrupt */
28511596SJason.Beloro@Sun.COM px_p->px_supp_intr_types |= DDI_INTR_TYPE_FIXED;
28611596SJason.Beloro@Sun.COM
2870Sstevel@tonic-gate return (DDI_SUCCESS);
2880Sstevel@tonic-gate }
2890Sstevel@tonic-gate
2900Sstevel@tonic-gate int
px_lib_dev_fini(dev_info_t * dip)2910Sstevel@tonic-gate px_lib_dev_fini(dev_info_t *dip)
2920Sstevel@tonic-gate {
2932509Sschwartz caddr_t csr_base;
2942509Sschwartz uint8_t chip_mask;
2952509Sschwartz px_t *px_p = DIP_TO_STATE(dip);
2962509Sschwartz pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
2970Sstevel@tonic-gate
2980Sstevel@tonic-gate DBG(DBG_DETACH, dip, "px_lib_dev_fini: dip 0x%p\n", dip);
2990Sstevel@tonic-gate
30027Sjchu /*
30127Sjchu * Deinitialize all the interrupt handlers
30227Sjchu */
3031772Sjl139090 switch (PX_CHIP_TYPE(pxu_p)) {
3041772Sjl139090 case PX_CHIP_OBERON:
3052509Sschwartz case PX_CHIP_FIRE:
3062509Sschwartz chip_mask = BITMASK(PX_CHIP_TYPE(pxu_p));
3072509Sschwartz csr_base = (caddr_t)pxu_p->px_address[PX_REG_CSR];
3082509Sschwartz px_err_reg_setup_pcie(chip_mask, csr_base, PX_ERR_DISABLE);
3091772Sjl139090 break;
3102509Sschwartz
3111772Sjl139090 default:
3121772Sjl139090 cmn_err(CE_WARN, "%s%d: PX primary bus Unknown\n",
3131772Sjl139090 ddi_driver_name(dip), ddi_get_instance(dip));
3141772Sjl139090 return (DDI_FAILURE);
3151772Sjl139090 }
31627Sjchu
3170Sstevel@tonic-gate iommu_tsb_free(pxu_p->tsb_cookie);
3180Sstevel@tonic-gate
31927Sjchu px_lib_unmap_regs((pxu_t *)px_p->px_plat_p);
32027Sjchu kmem_free(px_p->px_plat_p, sizeof (pxu_t));
3210Sstevel@tonic-gate px_p->px_plat_p = NULL;
3225328Sdanice (void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "virtual-dma");
3230Sstevel@tonic-gate
3240Sstevel@tonic-gate return (DDI_SUCCESS);
3250Sstevel@tonic-gate }
3260Sstevel@tonic-gate
3270Sstevel@tonic-gate /*ARGSUSED*/
3280Sstevel@tonic-gate int
px_lib_intr_devino_to_sysino(dev_info_t * dip,devino_t devino,sysino_t * sysino)3290Sstevel@tonic-gate px_lib_intr_devino_to_sysino(dev_info_t *dip, devino_t devino,
3300Sstevel@tonic-gate sysino_t *sysino)
3310Sstevel@tonic-gate {
3320Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
3330Sstevel@tonic-gate pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
3340Sstevel@tonic-gate uint64_t ret;
3350Sstevel@tonic-gate
3360Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_devino_to_sysino: dip 0x%p "
3370Sstevel@tonic-gate "devino 0x%x\n", dip, devino);
3380Sstevel@tonic-gate
3390Sstevel@tonic-gate if ((ret = hvio_intr_devino_to_sysino(DIP_TO_HANDLE(dip),
3400Sstevel@tonic-gate pxu_p, devino, sysino)) != H_EOK) {
3410Sstevel@tonic-gate DBG(DBG_LIB_INT, dip,
3420Sstevel@tonic-gate "hvio_intr_devino_to_sysino failed, ret 0x%lx\n", ret);
3430Sstevel@tonic-gate return (DDI_FAILURE);
3440Sstevel@tonic-gate }
3450Sstevel@tonic-gate
3460Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_devino_to_sysino: sysino 0x%llx\n",
3470Sstevel@tonic-gate *sysino);
3480Sstevel@tonic-gate
3490Sstevel@tonic-gate return (DDI_SUCCESS);
3500Sstevel@tonic-gate }
3510Sstevel@tonic-gate
3520Sstevel@tonic-gate /*ARGSUSED*/
3530Sstevel@tonic-gate int
px_lib_intr_getvalid(dev_info_t * dip,sysino_t sysino,intr_valid_state_t * intr_valid_state)3540Sstevel@tonic-gate px_lib_intr_getvalid(dev_info_t *dip, sysino_t sysino,
3550Sstevel@tonic-gate intr_valid_state_t *intr_valid_state)
3560Sstevel@tonic-gate {
3570Sstevel@tonic-gate uint64_t ret;
3580Sstevel@tonic-gate
3590Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_getvalid: dip 0x%p sysino 0x%llx\n",
3600Sstevel@tonic-gate dip, sysino);
3610Sstevel@tonic-gate
3620Sstevel@tonic-gate if ((ret = hvio_intr_getvalid(DIP_TO_HANDLE(dip),
3630Sstevel@tonic-gate sysino, intr_valid_state)) != H_EOK) {
3640Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "hvio_intr_getvalid failed, ret 0x%lx\n",
3650Sstevel@tonic-gate ret);
3660Sstevel@tonic-gate return (DDI_FAILURE);
3670Sstevel@tonic-gate }
3680Sstevel@tonic-gate
3690Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_getvalid: intr_valid_state 0x%x\n",
3700Sstevel@tonic-gate *intr_valid_state);
3710Sstevel@tonic-gate
3720Sstevel@tonic-gate return (DDI_SUCCESS);
3730Sstevel@tonic-gate }
3740Sstevel@tonic-gate
3750Sstevel@tonic-gate /*ARGSUSED*/
3760Sstevel@tonic-gate int
px_lib_intr_setvalid(dev_info_t * dip,sysino_t sysino,intr_valid_state_t intr_valid_state)3770Sstevel@tonic-gate px_lib_intr_setvalid(dev_info_t *dip, sysino_t sysino,
3780Sstevel@tonic-gate intr_valid_state_t intr_valid_state)
3790Sstevel@tonic-gate {
3800Sstevel@tonic-gate uint64_t ret;
3810Sstevel@tonic-gate
3820Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_setvalid: dip 0x%p sysino 0x%llx "
3830Sstevel@tonic-gate "intr_valid_state 0x%x\n", dip, sysino, intr_valid_state);
3840Sstevel@tonic-gate
3850Sstevel@tonic-gate if ((ret = hvio_intr_setvalid(DIP_TO_HANDLE(dip),
3860Sstevel@tonic-gate sysino, intr_valid_state)) != H_EOK) {
3870Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "hvio_intr_setvalid failed, ret 0x%lx\n",
3880Sstevel@tonic-gate ret);
3890Sstevel@tonic-gate return (DDI_FAILURE);
3900Sstevel@tonic-gate }
3910Sstevel@tonic-gate
3920Sstevel@tonic-gate return (DDI_SUCCESS);
3930Sstevel@tonic-gate }
3940Sstevel@tonic-gate
3950Sstevel@tonic-gate /*ARGSUSED*/
3960Sstevel@tonic-gate int
px_lib_intr_getstate(dev_info_t * dip,sysino_t sysino,intr_state_t * intr_state)3970Sstevel@tonic-gate px_lib_intr_getstate(dev_info_t *dip, sysino_t sysino,
3980Sstevel@tonic-gate intr_state_t *intr_state)
3990Sstevel@tonic-gate {
4000Sstevel@tonic-gate uint64_t ret;
4010Sstevel@tonic-gate
4020Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_getstate: dip 0x%p sysino 0x%llx\n",
4030Sstevel@tonic-gate dip, sysino);
4040Sstevel@tonic-gate
4050Sstevel@tonic-gate if ((ret = hvio_intr_getstate(DIP_TO_HANDLE(dip),
4060Sstevel@tonic-gate sysino, intr_state)) != H_EOK) {
4070Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "hvio_intr_getstate failed, ret 0x%lx\n",
4080Sstevel@tonic-gate ret);
4090Sstevel@tonic-gate return (DDI_FAILURE);
4100Sstevel@tonic-gate }
4110Sstevel@tonic-gate
4120Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_getstate: intr_state 0x%x\n",
4130Sstevel@tonic-gate *intr_state);
4140Sstevel@tonic-gate
4150Sstevel@tonic-gate return (DDI_SUCCESS);
4160Sstevel@tonic-gate }
4170Sstevel@tonic-gate
4180Sstevel@tonic-gate /*ARGSUSED*/
4190Sstevel@tonic-gate int
px_lib_intr_setstate(dev_info_t * dip,sysino_t sysino,intr_state_t intr_state)4200Sstevel@tonic-gate px_lib_intr_setstate(dev_info_t *dip, sysino_t sysino,
4210Sstevel@tonic-gate intr_state_t intr_state)
4220Sstevel@tonic-gate {
4230Sstevel@tonic-gate uint64_t ret;
4240Sstevel@tonic-gate
4250Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_setstate: dip 0x%p sysino 0x%llx "
4260Sstevel@tonic-gate "intr_state 0x%x\n", dip, sysino, intr_state);
4270Sstevel@tonic-gate
4280Sstevel@tonic-gate if ((ret = hvio_intr_setstate(DIP_TO_HANDLE(dip),
4290Sstevel@tonic-gate sysino, intr_state)) != H_EOK) {
4300Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "hvio_intr_setstate failed, ret 0x%lx\n",
4310Sstevel@tonic-gate ret);
4320Sstevel@tonic-gate return (DDI_FAILURE);
4330Sstevel@tonic-gate }
4340Sstevel@tonic-gate
4350Sstevel@tonic-gate return (DDI_SUCCESS);
4360Sstevel@tonic-gate }
4370Sstevel@tonic-gate
4380Sstevel@tonic-gate /*ARGSUSED*/
4390Sstevel@tonic-gate int
px_lib_intr_gettarget(dev_info_t * dip,sysino_t sysino,cpuid_t * cpuid)4400Sstevel@tonic-gate px_lib_intr_gettarget(dev_info_t *dip, sysino_t sysino, cpuid_t *cpuid)
4410Sstevel@tonic-gate {
4421772Sjl139090 px_t *px_p = DIP_TO_STATE(dip);
4431772Sjl139090 pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
4440Sstevel@tonic-gate uint64_t ret;
4450Sstevel@tonic-gate
4460Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_gettarget: dip 0x%p sysino 0x%llx\n",
4470Sstevel@tonic-gate dip, sysino);
4480Sstevel@tonic-gate
4491772Sjl139090 if ((ret = hvio_intr_gettarget(DIP_TO_HANDLE(dip), pxu_p,
4500Sstevel@tonic-gate sysino, cpuid)) != H_EOK) {
4510Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "hvio_intr_gettarget failed, ret 0x%lx\n",
4520Sstevel@tonic-gate ret);
4530Sstevel@tonic-gate return (DDI_FAILURE);
4540Sstevel@tonic-gate }
4550Sstevel@tonic-gate
4560Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_gettarget: cpuid 0x%x\n", cpuid);
4570Sstevel@tonic-gate
4580Sstevel@tonic-gate return (DDI_SUCCESS);
4590Sstevel@tonic-gate }
4600Sstevel@tonic-gate
4610Sstevel@tonic-gate /*ARGSUSED*/
4620Sstevel@tonic-gate int
px_lib_intr_settarget(dev_info_t * dip,sysino_t sysino,cpuid_t cpuid)4630Sstevel@tonic-gate px_lib_intr_settarget(dev_info_t *dip, sysino_t sysino, cpuid_t cpuid)
4640Sstevel@tonic-gate {
4651772Sjl139090 px_t *px_p = DIP_TO_STATE(dip);
4661772Sjl139090 pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
4670Sstevel@tonic-gate uint64_t ret;
4680Sstevel@tonic-gate
4690Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_settarget: dip 0x%p sysino 0x%llx "
4700Sstevel@tonic-gate "cpuid 0x%x\n", dip, sysino, cpuid);
4710Sstevel@tonic-gate
4721772Sjl139090 if ((ret = hvio_intr_settarget(DIP_TO_HANDLE(dip), pxu_p,
4730Sstevel@tonic-gate sysino, cpuid)) != H_EOK) {
4740Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "hvio_intr_settarget failed, ret 0x%lx\n",
4750Sstevel@tonic-gate ret);
4760Sstevel@tonic-gate return (DDI_FAILURE);
4770Sstevel@tonic-gate }
4780Sstevel@tonic-gate
4790Sstevel@tonic-gate return (DDI_SUCCESS);
4800Sstevel@tonic-gate }
4810Sstevel@tonic-gate
4820Sstevel@tonic-gate /*ARGSUSED*/
4830Sstevel@tonic-gate int
px_lib_intr_reset(dev_info_t * dip)4840Sstevel@tonic-gate px_lib_intr_reset(dev_info_t *dip)
4850Sstevel@tonic-gate {
4860Sstevel@tonic-gate devino_t ino;
4870Sstevel@tonic-gate sysino_t sysino;
4880Sstevel@tonic-gate
4890Sstevel@tonic-gate DBG(DBG_LIB_INT, dip, "px_lib_intr_reset: dip 0x%p\n", dip);
4900Sstevel@tonic-gate
4910Sstevel@tonic-gate /* Reset all Interrupts */
4920Sstevel@tonic-gate for (ino = 0; ino < INTERRUPT_MAPPING_ENTRIES; ino++) {
4930Sstevel@tonic-gate if (px_lib_intr_devino_to_sysino(dip, ino,
4940Sstevel@tonic-gate &sysino) != DDI_SUCCESS)
4950Sstevel@tonic-gate return (BF_FATAL);
4960Sstevel@tonic-gate
4970Sstevel@tonic-gate if (px_lib_intr_setstate(dip, sysino,
4980Sstevel@tonic-gate INTR_IDLE_STATE) != DDI_SUCCESS)
4990Sstevel@tonic-gate return (BF_FATAL);
5000Sstevel@tonic-gate }
5010Sstevel@tonic-gate
5020Sstevel@tonic-gate return (BF_NONE);
5030Sstevel@tonic-gate }
5040Sstevel@tonic-gate
5050Sstevel@tonic-gate /*ARGSUSED*/
5060Sstevel@tonic-gate int
px_lib_iommu_map(dev_info_t * dip,tsbid_t tsbid,pages_t pages,io_attributes_t attr,void * addr,size_t pfn_index,int flags)5070Sstevel@tonic-gate px_lib_iommu_map(dev_info_t *dip, tsbid_t tsbid, pages_t pages,
5081617Sgovinda io_attributes_t attr, void *addr, size_t pfn_index, int flags)
5090Sstevel@tonic-gate {
5100Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
5110Sstevel@tonic-gate pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
5120Sstevel@tonic-gate uint64_t ret;
5130Sstevel@tonic-gate
5140Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip, "px_lib_iommu_map: dip 0x%p tsbid 0x%llx "
5159707SDaniel.Ice@Sun.COM "pages 0x%x attr 0x%llx addr 0x%p pfn_index 0x%llx flags 0x%x\n",
5161617Sgovinda dip, tsbid, pages, attr, addr, pfn_index, flags);
5170Sstevel@tonic-gate
5180Sstevel@tonic-gate if ((ret = hvio_iommu_map(px_p->px_dev_hdl, pxu_p, tsbid, pages,
5191617Sgovinda attr, addr, pfn_index, flags)) != H_EOK) {
5200Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip,
5210Sstevel@tonic-gate "px_lib_iommu_map failed, ret 0x%lx\n", ret);
5220Sstevel@tonic-gate return (DDI_FAILURE);
5230Sstevel@tonic-gate }
5240Sstevel@tonic-gate
5250Sstevel@tonic-gate return (DDI_SUCCESS);
5260Sstevel@tonic-gate }
5270Sstevel@tonic-gate
5280Sstevel@tonic-gate /*ARGSUSED*/
5290Sstevel@tonic-gate int
px_lib_iommu_demap(dev_info_t * dip,tsbid_t tsbid,pages_t pages)5300Sstevel@tonic-gate px_lib_iommu_demap(dev_info_t *dip, tsbid_t tsbid, pages_t pages)
5310Sstevel@tonic-gate {
5320Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
5330Sstevel@tonic-gate pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
5340Sstevel@tonic-gate uint64_t ret;
5350Sstevel@tonic-gate
5360Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip, "px_lib_iommu_demap: dip 0x%p tsbid 0x%llx "
5370Sstevel@tonic-gate "pages 0x%x\n", dip, tsbid, pages);
5380Sstevel@tonic-gate
5390Sstevel@tonic-gate if ((ret = hvio_iommu_demap(px_p->px_dev_hdl, pxu_p, tsbid, pages))
5400Sstevel@tonic-gate != H_EOK) {
5410Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip,
5420Sstevel@tonic-gate "px_lib_iommu_demap failed, ret 0x%lx\n", ret);
5430Sstevel@tonic-gate
5440Sstevel@tonic-gate return (DDI_FAILURE);
5450Sstevel@tonic-gate }
5460Sstevel@tonic-gate
5470Sstevel@tonic-gate return (DDI_SUCCESS);
5480Sstevel@tonic-gate }
5490Sstevel@tonic-gate
5500Sstevel@tonic-gate /*ARGSUSED*/
5510Sstevel@tonic-gate int
px_lib_iommu_getmap(dev_info_t * dip,tsbid_t tsbid,io_attributes_t * attr_p,r_addr_t * r_addr_p)5521617Sgovinda px_lib_iommu_getmap(dev_info_t *dip, tsbid_t tsbid, io_attributes_t *attr_p,
5531617Sgovinda r_addr_t *r_addr_p)
5540Sstevel@tonic-gate {
5550Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
5560Sstevel@tonic-gate pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
5570Sstevel@tonic-gate uint64_t ret;
5580Sstevel@tonic-gate
5590Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip, "px_lib_iommu_getmap: dip 0x%p tsbid 0x%llx\n",
5600Sstevel@tonic-gate dip, tsbid);
5610Sstevel@tonic-gate
5620Sstevel@tonic-gate if ((ret = hvio_iommu_getmap(DIP_TO_HANDLE(dip), pxu_p, tsbid,
5631617Sgovinda attr_p, r_addr_p)) != H_EOK) {
5640Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip,
5650Sstevel@tonic-gate "hvio_iommu_getmap failed, ret 0x%lx\n", ret);
5660Sstevel@tonic-gate
5670Sstevel@tonic-gate return ((ret == H_ENOMAP) ? DDI_DMA_NOMAPPING:DDI_FAILURE);
5680Sstevel@tonic-gate }
5690Sstevel@tonic-gate
5709707SDaniel.Ice@Sun.COM DBG(DBG_LIB_DMA, dip, "px_lib_iommu_getmap: attr 0x%llx "
5719707SDaniel.Ice@Sun.COM "r_addr 0x%llx\n", *attr_p, *r_addr_p);
5720Sstevel@tonic-gate
5730Sstevel@tonic-gate return (DDI_SUCCESS);
5740Sstevel@tonic-gate }
5750Sstevel@tonic-gate
576*12619Sandrew.rutz@sun.com int
px_lib_iommu_detach(px_t * px_p)577*12619Sandrew.rutz@sun.com px_lib_iommu_detach(px_t *px_p)
578*12619Sandrew.rutz@sun.com {
579*12619Sandrew.rutz@sun.com /*
580*12619Sandrew.rutz@sun.com * Deallocate DVMA addr space that was reserved for OBP TTE's
581*12619Sandrew.rutz@sun.com * during Attach.
582*12619Sandrew.rutz@sun.com */
583*12619Sandrew.rutz@sun.com hvio_obptsb_detach(px_p);
584*12619Sandrew.rutz@sun.com
585*12619Sandrew.rutz@sun.com return (DDI_SUCCESS);
586*12619Sandrew.rutz@sun.com }
5870Sstevel@tonic-gate
5880Sstevel@tonic-gate /*
5890Sstevel@tonic-gate * Checks dma attributes against system bypass ranges
5900Sstevel@tonic-gate * The bypass range is determined by the hardware. Return them so the
5910Sstevel@tonic-gate * common code can do generic checking against them.
5920Sstevel@tonic-gate */
5930Sstevel@tonic-gate /*ARGSUSED*/
5940Sstevel@tonic-gate int
px_lib_dma_bypass_rngchk(dev_info_t * dip,ddi_dma_attr_t * attr_p,uint64_t * lo_p,uint64_t * hi_p)5951772Sjl139090 px_lib_dma_bypass_rngchk(dev_info_t *dip, ddi_dma_attr_t *attr_p,
5961772Sjl139090 uint64_t *lo_p, uint64_t *hi_p)
5970Sstevel@tonic-gate {
5981772Sjl139090 px_t *px_p = DIP_TO_STATE(dip);
5991772Sjl139090 pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
6001772Sjl139090
6011772Sjl139090 *lo_p = hvio_get_bypass_base(pxu_p);
6021772Sjl139090 *hi_p = hvio_get_bypass_end(pxu_p);
6030Sstevel@tonic-gate
6040Sstevel@tonic-gate return (DDI_SUCCESS);
6050Sstevel@tonic-gate }
6060Sstevel@tonic-gate
6070Sstevel@tonic-gate
6080Sstevel@tonic-gate /*ARGSUSED*/
6090Sstevel@tonic-gate int
px_lib_iommu_getbypass(dev_info_t * dip,r_addr_t ra,io_attributes_t attr,io_addr_t * io_addr_p)6101617Sgovinda px_lib_iommu_getbypass(dev_info_t *dip, r_addr_t ra, io_attributes_t attr,
6111617Sgovinda io_addr_t *io_addr_p)
6120Sstevel@tonic-gate {
6130Sstevel@tonic-gate uint64_t ret;
6141772Sjl139090 px_t *px_p = DIP_TO_STATE(dip);
6151772Sjl139090 pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
6160Sstevel@tonic-gate
6170Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip, "px_lib_iommu_getbypass: dip 0x%p ra 0x%llx "
6189707SDaniel.Ice@Sun.COM "attr 0x%llx\n", dip, ra, attr);
6190Sstevel@tonic-gate
6201772Sjl139090 if ((ret = hvio_iommu_getbypass(DIP_TO_HANDLE(dip), pxu_p, ra,
6211772Sjl139090 attr, io_addr_p)) != H_EOK) {
6220Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip,
6230Sstevel@tonic-gate "hvio_iommu_getbypass failed, ret 0x%lx\n", ret);
6240Sstevel@tonic-gate return (DDI_FAILURE);
6250Sstevel@tonic-gate }
6260Sstevel@tonic-gate
6270Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip, "px_lib_iommu_getbypass: io_addr 0x%llx\n",
6280Sstevel@tonic-gate *io_addr_p);
6290Sstevel@tonic-gate
6300Sstevel@tonic-gate return (DDI_SUCCESS);
6310Sstevel@tonic-gate }
6320Sstevel@tonic-gate
6330Sstevel@tonic-gate /*
6348691SLida.Horn@Sun.COM * Returns any needed IO address bit(s) for relaxed ordering in IOMMU
6358691SLida.Horn@Sun.COM * bypass mode.
6368691SLida.Horn@Sun.COM */
6378691SLida.Horn@Sun.COM uint64_t
px_lib_ro_bypass(dev_info_t * dip,io_attributes_t attr,uint64_t ioaddr)6388691SLida.Horn@Sun.COM px_lib_ro_bypass(dev_info_t *dip, io_attributes_t attr, uint64_t ioaddr)
6398691SLida.Horn@Sun.COM {
6408691SLida.Horn@Sun.COM px_t *px_p = DIP_TO_STATE(dip);
6418691SLida.Horn@Sun.COM pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
6428691SLida.Horn@Sun.COM
6438691SLida.Horn@Sun.COM if ((PX_CHIP_TYPE(pxu_p) == PX_CHIP_OBERON) && (attr & PCI_MAP_ATTR_RO))
6448691SLida.Horn@Sun.COM return (MMU_OBERON_BYPASS_RO | ioaddr);
6458691SLida.Horn@Sun.COM else
6468691SLida.Horn@Sun.COM return (ioaddr);
6478691SLida.Horn@Sun.COM }
6488691SLida.Horn@Sun.COM
6498691SLida.Horn@Sun.COM /*
6500Sstevel@tonic-gate * bus dma sync entry point.
6510Sstevel@tonic-gate */
6520Sstevel@tonic-gate /*ARGSUSED*/
6530Sstevel@tonic-gate int
px_lib_dma_sync(dev_info_t * dip,dev_info_t * rdip,ddi_dma_handle_t handle,off_t off,size_t len,uint_t cache_flags)6540Sstevel@tonic-gate px_lib_dma_sync(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle,
6551617Sgovinda off_t off, size_t len, uint_t cache_flags)
6560Sstevel@tonic-gate {
6570Sstevel@tonic-gate ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle;
6581772Sjl139090 px_t *px_p = DIP_TO_STATE(dip);
6591772Sjl139090 pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
6600Sstevel@tonic-gate
6610Sstevel@tonic-gate DBG(DBG_LIB_DMA, dip, "px_lib_dma_sync: dip 0x%p rdip 0x%p "
6620Sstevel@tonic-gate "handle 0x%llx off 0x%x len 0x%x flags 0x%x\n",
6630Sstevel@tonic-gate dip, rdip, handle, off, len, cache_flags);
6640Sstevel@tonic-gate
6650Sstevel@tonic-gate /*
6661772Sjl139090 * No flush needed for Oberon
6671772Sjl139090 */
6681772Sjl139090 if (PX_CHIP_TYPE(pxu_p) == PX_CHIP_OBERON)
6691772Sjl139090 return (DDI_SUCCESS);
6701772Sjl139090
6711772Sjl139090 /*
6720Sstevel@tonic-gate * jbus_stst_order is found only in certain cpu modules.
6730Sstevel@tonic-gate * Just return success if not present.
6740Sstevel@tonic-gate */
6750Sstevel@tonic-gate if (&jbus_stst_order == NULL)
6760Sstevel@tonic-gate return (DDI_SUCCESS);
6770Sstevel@tonic-gate
678909Segillett if (!(mp->dmai_flags & PX_DMAI_FLAGS_INUSE)) {
67927Sjchu cmn_err(CE_WARN, "%s%d: Unbound dma handle %p.",
68027Sjchu ddi_driver_name(rdip), ddi_get_instance(rdip), (void *)mp);
68127Sjchu
6820Sstevel@tonic-gate return (DDI_FAILURE);
6830Sstevel@tonic-gate }
6840Sstevel@tonic-gate
685909Segillett if (mp->dmai_flags & PX_DMAI_FLAGS_NOSYNC)
6860Sstevel@tonic-gate return (DDI_SUCCESS);
6870Sstevel@tonic-gate
6880Sstevel@tonic-gate /*
6890Sstevel@tonic-gate * No flush needed when sending data from memory to device.
6900Sstevel@tonic-gate * Nothing to do to "sync" memory to what device would already see.
6910Sstevel@tonic-gate */
6920Sstevel@tonic-gate if (!(mp->dmai_rflags & DDI_DMA_READ) ||
6930Sstevel@tonic-gate ((cache_flags & PX_DMA_SYNC_DDI_FLAGS) == DDI_DMA_SYNC_FORDEV))
6940Sstevel@tonic-gate return (DDI_SUCCESS);
6950Sstevel@tonic-gate
6960Sstevel@tonic-gate /*
6970Sstevel@tonic-gate * Perform necessary cpu workaround to ensure jbus ordering.
6980Sstevel@tonic-gate * CPU's internal "invalidate FIFOs" are flushed.
6990Sstevel@tonic-gate */
7000Sstevel@tonic-gate
7010Sstevel@tonic-gate #if !defined(lint)
7020Sstevel@tonic-gate kpreempt_disable();
7030Sstevel@tonic-gate #endif
7040Sstevel@tonic-gate jbus_stst_order();
7050Sstevel@tonic-gate #if !defined(lint)
7060Sstevel@tonic-gate kpreempt_enable();
7070Sstevel@tonic-gate #endif
7080Sstevel@tonic-gate return (DDI_SUCCESS);
7090Sstevel@tonic-gate }
7100Sstevel@tonic-gate
7110Sstevel@tonic-gate /*
7120Sstevel@tonic-gate * MSIQ Functions:
7130Sstevel@tonic-gate */
7140Sstevel@tonic-gate /*ARGSUSED*/
7150Sstevel@tonic-gate int
px_lib_msiq_init(dev_info_t * dip)7160Sstevel@tonic-gate px_lib_msiq_init(dev_info_t *dip)
7170Sstevel@tonic-gate {
7180Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
7190Sstevel@tonic-gate pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
7200Sstevel@tonic-gate px_msiq_state_t *msiq_state_p = &px_p->px_ib_p->ib_msiq_state;
7210Sstevel@tonic-gate px_dvma_addr_t pg_index;
7227403SAlan.Adamson@Sun.COM size_t q_sz = msiq_state_p->msiq_rec_cnt * sizeof (msiq_rec_t);
7230Sstevel@tonic-gate size_t size;
7247403SAlan.Adamson@Sun.COM int i, ret;
7250Sstevel@tonic-gate
7260Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_init: dip 0x%p\n", dip);
7270Sstevel@tonic-gate
7287403SAlan.Adamson@Sun.COM /* must aligned on q_sz (happens to be !!! page) boundary */
7297403SAlan.Adamson@Sun.COM ASSERT(q_sz == 8 * 1024);
7307403SAlan.Adamson@Sun.COM
7310Sstevel@tonic-gate /*
7320Sstevel@tonic-gate * Map the EQ memory into the Fire MMU (has to be 512KB aligned)
7330Sstevel@tonic-gate * and then initialize the base address register.
7340Sstevel@tonic-gate *
7350Sstevel@tonic-gate * Allocate entries from Fire IOMMU so that the resulting address
7360Sstevel@tonic-gate * is properly aligned. Calculate the index of the first allocated
7370Sstevel@tonic-gate * entry. Note: The size of the mapping is assumed to be a multiple
7380Sstevel@tonic-gate * of the page size.
7390Sstevel@tonic-gate */
7407403SAlan.Adamson@Sun.COM size = msiq_state_p->msiq_cnt * q_sz;
7417403SAlan.Adamson@Sun.COM
7427403SAlan.Adamson@Sun.COM msiq_state_p->msiq_buf_p = kmem_zalloc(size, KM_SLEEP);
7437403SAlan.Adamson@Sun.COM
7447403SAlan.Adamson@Sun.COM for (i = 0; i < msiq_state_p->msiq_cnt; i++)
7457403SAlan.Adamson@Sun.COM msiq_state_p->msiq_p[i].msiq_base_p = (msiqhead_t *)
7467403SAlan.Adamson@Sun.COM ((caddr_t)msiq_state_p->msiq_buf_p + (i * q_sz));
7470Sstevel@tonic-gate
7480Sstevel@tonic-gate pxu_p->msiq_mapped_p = vmem_xalloc(px_p->px_mmu_p->mmu_dvma_map,
7490Sstevel@tonic-gate size, (512 * 1024), 0, 0, NULL, NULL, VM_NOSLEEP | VM_BESTFIT);
7500Sstevel@tonic-gate
7510Sstevel@tonic-gate if (pxu_p->msiq_mapped_p == NULL)
7520Sstevel@tonic-gate return (DDI_FAILURE);
7530Sstevel@tonic-gate
7540Sstevel@tonic-gate pg_index = MMU_PAGE_INDEX(px_p->px_mmu_p,
7550Sstevel@tonic-gate MMU_BTOP((ulong_t)pxu_p->msiq_mapped_p));
7560Sstevel@tonic-gate
7570Sstevel@tonic-gate if ((ret = px_lib_iommu_map(px_p->px_dip, PCI_TSBID(0, pg_index),
7582755Segillett MMU_BTOP(size), PCI_MAP_ATTR_WRITE, msiq_state_p->msiq_buf_p,
7592755Segillett 0, MMU_MAP_BUF)) != DDI_SUCCESS) {
7600Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip,
7616983Sanbui "px_lib_msiq_init: px_lib_iommu_map failed, "
7626983Sanbui "ret 0x%lx\n", ret);
7630Sstevel@tonic-gate
7640Sstevel@tonic-gate (void) px_lib_msiq_fini(dip);
7650Sstevel@tonic-gate return (DDI_FAILURE);
7660Sstevel@tonic-gate }
7670Sstevel@tonic-gate
7687124Sanbui if ((ret = hvio_msiq_init(DIP_TO_HANDLE(dip),
7697124Sanbui pxu_p)) != H_EOK) {
7707124Sanbui DBG(DBG_LIB_MSIQ, dip,
7717124Sanbui "hvio_msiq_init failed, ret 0x%lx\n", ret);
7727124Sanbui
7737124Sanbui (void) px_lib_msiq_fini(dip);
7747124Sanbui return (DDI_FAILURE);
7757124Sanbui }
7760Sstevel@tonic-gate
7770Sstevel@tonic-gate return (DDI_SUCCESS);
7780Sstevel@tonic-gate }
7790Sstevel@tonic-gate
7800Sstevel@tonic-gate /*ARGSUSED*/
7810Sstevel@tonic-gate int
px_lib_msiq_fini(dev_info_t * dip)7820Sstevel@tonic-gate px_lib_msiq_fini(dev_info_t *dip)
7830Sstevel@tonic-gate {
7840Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
7850Sstevel@tonic-gate pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
7860Sstevel@tonic-gate px_msiq_state_t *msiq_state_p = &px_p->px_ib_p->ib_msiq_state;
7870Sstevel@tonic-gate px_dvma_addr_t pg_index;
7880Sstevel@tonic-gate size_t size;
7890Sstevel@tonic-gate
7900Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_fini: dip 0x%p\n", dip);
7910Sstevel@tonic-gate
7920Sstevel@tonic-gate /*
7930Sstevel@tonic-gate * Unmap and free the EQ memory that had been mapped
7940Sstevel@tonic-gate * into the Fire IOMMU.
7950Sstevel@tonic-gate */
7960Sstevel@tonic-gate size = msiq_state_p->msiq_cnt *
7970Sstevel@tonic-gate msiq_state_p->msiq_rec_cnt * sizeof (msiq_rec_t);
7980Sstevel@tonic-gate
7990Sstevel@tonic-gate pg_index = MMU_PAGE_INDEX(px_p->px_mmu_p,
8000Sstevel@tonic-gate MMU_BTOP((ulong_t)pxu_p->msiq_mapped_p));
8010Sstevel@tonic-gate
8020Sstevel@tonic-gate (void) px_lib_iommu_demap(px_p->px_dip,
8030Sstevel@tonic-gate PCI_TSBID(0, pg_index), MMU_BTOP(size));
8040Sstevel@tonic-gate
8050Sstevel@tonic-gate /* Free the entries from the Fire MMU */
8060Sstevel@tonic-gate vmem_xfree(px_p->px_mmu_p->mmu_dvma_map,
8070Sstevel@tonic-gate (void *)pxu_p->msiq_mapped_p, size);
8080Sstevel@tonic-gate
8097403SAlan.Adamson@Sun.COM kmem_free(msiq_state_p->msiq_buf_p, msiq_state_p->msiq_cnt *
8107403SAlan.Adamson@Sun.COM msiq_state_p->msiq_rec_cnt * sizeof (msiq_rec_t));
8117403SAlan.Adamson@Sun.COM
8120Sstevel@tonic-gate return (DDI_SUCCESS);
8130Sstevel@tonic-gate }
8140Sstevel@tonic-gate
8150Sstevel@tonic-gate /*ARGSUSED*/
8160Sstevel@tonic-gate int
px_lib_msiq_info(dev_info_t * dip,msiqid_t msiq_id,r_addr_t * ra_p,uint_t * msiq_rec_cnt_p)8170Sstevel@tonic-gate px_lib_msiq_info(dev_info_t *dip, msiqid_t msiq_id, r_addr_t *ra_p,
8180Sstevel@tonic-gate uint_t *msiq_rec_cnt_p)
8190Sstevel@tonic-gate {
8200Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
8210Sstevel@tonic-gate px_msiq_state_t *msiq_state_p = &px_p->px_ib_p->ib_msiq_state;
8220Sstevel@tonic-gate size_t msiq_size;
8230Sstevel@tonic-gate
8240Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_msiq_info: dip 0x%p msiq_id 0x%x\n",
8250Sstevel@tonic-gate dip, msiq_id);
8260Sstevel@tonic-gate
8270Sstevel@tonic-gate msiq_size = msiq_state_p->msiq_rec_cnt * sizeof (msiq_rec_t);
8282755Segillett ra_p = (r_addr_t *)((caddr_t)msiq_state_p->msiq_buf_p +
8292755Segillett (msiq_id * msiq_size));
8300Sstevel@tonic-gate
8310Sstevel@tonic-gate *msiq_rec_cnt_p = msiq_state_p->msiq_rec_cnt;
8320Sstevel@tonic-gate
8330Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_msiq_info: ra_p 0x%p msiq_rec_cnt 0x%x\n",
8340Sstevel@tonic-gate ra_p, *msiq_rec_cnt_p);
8350Sstevel@tonic-gate
8360Sstevel@tonic-gate return (DDI_SUCCESS);
8370Sstevel@tonic-gate }
8380Sstevel@tonic-gate
8390Sstevel@tonic-gate /*ARGSUSED*/
8400Sstevel@tonic-gate int
px_lib_msiq_getvalid(dev_info_t * dip,msiqid_t msiq_id,pci_msiq_valid_state_t * msiq_valid_state)8410Sstevel@tonic-gate px_lib_msiq_getvalid(dev_info_t *dip, msiqid_t msiq_id,
8420Sstevel@tonic-gate pci_msiq_valid_state_t *msiq_valid_state)
8430Sstevel@tonic-gate {
8440Sstevel@tonic-gate uint64_t ret;
8450Sstevel@tonic-gate
8460Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_getvalid: dip 0x%p msiq_id 0x%x\n",
8470Sstevel@tonic-gate dip, msiq_id);
8480Sstevel@tonic-gate
8490Sstevel@tonic-gate if ((ret = hvio_msiq_getvalid(DIP_TO_HANDLE(dip),
8500Sstevel@tonic-gate msiq_id, msiq_valid_state)) != H_EOK) {
8510Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip,
8520Sstevel@tonic-gate "hvio_msiq_getvalid failed, ret 0x%lx\n", ret);
8530Sstevel@tonic-gate return (DDI_FAILURE);
8540Sstevel@tonic-gate }
8550Sstevel@tonic-gate
8560Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_getvalid: msiq_valid_state 0x%x\n",
8570Sstevel@tonic-gate *msiq_valid_state);
8580Sstevel@tonic-gate
8590Sstevel@tonic-gate return (DDI_SUCCESS);
8600Sstevel@tonic-gate }
8610Sstevel@tonic-gate
8620Sstevel@tonic-gate /*ARGSUSED*/
8630Sstevel@tonic-gate int
px_lib_msiq_setvalid(dev_info_t * dip,msiqid_t msiq_id,pci_msiq_valid_state_t msiq_valid_state)8640Sstevel@tonic-gate px_lib_msiq_setvalid(dev_info_t *dip, msiqid_t msiq_id,
8650Sstevel@tonic-gate pci_msiq_valid_state_t msiq_valid_state)
8660Sstevel@tonic-gate {
8670Sstevel@tonic-gate uint64_t ret;
8680Sstevel@tonic-gate
8690Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_setvalid: dip 0x%p msiq_id 0x%x "
8700Sstevel@tonic-gate "msiq_valid_state 0x%x\n", dip, msiq_id, msiq_valid_state);
8710Sstevel@tonic-gate
8720Sstevel@tonic-gate if ((ret = hvio_msiq_setvalid(DIP_TO_HANDLE(dip),
8730Sstevel@tonic-gate msiq_id, msiq_valid_state)) != H_EOK) {
8740Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip,
8750Sstevel@tonic-gate "hvio_msiq_setvalid failed, ret 0x%lx\n", ret);
8760Sstevel@tonic-gate return (DDI_FAILURE);
8770Sstevel@tonic-gate }
8780Sstevel@tonic-gate
8790Sstevel@tonic-gate return (DDI_SUCCESS);
8800Sstevel@tonic-gate }
8810Sstevel@tonic-gate
8820Sstevel@tonic-gate /*ARGSUSED*/
8830Sstevel@tonic-gate int
px_lib_msiq_getstate(dev_info_t * dip,msiqid_t msiq_id,pci_msiq_state_t * msiq_state)8840Sstevel@tonic-gate px_lib_msiq_getstate(dev_info_t *dip, msiqid_t msiq_id,
8850Sstevel@tonic-gate pci_msiq_state_t *msiq_state)
8860Sstevel@tonic-gate {
8870Sstevel@tonic-gate uint64_t ret;
8880Sstevel@tonic-gate
8890Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_getstate: dip 0x%p msiq_id 0x%x\n",
8900Sstevel@tonic-gate dip, msiq_id);
8910Sstevel@tonic-gate
8920Sstevel@tonic-gate if ((ret = hvio_msiq_getstate(DIP_TO_HANDLE(dip),
8930Sstevel@tonic-gate msiq_id, msiq_state)) != H_EOK) {
8940Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip,
8950Sstevel@tonic-gate "hvio_msiq_getstate failed, ret 0x%lx\n", ret);
8960Sstevel@tonic-gate return (DDI_FAILURE);
8970Sstevel@tonic-gate }
8980Sstevel@tonic-gate
8990Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_getstate: msiq_state 0x%x\n",
9000Sstevel@tonic-gate *msiq_state);
9010Sstevel@tonic-gate
9020Sstevel@tonic-gate return (DDI_SUCCESS);
9030Sstevel@tonic-gate }
9040Sstevel@tonic-gate
9050Sstevel@tonic-gate /*ARGSUSED*/
9060Sstevel@tonic-gate int
px_lib_msiq_setstate(dev_info_t * dip,msiqid_t msiq_id,pci_msiq_state_t msiq_state)9070Sstevel@tonic-gate px_lib_msiq_setstate(dev_info_t *dip, msiqid_t msiq_id,
9080Sstevel@tonic-gate pci_msiq_state_t msiq_state)
9090Sstevel@tonic-gate {
9100Sstevel@tonic-gate uint64_t ret;
9110Sstevel@tonic-gate
9120Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_setstate: dip 0x%p msiq_id 0x%x "
9130Sstevel@tonic-gate "msiq_state 0x%x\n", dip, msiq_id, msiq_state);
9140Sstevel@tonic-gate
9150Sstevel@tonic-gate if ((ret = hvio_msiq_setstate(DIP_TO_HANDLE(dip),
9160Sstevel@tonic-gate msiq_id, msiq_state)) != H_EOK) {
9170Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip,
9180Sstevel@tonic-gate "hvio_msiq_setstate failed, ret 0x%lx\n", ret);
9190Sstevel@tonic-gate return (DDI_FAILURE);
9200Sstevel@tonic-gate }
9210Sstevel@tonic-gate
9220Sstevel@tonic-gate return (DDI_SUCCESS);
9230Sstevel@tonic-gate }
9240Sstevel@tonic-gate
9250Sstevel@tonic-gate /*ARGSUSED*/
9260Sstevel@tonic-gate int
px_lib_msiq_gethead(dev_info_t * dip,msiqid_t msiq_id,msiqhead_t * msiq_head)9270Sstevel@tonic-gate px_lib_msiq_gethead(dev_info_t *dip, msiqid_t msiq_id,
9280Sstevel@tonic-gate msiqhead_t *msiq_head)
9290Sstevel@tonic-gate {
9300Sstevel@tonic-gate uint64_t ret;
9310Sstevel@tonic-gate
9320Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_gethead: dip 0x%p msiq_id 0x%x\n",
9330Sstevel@tonic-gate dip, msiq_id);
9340Sstevel@tonic-gate
9350Sstevel@tonic-gate if ((ret = hvio_msiq_gethead(DIP_TO_HANDLE(dip),
9360Sstevel@tonic-gate msiq_id, msiq_head)) != H_EOK) {
9370Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip,
9380Sstevel@tonic-gate "hvio_msiq_gethead failed, ret 0x%lx\n", ret);
9390Sstevel@tonic-gate return (DDI_FAILURE);
9400Sstevel@tonic-gate }
9410Sstevel@tonic-gate
9420Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_gethead: msiq_head 0x%x\n",
9430Sstevel@tonic-gate *msiq_head);
9440Sstevel@tonic-gate
9450Sstevel@tonic-gate return (DDI_SUCCESS);
9460Sstevel@tonic-gate }
9470Sstevel@tonic-gate
9480Sstevel@tonic-gate /*ARGSUSED*/
9490Sstevel@tonic-gate int
px_lib_msiq_sethead(dev_info_t * dip,msiqid_t msiq_id,msiqhead_t msiq_head)9500Sstevel@tonic-gate px_lib_msiq_sethead(dev_info_t *dip, msiqid_t msiq_id,
9510Sstevel@tonic-gate msiqhead_t msiq_head)
9520Sstevel@tonic-gate {
9530Sstevel@tonic-gate uint64_t ret;
9540Sstevel@tonic-gate
9550Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_sethead: dip 0x%p msiq_id 0x%x "
9560Sstevel@tonic-gate "msiq_head 0x%x\n", dip, msiq_id, msiq_head);
9570Sstevel@tonic-gate
9580Sstevel@tonic-gate if ((ret = hvio_msiq_sethead(DIP_TO_HANDLE(dip),
9590Sstevel@tonic-gate msiq_id, msiq_head)) != H_EOK) {
9600Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip,
9610Sstevel@tonic-gate "hvio_msiq_sethead failed, ret 0x%lx\n", ret);
9620Sstevel@tonic-gate return (DDI_FAILURE);
9630Sstevel@tonic-gate }
9640Sstevel@tonic-gate
9650Sstevel@tonic-gate return (DDI_SUCCESS);
9660Sstevel@tonic-gate }
9670Sstevel@tonic-gate
9680Sstevel@tonic-gate /*ARGSUSED*/
9690Sstevel@tonic-gate int
px_lib_msiq_gettail(dev_info_t * dip,msiqid_t msiq_id,msiqtail_t * msiq_tail)9700Sstevel@tonic-gate px_lib_msiq_gettail(dev_info_t *dip, msiqid_t msiq_id,
9710Sstevel@tonic-gate msiqtail_t *msiq_tail)
9720Sstevel@tonic-gate {
9730Sstevel@tonic-gate uint64_t ret;
9740Sstevel@tonic-gate
9750Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_gettail: dip 0x%p msiq_id 0x%x\n",
9760Sstevel@tonic-gate dip, msiq_id);
9770Sstevel@tonic-gate
9780Sstevel@tonic-gate if ((ret = hvio_msiq_gettail(DIP_TO_HANDLE(dip),
9790Sstevel@tonic-gate msiq_id, msiq_tail)) != H_EOK) {
9800Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip,
9810Sstevel@tonic-gate "hvio_msiq_gettail failed, ret 0x%lx\n", ret);
9820Sstevel@tonic-gate return (DDI_FAILURE);
9830Sstevel@tonic-gate }
9840Sstevel@tonic-gate
9850Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msiq_gettail: msiq_tail 0x%x\n",
9860Sstevel@tonic-gate *msiq_tail);
9870Sstevel@tonic-gate
9880Sstevel@tonic-gate return (DDI_SUCCESS);
9890Sstevel@tonic-gate }
9900Sstevel@tonic-gate
9910Sstevel@tonic-gate /*ARGSUSED*/
9920Sstevel@tonic-gate void
px_lib_get_msiq_rec(dev_info_t * dip,msiqhead_t * msiq_head_p,msiq_rec_t * msiq_rec_p)9932588Segillett px_lib_get_msiq_rec(dev_info_t *dip, msiqhead_t *msiq_head_p,
9942588Segillett msiq_rec_t *msiq_rec_p)
9950Sstevel@tonic-gate {
9962588Segillett eq_rec_t *eq_rec_p = (eq_rec_t *)msiq_head_p;
9970Sstevel@tonic-gate
9980Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_get_msiq_rec: dip 0x%p eq_rec_p 0x%p\n",
9990Sstevel@tonic-gate dip, eq_rec_p);
10000Sstevel@tonic-gate
1001287Smg140465 if (!eq_rec_p->eq_rec_fmt_type) {
1002287Smg140465 /* Set msiq_rec_type to zero */
1003287Smg140465 msiq_rec_p->msiq_rec_type = 0;
10040Sstevel@tonic-gate
10050Sstevel@tonic-gate return;
10060Sstevel@tonic-gate }
10070Sstevel@tonic-gate
10080Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_get_msiq_rec: EQ RECORD, "
10090Sstevel@tonic-gate "eq_rec_rid 0x%llx eq_rec_fmt_type 0x%llx "
10100Sstevel@tonic-gate "eq_rec_len 0x%llx eq_rec_addr0 0x%llx "
10110Sstevel@tonic-gate "eq_rec_addr1 0x%llx eq_rec_data0 0x%llx "
10120Sstevel@tonic-gate "eq_rec_data1 0x%llx\n", eq_rec_p->eq_rec_rid,
10130Sstevel@tonic-gate eq_rec_p->eq_rec_fmt_type, eq_rec_p->eq_rec_len,
10140Sstevel@tonic-gate eq_rec_p->eq_rec_addr0, eq_rec_p->eq_rec_addr1,
10150Sstevel@tonic-gate eq_rec_p->eq_rec_data0, eq_rec_p->eq_rec_data1);
10160Sstevel@tonic-gate
10170Sstevel@tonic-gate /*
10180Sstevel@tonic-gate * Only upper 4 bits of eq_rec_fmt_type is used
10190Sstevel@tonic-gate * to identify the EQ record type.
10200Sstevel@tonic-gate */
10210Sstevel@tonic-gate switch (eq_rec_p->eq_rec_fmt_type >> 3) {
10220Sstevel@tonic-gate case EQ_REC_MSI32:
10230Sstevel@tonic-gate msiq_rec_p->msiq_rec_type = MSI32_REC;
10240Sstevel@tonic-gate
1025225Sess msiq_rec_p->msiq_rec_data.msi.msi_data =
1026225Sess eq_rec_p->eq_rec_data0;
10270Sstevel@tonic-gate break;
10280Sstevel@tonic-gate case EQ_REC_MSI64:
10290Sstevel@tonic-gate msiq_rec_p->msiq_rec_type = MSI64_REC;
10300Sstevel@tonic-gate
1031225Sess msiq_rec_p->msiq_rec_data.msi.msi_data =
1032225Sess eq_rec_p->eq_rec_data0;
10330Sstevel@tonic-gate break;
10340Sstevel@tonic-gate case EQ_REC_MSG:
10350Sstevel@tonic-gate msiq_rec_p->msiq_rec_type = MSG_REC;
10360Sstevel@tonic-gate
10370Sstevel@tonic-gate msiq_rec_p->msiq_rec_data.msg.msg_route =
10380Sstevel@tonic-gate eq_rec_p->eq_rec_fmt_type & 7;
10390Sstevel@tonic-gate msiq_rec_p->msiq_rec_data.msg.msg_targ = eq_rec_p->eq_rec_rid;
10400Sstevel@tonic-gate msiq_rec_p->msiq_rec_data.msg.msg_code = eq_rec_p->eq_rec_data0;
10410Sstevel@tonic-gate break;
10420Sstevel@tonic-gate default:
10430Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: px_lib_get_msiq_rec: "
1044671Skrishnae "0x%x is an unknown EQ record type",
10450Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip),
1046671Skrishnae (int)eq_rec_p->eq_rec_fmt_type);
10470Sstevel@tonic-gate break;
10480Sstevel@tonic-gate }
10490Sstevel@tonic-gate
10500Sstevel@tonic-gate msiq_rec_p->msiq_rec_rid = eq_rec_p->eq_rec_rid;
10510Sstevel@tonic-gate msiq_rec_p->msiq_rec_msi_addr = ((eq_rec_p->eq_rec_addr1 << 16) |
10520Sstevel@tonic-gate (eq_rec_p->eq_rec_addr0 << 2));
10532973Sgovinda }
10542973Sgovinda
10552973Sgovinda /*ARGSUSED*/
10562973Sgovinda void
px_lib_clr_msiq_rec(dev_info_t * dip,msiqhead_t * msiq_head_p)10572973Sgovinda px_lib_clr_msiq_rec(dev_info_t *dip, msiqhead_t *msiq_head_p)
10582973Sgovinda {
10592973Sgovinda eq_rec_t *eq_rec_p = (eq_rec_t *)msiq_head_p;
10602973Sgovinda
10612973Sgovinda DBG(DBG_LIB_MSIQ, dip, "px_lib_clr_msiq_rec: dip 0x%p eq_rec_p 0x%p\n",
10622973Sgovinda dip, eq_rec_p);
10632973Sgovinda
10642973Sgovinda if (eq_rec_p->eq_rec_fmt_type) {
10652973Sgovinda /* Zero out eq_rec_fmt_type field */
10662973Sgovinda eq_rec_p->eq_rec_fmt_type = 0;
10672973Sgovinda }
10680Sstevel@tonic-gate }
10690Sstevel@tonic-gate
10700Sstevel@tonic-gate /*
10710Sstevel@tonic-gate * MSI Functions:
10720Sstevel@tonic-gate */
10730Sstevel@tonic-gate /*ARGSUSED*/
10740Sstevel@tonic-gate int
px_lib_msi_init(dev_info_t * dip)10750Sstevel@tonic-gate px_lib_msi_init(dev_info_t *dip)
10760Sstevel@tonic-gate {
10770Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
10780Sstevel@tonic-gate px_msi_state_t *msi_state_p = &px_p->px_ib_p->ib_msi_state;
10790Sstevel@tonic-gate uint64_t ret;
10800Sstevel@tonic-gate
10810Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_init: dip 0x%p\n", dip);
10820Sstevel@tonic-gate
10830Sstevel@tonic-gate if ((ret = hvio_msi_init(DIP_TO_HANDLE(dip),
10840Sstevel@tonic-gate msi_state_p->msi_addr32, msi_state_p->msi_addr64)) != H_EOK) {
10850Sstevel@tonic-gate DBG(DBG_LIB_MSIQ, dip, "px_lib_msi_init failed, ret 0x%lx\n",
10860Sstevel@tonic-gate ret);
10870Sstevel@tonic-gate return (DDI_FAILURE);
10880Sstevel@tonic-gate }
10890Sstevel@tonic-gate
10900Sstevel@tonic-gate return (DDI_SUCCESS);
10910Sstevel@tonic-gate }
10920Sstevel@tonic-gate
10930Sstevel@tonic-gate /*ARGSUSED*/
10940Sstevel@tonic-gate int
px_lib_msi_getmsiq(dev_info_t * dip,msinum_t msi_num,msiqid_t * msiq_id)10950Sstevel@tonic-gate px_lib_msi_getmsiq(dev_info_t *dip, msinum_t msi_num,
10960Sstevel@tonic-gate msiqid_t *msiq_id)
10970Sstevel@tonic-gate {
10980Sstevel@tonic-gate uint64_t ret;
10990Sstevel@tonic-gate
11000Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_getmsiq: dip 0x%p msi_num 0x%x\n",
11010Sstevel@tonic-gate dip, msi_num);
11020Sstevel@tonic-gate
11030Sstevel@tonic-gate if ((ret = hvio_msi_getmsiq(DIP_TO_HANDLE(dip),
11040Sstevel@tonic-gate msi_num, msiq_id)) != H_EOK) {
11050Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip,
11060Sstevel@tonic-gate "hvio_msi_getmsiq failed, ret 0x%lx\n", ret);
11070Sstevel@tonic-gate return (DDI_FAILURE);
11080Sstevel@tonic-gate }
11090Sstevel@tonic-gate
11100Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_getmsiq: msiq_id 0x%x\n",
11110Sstevel@tonic-gate *msiq_id);
11120Sstevel@tonic-gate
11130Sstevel@tonic-gate return (DDI_SUCCESS);
11140Sstevel@tonic-gate }
11150Sstevel@tonic-gate
11160Sstevel@tonic-gate /*ARGSUSED*/
11170Sstevel@tonic-gate int
px_lib_msi_setmsiq(dev_info_t * dip,msinum_t msi_num,msiqid_t msiq_id,msi_type_t msitype)11180Sstevel@tonic-gate px_lib_msi_setmsiq(dev_info_t *dip, msinum_t msi_num,
11190Sstevel@tonic-gate msiqid_t msiq_id, msi_type_t msitype)
11200Sstevel@tonic-gate {
11210Sstevel@tonic-gate uint64_t ret;
11220Sstevel@tonic-gate
11230Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_setmsiq: dip 0x%p msi_num 0x%x "
11240Sstevel@tonic-gate "msq_id 0x%x\n", dip, msi_num, msiq_id);
11250Sstevel@tonic-gate
11260Sstevel@tonic-gate if ((ret = hvio_msi_setmsiq(DIP_TO_HANDLE(dip),
11270Sstevel@tonic-gate msi_num, msiq_id)) != H_EOK) {
11280Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip,
11290Sstevel@tonic-gate "hvio_msi_setmsiq failed, ret 0x%lx\n", ret);
11300Sstevel@tonic-gate return (DDI_FAILURE);
11310Sstevel@tonic-gate }
11320Sstevel@tonic-gate
11330Sstevel@tonic-gate return (DDI_SUCCESS);
11340Sstevel@tonic-gate }
11350Sstevel@tonic-gate
11360Sstevel@tonic-gate /*ARGSUSED*/
11370Sstevel@tonic-gate int
px_lib_msi_getvalid(dev_info_t * dip,msinum_t msi_num,pci_msi_valid_state_t * msi_valid_state)11380Sstevel@tonic-gate px_lib_msi_getvalid(dev_info_t *dip, msinum_t msi_num,
11390Sstevel@tonic-gate pci_msi_valid_state_t *msi_valid_state)
11400Sstevel@tonic-gate {
11410Sstevel@tonic-gate uint64_t ret;
11420Sstevel@tonic-gate
11430Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_getvalid: dip 0x%p msi_num 0x%x\n",
11440Sstevel@tonic-gate dip, msi_num);
11450Sstevel@tonic-gate
11460Sstevel@tonic-gate if ((ret = hvio_msi_getvalid(DIP_TO_HANDLE(dip),
11470Sstevel@tonic-gate msi_num, msi_valid_state)) != H_EOK) {
11480Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip,
11490Sstevel@tonic-gate "hvio_msi_getvalid failed, ret 0x%lx\n", ret);
11500Sstevel@tonic-gate return (DDI_FAILURE);
11510Sstevel@tonic-gate }
11520Sstevel@tonic-gate
11530Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_getvalid: msiq_id 0x%x\n",
11540Sstevel@tonic-gate *msi_valid_state);
11550Sstevel@tonic-gate
11560Sstevel@tonic-gate return (DDI_SUCCESS);
11570Sstevel@tonic-gate }
11580Sstevel@tonic-gate
11590Sstevel@tonic-gate /*ARGSUSED*/
11600Sstevel@tonic-gate int
px_lib_msi_setvalid(dev_info_t * dip,msinum_t msi_num,pci_msi_valid_state_t msi_valid_state)11610Sstevel@tonic-gate px_lib_msi_setvalid(dev_info_t *dip, msinum_t msi_num,
11620Sstevel@tonic-gate pci_msi_valid_state_t msi_valid_state)
11630Sstevel@tonic-gate {
11640Sstevel@tonic-gate uint64_t ret;
11650Sstevel@tonic-gate
11660Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_setvalid: dip 0x%p msi_num 0x%x "
11670Sstevel@tonic-gate "msi_valid_state 0x%x\n", dip, msi_num, msi_valid_state);
11680Sstevel@tonic-gate
11690Sstevel@tonic-gate if ((ret = hvio_msi_setvalid(DIP_TO_HANDLE(dip),
11700Sstevel@tonic-gate msi_num, msi_valid_state)) != H_EOK) {
11710Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip,
11720Sstevel@tonic-gate "hvio_msi_setvalid failed, ret 0x%lx\n", ret);
11730Sstevel@tonic-gate return (DDI_FAILURE);
11740Sstevel@tonic-gate }
11750Sstevel@tonic-gate
11760Sstevel@tonic-gate return (DDI_SUCCESS);
11770Sstevel@tonic-gate }
11780Sstevel@tonic-gate
11790Sstevel@tonic-gate /*ARGSUSED*/
11800Sstevel@tonic-gate int
px_lib_msi_getstate(dev_info_t * dip,msinum_t msi_num,pci_msi_state_t * msi_state)11810Sstevel@tonic-gate px_lib_msi_getstate(dev_info_t *dip, msinum_t msi_num,
11820Sstevel@tonic-gate pci_msi_state_t *msi_state)
11830Sstevel@tonic-gate {
11840Sstevel@tonic-gate uint64_t ret;
11850Sstevel@tonic-gate
11860Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_getstate: dip 0x%p msi_num 0x%x\n",
11870Sstevel@tonic-gate dip, msi_num);
11880Sstevel@tonic-gate
11890Sstevel@tonic-gate if ((ret = hvio_msi_getstate(DIP_TO_HANDLE(dip),
11900Sstevel@tonic-gate msi_num, msi_state)) != H_EOK) {
11910Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip,
11920Sstevel@tonic-gate "hvio_msi_getstate failed, ret 0x%lx\n", ret);
11930Sstevel@tonic-gate return (DDI_FAILURE);
11940Sstevel@tonic-gate }
11950Sstevel@tonic-gate
11960Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_getstate: msi_state 0x%x\n",
11970Sstevel@tonic-gate *msi_state);
11980Sstevel@tonic-gate
11990Sstevel@tonic-gate return (DDI_SUCCESS);
12000Sstevel@tonic-gate }
12010Sstevel@tonic-gate
12020Sstevel@tonic-gate /*ARGSUSED*/
12030Sstevel@tonic-gate int
px_lib_msi_setstate(dev_info_t * dip,msinum_t msi_num,pci_msi_state_t msi_state)12040Sstevel@tonic-gate px_lib_msi_setstate(dev_info_t *dip, msinum_t msi_num,
12050Sstevel@tonic-gate pci_msi_state_t msi_state)
12060Sstevel@tonic-gate {
12070Sstevel@tonic-gate uint64_t ret;
12080Sstevel@tonic-gate
12090Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msi_setstate: dip 0x%p msi_num 0x%x "
12100Sstevel@tonic-gate "msi_state 0x%x\n", dip, msi_num, msi_state);
12110Sstevel@tonic-gate
12120Sstevel@tonic-gate if ((ret = hvio_msi_setstate(DIP_TO_HANDLE(dip),
12130Sstevel@tonic-gate msi_num, msi_state)) != H_EOK) {
12140Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip,
12150Sstevel@tonic-gate "hvio_msi_setstate failed, ret 0x%lx\n", ret);
12160Sstevel@tonic-gate return (DDI_FAILURE);
12170Sstevel@tonic-gate }
12180Sstevel@tonic-gate
12190Sstevel@tonic-gate return (DDI_SUCCESS);
12200Sstevel@tonic-gate }
12210Sstevel@tonic-gate
12220Sstevel@tonic-gate /*
12230Sstevel@tonic-gate * MSG Functions:
12240Sstevel@tonic-gate */
12250Sstevel@tonic-gate /*ARGSUSED*/
12260Sstevel@tonic-gate int
px_lib_msg_getmsiq(dev_info_t * dip,pcie_msg_type_t msg_type,msiqid_t * msiq_id)12270Sstevel@tonic-gate px_lib_msg_getmsiq(dev_info_t *dip, pcie_msg_type_t msg_type,
12280Sstevel@tonic-gate msiqid_t *msiq_id)
12290Sstevel@tonic-gate {
12300Sstevel@tonic-gate uint64_t ret;
12310Sstevel@tonic-gate
12320Sstevel@tonic-gate DBG(DBG_LIB_MSG, dip, "px_lib_msg_getmsiq: dip 0x%p msg_type 0x%x\n",
12330Sstevel@tonic-gate dip, msg_type);
12340Sstevel@tonic-gate
12350Sstevel@tonic-gate if ((ret = hvio_msg_getmsiq(DIP_TO_HANDLE(dip),
12360Sstevel@tonic-gate msg_type, msiq_id)) != H_EOK) {
12370Sstevel@tonic-gate DBG(DBG_LIB_MSG, dip,
12380Sstevel@tonic-gate "hvio_msg_getmsiq failed, ret 0x%lx\n", ret);
12390Sstevel@tonic-gate return (DDI_FAILURE);
12400Sstevel@tonic-gate }
12410Sstevel@tonic-gate
12420Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msg_getmsiq: msiq_id 0x%x\n",
12430Sstevel@tonic-gate *msiq_id);
12440Sstevel@tonic-gate
12450Sstevel@tonic-gate return (DDI_SUCCESS);
12460Sstevel@tonic-gate }
12470Sstevel@tonic-gate
12480Sstevel@tonic-gate /*ARGSUSED*/
12490Sstevel@tonic-gate int
px_lib_msg_setmsiq(dev_info_t * dip,pcie_msg_type_t msg_type,msiqid_t msiq_id)12500Sstevel@tonic-gate px_lib_msg_setmsiq(dev_info_t *dip, pcie_msg_type_t msg_type,
12510Sstevel@tonic-gate msiqid_t msiq_id)
12520Sstevel@tonic-gate {
12530Sstevel@tonic-gate uint64_t ret;
12540Sstevel@tonic-gate
12550Sstevel@tonic-gate DBG(DBG_LIB_MSG, dip, "px_lib_msi_setstate: dip 0x%p msg_type 0x%x "
12560Sstevel@tonic-gate "msiq_id 0x%x\n", dip, msg_type, msiq_id);
12570Sstevel@tonic-gate
12580Sstevel@tonic-gate if ((ret = hvio_msg_setmsiq(DIP_TO_HANDLE(dip),
12590Sstevel@tonic-gate msg_type, msiq_id)) != H_EOK) {
12600Sstevel@tonic-gate DBG(DBG_LIB_MSG, dip,
12610Sstevel@tonic-gate "hvio_msg_setmsiq failed, ret 0x%lx\n", ret);
12620Sstevel@tonic-gate return (DDI_FAILURE);
12630Sstevel@tonic-gate }
12640Sstevel@tonic-gate
12650Sstevel@tonic-gate return (DDI_SUCCESS);
12660Sstevel@tonic-gate }
12670Sstevel@tonic-gate
12680Sstevel@tonic-gate /*ARGSUSED*/
12690Sstevel@tonic-gate int
px_lib_msg_getvalid(dev_info_t * dip,pcie_msg_type_t msg_type,pcie_msg_valid_state_t * msg_valid_state)12700Sstevel@tonic-gate px_lib_msg_getvalid(dev_info_t *dip, pcie_msg_type_t msg_type,
12710Sstevel@tonic-gate pcie_msg_valid_state_t *msg_valid_state)
12720Sstevel@tonic-gate {
12730Sstevel@tonic-gate uint64_t ret;
12740Sstevel@tonic-gate
12750Sstevel@tonic-gate DBG(DBG_LIB_MSG, dip, "px_lib_msg_getvalid: dip 0x%p msg_type 0x%x\n",
12760Sstevel@tonic-gate dip, msg_type);
12770Sstevel@tonic-gate
12780Sstevel@tonic-gate if ((ret = hvio_msg_getvalid(DIP_TO_HANDLE(dip), msg_type,
12790Sstevel@tonic-gate msg_valid_state)) != H_EOK) {
12800Sstevel@tonic-gate DBG(DBG_LIB_MSG, dip,
12810Sstevel@tonic-gate "hvio_msg_getvalid failed, ret 0x%lx\n", ret);
12820Sstevel@tonic-gate return (DDI_FAILURE);
12830Sstevel@tonic-gate }
12840Sstevel@tonic-gate
12850Sstevel@tonic-gate DBG(DBG_LIB_MSI, dip, "px_lib_msg_getvalid: msg_valid_state 0x%x\n",
12860Sstevel@tonic-gate *msg_valid_state);
12870Sstevel@tonic-gate
12880Sstevel@tonic-gate return (DDI_SUCCESS);
12890Sstevel@tonic-gate }
12900Sstevel@tonic-gate
12910Sstevel@tonic-gate /*ARGSUSED*/
12920Sstevel@tonic-gate int
px_lib_msg_setvalid(dev_info_t * dip,pcie_msg_type_t msg_type,pcie_msg_valid_state_t msg_valid_state)12930Sstevel@tonic-gate px_lib_msg_setvalid(dev_info_t *dip, pcie_msg_type_t msg_type,
12940Sstevel@tonic-gate pcie_msg_valid_state_t msg_valid_state)
12950Sstevel@tonic-gate {
12960Sstevel@tonic-gate uint64_t ret;
12970Sstevel@tonic-gate
12980Sstevel@tonic-gate DBG(DBG_LIB_MSG, dip, "px_lib_msg_setvalid: dip 0x%p msg_type 0x%x "
12990Sstevel@tonic-gate "msg_valid_state 0x%x\n", dip, msg_type, msg_valid_state);
13000Sstevel@tonic-gate
13010Sstevel@tonic-gate if ((ret = hvio_msg_setvalid(DIP_TO_HANDLE(dip), msg_type,
13020Sstevel@tonic-gate msg_valid_state)) != H_EOK) {
13030Sstevel@tonic-gate DBG(DBG_LIB_MSG, dip,
13040Sstevel@tonic-gate "hvio_msg_setvalid failed, ret 0x%lx\n", ret);
13050Sstevel@tonic-gate return (DDI_FAILURE);
13060Sstevel@tonic-gate }
13070Sstevel@tonic-gate
13080Sstevel@tonic-gate return (DDI_SUCCESS);
13090Sstevel@tonic-gate }
13100Sstevel@tonic-gate
131111596SJason.Beloro@Sun.COM /*ARGSUSED*/
131211596SJason.Beloro@Sun.COM void
px_panic_domain(px_t * px_p,pcie_req_id_t bdf)131311596SJason.Beloro@Sun.COM px_panic_domain(px_t *px_p, pcie_req_id_t bdf)
131411596SJason.Beloro@Sun.COM {
131511596SJason.Beloro@Sun.COM }
131611596SJason.Beloro@Sun.COM
13170Sstevel@tonic-gate /*
13180Sstevel@tonic-gate * Suspend/Resume Functions:
13190Sstevel@tonic-gate * Currently unsupported by hypervisor
13200Sstevel@tonic-gate */
13210Sstevel@tonic-gate int
px_lib_suspend(dev_info_t * dip)13220Sstevel@tonic-gate px_lib_suspend(dev_info_t *dip)
13230Sstevel@tonic-gate {
13240Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
13250Sstevel@tonic-gate pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
13261648Sjchu px_cb_t *cb_p = PX2CB(px_p);
13270Sstevel@tonic-gate devhandle_t dev_hdl, xbus_dev_hdl;
13281648Sjchu uint64_t ret = H_EOK;
13290Sstevel@tonic-gate
13300Sstevel@tonic-gate DBG(DBG_DETACH, dip, "px_lib_suspend: dip 0x%p\n", dip);
13310Sstevel@tonic-gate
133227Sjchu dev_hdl = (devhandle_t)pxu_p->px_address[PX_REG_CSR];
133327Sjchu xbus_dev_hdl = (devhandle_t)pxu_p->px_address[PX_REG_XBC];
13340Sstevel@tonic-gate
13351648Sjchu if ((ret = hvio_suspend(dev_hdl, pxu_p)) != H_EOK)
13361648Sjchu goto fail;
13371648Sjchu
13381648Sjchu if (--cb_p->attachcnt == 0) {
13391648Sjchu ret = hvio_cb_suspend(xbus_dev_hdl, pxu_p);
13401648Sjchu if (ret != H_EOK)
13411648Sjchu cb_p->attachcnt++;
13420Sstevel@tonic-gate }
13433274Set142600 pxu_p->cpr_flag = PX_ENTERED_CPR;
13440Sstevel@tonic-gate
13451648Sjchu fail:
13460Sstevel@tonic-gate return ((ret != H_EOK) ? DDI_FAILURE: DDI_SUCCESS);
13470Sstevel@tonic-gate }
13480Sstevel@tonic-gate
13490Sstevel@tonic-gate void
px_lib_resume(dev_info_t * dip)13500Sstevel@tonic-gate px_lib_resume(dev_info_t *dip)
13510Sstevel@tonic-gate {
13520Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
13530Sstevel@tonic-gate pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
13541648Sjchu px_cb_t *cb_p = PX2CB(px_p);
13550Sstevel@tonic-gate devhandle_t dev_hdl, xbus_dev_hdl;
13560Sstevel@tonic-gate devino_t pec_ino = px_p->px_inos[PX_INTR_PEC];
13570Sstevel@tonic-gate devino_t xbc_ino = px_p->px_inos[PX_INTR_XBC];
13580Sstevel@tonic-gate
13590Sstevel@tonic-gate DBG(DBG_ATTACH, dip, "px_lib_resume: dip 0x%p\n", dip);
13600Sstevel@tonic-gate
136127Sjchu dev_hdl = (devhandle_t)pxu_p->px_address[PX_REG_CSR];
136227Sjchu xbus_dev_hdl = (devhandle_t)pxu_p->px_address[PX_REG_XBC];
13630Sstevel@tonic-gate
13641648Sjchu if (++cb_p->attachcnt == 1)
13650Sstevel@tonic-gate hvio_cb_resume(dev_hdl, xbus_dev_hdl, xbc_ino, pxu_p);
13660Sstevel@tonic-gate
13671648Sjchu hvio_resume(dev_hdl, pec_ino, pxu_p);
13680Sstevel@tonic-gate }
13690Sstevel@tonic-gate
13701772Sjl139090 /*
13711772Sjl139090 * Generate a unique Oberon UBC ID based on the Logicial System Board and
13721772Sjl139090 * the IO Channel from the portid property field.
13731772Sjl139090 */
13741772Sjl139090 static uint64_t
oberon_get_ubc_id(dev_info_t * dip)13751772Sjl139090 oberon_get_ubc_id(dev_info_t *dip)
13761772Sjl139090 {
13771772Sjl139090 px_t *px_p = DIP_TO_STATE(dip);
13781772Sjl139090 pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
13791772Sjl139090 uint64_t ubc_id;
13801772Sjl139090
13811772Sjl139090 /*
13821772Sjl139090 * Generate a unique 6 bit UBC ID using the 2 IO_Channel#[1:0] bits and
13831772Sjl139090 * the 4 LSB_ID[3:0] bits from the Oberon's portid property.
13841772Sjl139090 */
13851772Sjl139090 ubc_id = (((pxu_p->portid >> OBERON_PORT_ID_IOC) &
13861772Sjl139090 OBERON_PORT_ID_IOC_MASK) | (((pxu_p->portid >>
13871772Sjl139090 OBERON_PORT_ID_LSB) & OBERON_PORT_ID_LSB_MASK)
13881772Sjl139090 << OBERON_UBC_ID_LSB));
13891772Sjl139090
13901772Sjl139090 return (ubc_id);
13911772Sjl139090 }
13921772Sjl139090
13931772Sjl139090 /*
13941772Sjl139090 * Oberon does not have a UBC scratch register, so alloc an array of scratch
13951772Sjl139090 * registers when needed and use a unique UBC ID as an index. This code
13961772Sjl139090 * can be simplified if we use a pre-allocated array. They are currently
13971772Sjl139090 * being dynamically allocated because it's only needed by the Oberon.
13981772Sjl139090 */
13991772Sjl139090 static void
oberon_set_cb(dev_info_t * dip,uint64_t val)14001772Sjl139090 oberon_set_cb(dev_info_t *dip, uint64_t val)
14011772Sjl139090 {
14021772Sjl139090 uint64_t ubc_id;
14031772Sjl139090
14041772Sjl139090 if (px_oberon_ubc_scratch_regs == NULL)
14051772Sjl139090 px_oberon_ubc_scratch_regs =
14061772Sjl139090 (uint64_t *)kmem_zalloc(sizeof (uint64_t)*
14071772Sjl139090 OBERON_UBC_ID_MAX, KM_SLEEP);
14081772Sjl139090
14091772Sjl139090 ubc_id = oberon_get_ubc_id(dip);
14101772Sjl139090
14111772Sjl139090 px_oberon_ubc_scratch_regs[ubc_id] = val;
14121772Sjl139090
14131772Sjl139090 /*
14141772Sjl139090 * Check if any scratch registers are still in use. If all scratch
14151772Sjl139090 * registers are currently set to zero, then deallocate the scratch
14161772Sjl139090 * register array.
14171772Sjl139090 */
14181772Sjl139090 for (ubc_id = 0; ubc_id < OBERON_UBC_ID_MAX; ubc_id++) {
14191772Sjl139090 if (px_oberon_ubc_scratch_regs[ubc_id] != NULL)
14201772Sjl139090 return;
14211772Sjl139090 }
14221772Sjl139090
14231772Sjl139090 /*
14241772Sjl139090 * All scratch registers are set to zero so deallocate the scratch
14251772Sjl139090 * register array and set the pointer to NULL.
14261772Sjl139090 */
14271772Sjl139090 kmem_free(px_oberon_ubc_scratch_regs,
14281772Sjl139090 (sizeof (uint64_t)*OBERON_UBC_ID_MAX));
14291772Sjl139090
14301772Sjl139090 px_oberon_ubc_scratch_regs = NULL;
14311772Sjl139090 }
14321772Sjl139090
14331772Sjl139090 /*
14341772Sjl139090 * Oberon does not have a UBC scratch register, so use an allocated array of
14351772Sjl139090 * scratch registers and use the unique UBC ID as an index into that array.
14361772Sjl139090 */
14371772Sjl139090 static uint64_t
oberon_get_cb(dev_info_t * dip)14381772Sjl139090 oberon_get_cb(dev_info_t *dip)
14391772Sjl139090 {
14401772Sjl139090 uint64_t ubc_id;
14411772Sjl139090
14421772Sjl139090 if (px_oberon_ubc_scratch_regs == NULL)
14431772Sjl139090 return (0);
14441772Sjl139090
14451772Sjl139090 ubc_id = oberon_get_ubc_id(dip);
14461772Sjl139090
14471772Sjl139090 return (px_oberon_ubc_scratch_regs[ubc_id]);
14481772Sjl139090 }
14491772Sjl139090
14501772Sjl139090 /*
14511772Sjl139090 * Misc Functions:
14521772Sjl139090 * Currently unsupported by hypervisor
14531772Sjl139090 */
14541772Sjl139090 static uint64_t
px_get_cb(dev_info_t * dip)14551772Sjl139090 px_get_cb(dev_info_t *dip)
14561772Sjl139090 {
14571772Sjl139090 px_t *px_p = DIP_TO_STATE(dip);
14581772Sjl139090 pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
14591772Sjl139090
14601772Sjl139090 /*
14611772Sjl139090 * Oberon does not currently have Scratchpad registers.
14621772Sjl139090 */
14631772Sjl139090 if (PX_CHIP_TYPE(pxu_p) == PX_CHIP_OBERON)
14641772Sjl139090 return (oberon_get_cb(dip));
14651772Sjl139090
14661772Sjl139090 return (CSR_XR((caddr_t)pxu_p->px_address[PX_REG_XBC], JBUS_SCRATCH_1));
14671772Sjl139090 }
14681772Sjl139090
14691772Sjl139090 static void
px_set_cb(dev_info_t * dip,uint64_t val)14701772Sjl139090 px_set_cb(dev_info_t *dip, uint64_t val)
14711772Sjl139090 {
14721772Sjl139090 px_t *px_p = DIP_TO_STATE(dip);
14731772Sjl139090 pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
14741772Sjl139090
14751772Sjl139090 /*
14761772Sjl139090 * Oberon does not currently have Scratchpad registers.
14771772Sjl139090 */
14781772Sjl139090 if (PX_CHIP_TYPE(pxu_p) == PX_CHIP_OBERON) {
14791772Sjl139090 oberon_set_cb(dip, val);
14801772Sjl139090 return;
14811772Sjl139090 }
14821772Sjl139090
14831772Sjl139090 CSR_XS((caddr_t)pxu_p->px_address[PX_REG_XBC], JBUS_SCRATCH_1, val);
14841772Sjl139090 }
14851772Sjl139090
14860Sstevel@tonic-gate /*ARGSUSED*/
14870Sstevel@tonic-gate int
px_lib_map_vconfig(dev_info_t * dip,ddi_map_req_t * mp,pci_config_offset_t off,pci_regspec_t * rp,caddr_t * addrp)14880Sstevel@tonic-gate px_lib_map_vconfig(dev_info_t *dip,
14890Sstevel@tonic-gate ddi_map_req_t *mp, pci_config_offset_t off,
14900Sstevel@tonic-gate pci_regspec_t *rp, caddr_t *addrp)
14910Sstevel@tonic-gate {
14920Sstevel@tonic-gate /*
14930Sstevel@tonic-gate * No special config space access services in this layer.
14940Sstevel@tonic-gate */
14950Sstevel@tonic-gate return (DDI_FAILURE);
14960Sstevel@tonic-gate }
14970Sstevel@tonic-gate
1498624Sschwartz void
px_lib_map_attr_check(ddi_map_req_t * mp)1499677Sjchu px_lib_map_attr_check(ddi_map_req_t *mp)
1500677Sjchu {
1501677Sjchu ddi_acc_hdl_t *hp = mp->map_handlep;
1502677Sjchu
1503677Sjchu /* fire does not accept byte masks from PIO store merge */
1504677Sjchu if (hp->ah_acc.devacc_attr_dataorder == DDI_STORECACHING_OK_ACC)
1505677Sjchu hp->ah_acc.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
1506677Sjchu }
1507677Sjchu
15083274Set142600 /* This function is called only by poke, caut put and pxtool poke. */
1509677Sjchu void
px_lib_clr_errs(px_t * px_p,dev_info_t * rdip,uint64_t addr)15103274Set142600 px_lib_clr_errs(px_t *px_p, dev_info_t *rdip, uint64_t addr)
151127Sjchu {
1512624Sschwartz px_pec_t *pec_p = px_p->px_pec_p;
151327Sjchu dev_info_t *rpdip = px_p->px_dip;
15143274Set142600 int rc_err, fab_err, i;
151527Sjchu int acctype = pec_p->pec_safeacc_type;
151627Sjchu ddi_fm_error_t derr;
151710923SEvan.Yan@Sun.COM pci_ranges_t *ranges_p;
15183274Set142600 int range_len;
15193274Set142600 uint32_t addr_high, addr_low;
15209921SKrishna.Elango@Sun.COM pcie_req_id_t bdf = PCIE_INVALID_BDF;
152127Sjchu
152227Sjchu /* Create the derr */
152327Sjchu bzero(&derr, sizeof (ddi_fm_error_t));
152427Sjchu derr.fme_version = DDI_FME_VERSION;
152527Sjchu derr.fme_ena = fm_ena_generate(0, FM_ENA_FMT1);
152627Sjchu derr.fme_flag = acctype;
152727Sjchu
152827Sjchu if (acctype == DDI_FM_ERR_EXPECTED) {
152927Sjchu derr.fme_status = DDI_FM_NONFATAL;
153027Sjchu ndi_fm_acc_err_set(pec_p->pec_acc_hdl, &derr);
153127Sjchu }
153227Sjchu
15336313Skrishnae if (px_fm_enter(px_p) != DDI_SUCCESS)
15346313Skrishnae return;
153527Sjchu
153627Sjchu /* send ereport/handle/clear fire registers */
15373274Set142600 rc_err = px_err_cmn_intr(px_p, &derr, PX_LIB_CALL, PX_FM_BLOCK_ALL);
15383274Set142600
15393274Set142600 /* Figure out if this is a cfg or mem32 access */
15403274Set142600 addr_high = (uint32_t)(addr >> 32);
15413274Set142600 addr_low = (uint32_t)addr;
154210923SEvan.Yan@Sun.COM range_len = px_p->px_ranges_length / sizeof (pci_ranges_t);
15433274Set142600 i = 0;
15443274Set142600 for (ranges_p = px_p->px_ranges_p; i < range_len; i++, ranges_p++) {
15453274Set142600 if (ranges_p->parent_high == addr_high) {
15463274Set142600 switch (ranges_p->child_high & PCI_ADDR_MASK) {
15473274Set142600 case PCI_ADDR_CONFIG:
15483274Set142600 bdf = (pcie_req_id_t)(addr_low >> 12);
15493274Set142600 addr_low = 0;
15503274Set142600 break;
15513274Set142600 case PCI_ADDR_MEM32:
15523274Set142600 if (rdip)
15536313Skrishnae bdf = PCI_GET_BDF(rdip);
15543274Set142600 else
15559921SKrishna.Elango@Sun.COM bdf = PCIE_INVALID_BDF;
15563274Set142600 break;
15573274Set142600 }
15583274Set142600 break;
15593274Set142600 }
15603274Set142600 }
15613274Set142600
156211596SJason.Beloro@Sun.COM (void) px_rp_en_q(px_p, bdf, addr_low, NULL);
15633274Set142600
15643274Set142600 /*
15653274Set142600 * XXX - Current code scans the fabric for all px_tool accesses.
15663274Set142600 * In future, do not scan fabric for px_tool access to IO Root Nexus
15673274Set142600 */
15686313Skrishnae fab_err = px_scan_fabric(px_p, rpdip, &derr);
15696313Skrishnae
15706313Skrishnae px_err_panic(rc_err, PX_RC, fab_err, B_TRUE);
15716313Skrishnae px_fm_exit(px_p);
15726313Skrishnae px_err_panic(rc_err, PX_RC, fab_err, B_FALSE);
157327Sjchu }
157427Sjchu
15750Sstevel@tonic-gate #ifdef DEBUG
15760Sstevel@tonic-gate int px_peekfault_cnt = 0;
15770Sstevel@tonic-gate int px_pokefault_cnt = 0;
15780Sstevel@tonic-gate #endif /* DEBUG */
15790Sstevel@tonic-gate
15800Sstevel@tonic-gate /*ARGSUSED*/
15810Sstevel@tonic-gate static int
px_lib_do_poke(dev_info_t * dip,dev_info_t * rdip,peekpoke_ctlops_t * in_args)15820Sstevel@tonic-gate px_lib_do_poke(dev_info_t *dip, dev_info_t *rdip,
15830Sstevel@tonic-gate peekpoke_ctlops_t *in_args)
15840Sstevel@tonic-gate {
15850Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
15860Sstevel@tonic-gate px_pec_t *pec_p = px_p->px_pec_p;
15870Sstevel@tonic-gate int err = DDI_SUCCESS;
15880Sstevel@tonic-gate on_trap_data_t otd;
15890Sstevel@tonic-gate
15900Sstevel@tonic-gate mutex_enter(&pec_p->pec_pokefault_mutex);
15910Sstevel@tonic-gate pec_p->pec_ontrap_data = &otd;
159227Sjchu pec_p->pec_safeacc_type = DDI_FM_ERR_POKE;
15930Sstevel@tonic-gate
15940Sstevel@tonic-gate /* Set up protected environment. */
15950Sstevel@tonic-gate if (!on_trap(&otd, OT_DATA_ACCESS)) {
15960Sstevel@tonic-gate uintptr_t tramp = otd.ot_trampoline;
15970Sstevel@tonic-gate
15980Sstevel@tonic-gate otd.ot_trampoline = (uintptr_t)&poke_fault;
15990Sstevel@tonic-gate err = do_poke(in_args->size, (void *)in_args->dev_addr,
16000Sstevel@tonic-gate (void *)in_args->host_addr);
16010Sstevel@tonic-gate otd.ot_trampoline = tramp;
16020Sstevel@tonic-gate } else
16030Sstevel@tonic-gate err = DDI_FAILURE;
16040Sstevel@tonic-gate
16053274Set142600 px_lib_clr_errs(px_p, rdip, in_args->dev_addr);
160627Sjchu
16070Sstevel@tonic-gate if (otd.ot_trap & OT_DATA_ACCESS)
16080Sstevel@tonic-gate err = DDI_FAILURE;
16090Sstevel@tonic-gate
16100Sstevel@tonic-gate /* Take down protected environment. */
16110Sstevel@tonic-gate no_trap();
16120Sstevel@tonic-gate
16130Sstevel@tonic-gate pec_p->pec_ontrap_data = NULL;
161427Sjchu pec_p->pec_safeacc_type = DDI_FM_ERR_UNEXPECTED;
16150Sstevel@tonic-gate mutex_exit(&pec_p->pec_pokefault_mutex);
16160Sstevel@tonic-gate
16170Sstevel@tonic-gate #ifdef DEBUG
16180Sstevel@tonic-gate if (err == DDI_FAILURE)
16190Sstevel@tonic-gate px_pokefault_cnt++;
16200Sstevel@tonic-gate #endif
16210Sstevel@tonic-gate return (err);
16220Sstevel@tonic-gate }
16230Sstevel@tonic-gate
16240Sstevel@tonic-gate /*ARGSUSED*/
16250Sstevel@tonic-gate static int
px_lib_do_caut_put(dev_info_t * dip,dev_info_t * rdip,peekpoke_ctlops_t * cautacc_ctlops_arg)16260Sstevel@tonic-gate px_lib_do_caut_put(dev_info_t *dip, dev_info_t *rdip,
16270Sstevel@tonic-gate peekpoke_ctlops_t *cautacc_ctlops_arg)
16280Sstevel@tonic-gate {
16290Sstevel@tonic-gate size_t size = cautacc_ctlops_arg->size;
16300Sstevel@tonic-gate uintptr_t dev_addr = cautacc_ctlops_arg->dev_addr;
16310Sstevel@tonic-gate uintptr_t host_addr = cautacc_ctlops_arg->host_addr;
16320Sstevel@tonic-gate ddi_acc_impl_t *hp = (ddi_acc_impl_t *)cautacc_ctlops_arg->handle;
16330Sstevel@tonic-gate size_t repcount = cautacc_ctlops_arg->repcount;
16340Sstevel@tonic-gate uint_t flags = cautacc_ctlops_arg->flags;
16350Sstevel@tonic-gate
16360Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
16370Sstevel@tonic-gate px_pec_t *pec_p = px_p->px_pec_p;
16380Sstevel@tonic-gate int err = DDI_SUCCESS;
16390Sstevel@tonic-gate
164027Sjchu /*
164127Sjchu * Note that i_ndi_busop_access_enter ends up grabbing the pokefault
164227Sjchu * mutex.
164327Sjchu */
16440Sstevel@tonic-gate i_ndi_busop_access_enter(hp->ahi_common.ah_dip, (ddi_acc_handle_t)hp);
16450Sstevel@tonic-gate
164627Sjchu pec_p->pec_ontrap_data = (on_trap_data_t *)hp->ahi_err->err_ontrap;
164727Sjchu pec_p->pec_safeacc_type = DDI_FM_ERR_EXPECTED;
164827Sjchu hp->ahi_err->err_expected = DDI_FM_ERR_EXPECTED;
16490Sstevel@tonic-gate
16500Sstevel@tonic-gate if (!i_ddi_ontrap((ddi_acc_handle_t)hp)) {
16510Sstevel@tonic-gate for (; repcount; repcount--) {
16520Sstevel@tonic-gate switch (size) {
16530Sstevel@tonic-gate
16540Sstevel@tonic-gate case sizeof (uint8_t):
16550Sstevel@tonic-gate i_ddi_put8(hp, (uint8_t *)dev_addr,
16560Sstevel@tonic-gate *(uint8_t *)host_addr);
16570Sstevel@tonic-gate break;
16580Sstevel@tonic-gate
16590Sstevel@tonic-gate case sizeof (uint16_t):
16600Sstevel@tonic-gate i_ddi_put16(hp, (uint16_t *)dev_addr,
16610Sstevel@tonic-gate *(uint16_t *)host_addr);
16620Sstevel@tonic-gate break;
16630Sstevel@tonic-gate
16640Sstevel@tonic-gate case sizeof (uint32_t):
16650Sstevel@tonic-gate i_ddi_put32(hp, (uint32_t *)dev_addr,
16660Sstevel@tonic-gate *(uint32_t *)host_addr);
16670Sstevel@tonic-gate break;
16680Sstevel@tonic-gate
16690Sstevel@tonic-gate case sizeof (uint64_t):
16700Sstevel@tonic-gate i_ddi_put64(hp, (uint64_t *)dev_addr,
16710Sstevel@tonic-gate *(uint64_t *)host_addr);
16720Sstevel@tonic-gate break;
16730Sstevel@tonic-gate }
16740Sstevel@tonic-gate
16750Sstevel@tonic-gate host_addr += size;
16760Sstevel@tonic-gate
16770Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR)
16780Sstevel@tonic-gate dev_addr += size;
16790Sstevel@tonic-gate
16803274Set142600 px_lib_clr_errs(px_p, rdip, dev_addr);
168127Sjchu
16820Sstevel@tonic-gate if (pec_p->pec_ontrap_data->ot_trap & OT_DATA_ACCESS) {
16830Sstevel@tonic-gate err = DDI_FAILURE;
16840Sstevel@tonic-gate #ifdef DEBUG
16850Sstevel@tonic-gate px_pokefault_cnt++;
16860Sstevel@tonic-gate #endif
16870Sstevel@tonic-gate break;
16880Sstevel@tonic-gate }
16890Sstevel@tonic-gate }
16900Sstevel@tonic-gate }
16910Sstevel@tonic-gate
16920Sstevel@tonic-gate i_ddi_notrap((ddi_acc_handle_t)hp);
16930Sstevel@tonic-gate pec_p->pec_ontrap_data = NULL;
169427Sjchu pec_p->pec_safeacc_type = DDI_FM_ERR_UNEXPECTED;
16950Sstevel@tonic-gate i_ndi_busop_access_exit(hp->ahi_common.ah_dip, (ddi_acc_handle_t)hp);
16960Sstevel@tonic-gate hp->ahi_err->err_expected = DDI_FM_ERR_UNEXPECTED;
16970Sstevel@tonic-gate
16980Sstevel@tonic-gate return (err);
16990Sstevel@tonic-gate }
17000Sstevel@tonic-gate
17010Sstevel@tonic-gate
17020Sstevel@tonic-gate int
px_lib_ctlops_poke(dev_info_t * dip,dev_info_t * rdip,peekpoke_ctlops_t * in_args)17030Sstevel@tonic-gate px_lib_ctlops_poke(dev_info_t *dip, dev_info_t *rdip,
17040Sstevel@tonic-gate peekpoke_ctlops_t *in_args)
17050Sstevel@tonic-gate {
17060Sstevel@tonic-gate return (in_args->handle ? px_lib_do_caut_put(dip, rdip, in_args) :
17070Sstevel@tonic-gate px_lib_do_poke(dip, rdip, in_args));
17080Sstevel@tonic-gate }
17090Sstevel@tonic-gate
17100Sstevel@tonic-gate
17110Sstevel@tonic-gate /*ARGSUSED*/
17120Sstevel@tonic-gate static int
px_lib_do_peek(dev_info_t * dip,peekpoke_ctlops_t * in_args)17130Sstevel@tonic-gate px_lib_do_peek(dev_info_t *dip, peekpoke_ctlops_t *in_args)
17140Sstevel@tonic-gate {
171527Sjchu px_t *px_p = DIP_TO_STATE(dip);
171627Sjchu px_pec_t *pec_p = px_p->px_pec_p;
17170Sstevel@tonic-gate int err = DDI_SUCCESS;
17180Sstevel@tonic-gate on_trap_data_t otd;
17190Sstevel@tonic-gate
172027Sjchu mutex_enter(&pec_p->pec_pokefault_mutex);
172111596SJason.Beloro@Sun.COM if (px_fm_enter(px_p) != DDI_SUCCESS) {
172211596SJason.Beloro@Sun.COM mutex_exit(&pec_p->pec_pokefault_mutex);
17236313Skrishnae return (DDI_FAILURE);
172411596SJason.Beloro@Sun.COM }
172527Sjchu pec_p->pec_safeacc_type = DDI_FM_ERR_PEEK;
17266313Skrishnae px_fm_exit(px_p);
172727Sjchu
17280Sstevel@tonic-gate if (!on_trap(&otd, OT_DATA_ACCESS)) {
17290Sstevel@tonic-gate uintptr_t tramp = otd.ot_trampoline;
17300Sstevel@tonic-gate
17310Sstevel@tonic-gate otd.ot_trampoline = (uintptr_t)&peek_fault;
17320Sstevel@tonic-gate err = do_peek(in_args->size, (void *)in_args->dev_addr,
17330Sstevel@tonic-gate (void *)in_args->host_addr);
17340Sstevel@tonic-gate otd.ot_trampoline = tramp;
17350Sstevel@tonic-gate } else
17360Sstevel@tonic-gate err = DDI_FAILURE;
17370Sstevel@tonic-gate
17380Sstevel@tonic-gate no_trap();
173927Sjchu pec_p->pec_safeacc_type = DDI_FM_ERR_UNEXPECTED;
174027Sjchu mutex_exit(&pec_p->pec_pokefault_mutex);
17410Sstevel@tonic-gate
17420Sstevel@tonic-gate #ifdef DEBUG
17430Sstevel@tonic-gate if (err == DDI_FAILURE)
17440Sstevel@tonic-gate px_peekfault_cnt++;
17450Sstevel@tonic-gate #endif
17460Sstevel@tonic-gate return (err);
17470Sstevel@tonic-gate }
17480Sstevel@tonic-gate
17490Sstevel@tonic-gate
17500Sstevel@tonic-gate static int
px_lib_do_caut_get(dev_info_t * dip,peekpoke_ctlops_t * cautacc_ctlops_arg)17510Sstevel@tonic-gate px_lib_do_caut_get(dev_info_t *dip, peekpoke_ctlops_t *cautacc_ctlops_arg)
17520Sstevel@tonic-gate {
17530Sstevel@tonic-gate size_t size = cautacc_ctlops_arg->size;
17540Sstevel@tonic-gate uintptr_t dev_addr = cautacc_ctlops_arg->dev_addr;
17550Sstevel@tonic-gate uintptr_t host_addr = cautacc_ctlops_arg->host_addr;
17560Sstevel@tonic-gate ddi_acc_impl_t *hp = (ddi_acc_impl_t *)cautacc_ctlops_arg->handle;
17570Sstevel@tonic-gate size_t repcount = cautacc_ctlops_arg->repcount;
17580Sstevel@tonic-gate uint_t flags = cautacc_ctlops_arg->flags;
17590Sstevel@tonic-gate
17600Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
17610Sstevel@tonic-gate px_pec_t *pec_p = px_p->px_pec_p;
17620Sstevel@tonic-gate int err = DDI_SUCCESS;
17630Sstevel@tonic-gate
176427Sjchu /*
176527Sjchu * Note that i_ndi_busop_access_enter ends up grabbing the pokefault
176627Sjchu * mutex.
176727Sjchu */
176827Sjchu i_ndi_busop_access_enter(hp->ahi_common.ah_dip, (ddi_acc_handle_t)hp);
176927Sjchu
177027Sjchu pec_p->pec_ontrap_data = (on_trap_data_t *)hp->ahi_err->err_ontrap;
177127Sjchu pec_p->pec_safeacc_type = DDI_FM_ERR_EXPECTED;
17720Sstevel@tonic-gate hp->ahi_err->err_expected = DDI_FM_ERR_EXPECTED;
17730Sstevel@tonic-gate
17740Sstevel@tonic-gate if (repcount == 1) {
17750Sstevel@tonic-gate if (!i_ddi_ontrap((ddi_acc_handle_t)hp)) {
17760Sstevel@tonic-gate i_ddi_caut_get(size, (void *)dev_addr,
17770Sstevel@tonic-gate (void *)host_addr);
17780Sstevel@tonic-gate } else {
17790Sstevel@tonic-gate int i;
17800Sstevel@tonic-gate uint8_t *ff_addr = (uint8_t *)host_addr;
17810Sstevel@tonic-gate for (i = 0; i < size; i++)
17820Sstevel@tonic-gate *ff_addr++ = 0xff;
17830Sstevel@tonic-gate
17840Sstevel@tonic-gate err = DDI_FAILURE;
17850Sstevel@tonic-gate #ifdef DEBUG
17860Sstevel@tonic-gate px_peekfault_cnt++;
17870Sstevel@tonic-gate #endif
17880Sstevel@tonic-gate }
17890Sstevel@tonic-gate } else {
17900Sstevel@tonic-gate if (!i_ddi_ontrap((ddi_acc_handle_t)hp)) {
17910Sstevel@tonic-gate for (; repcount; repcount--) {
17920Sstevel@tonic-gate i_ddi_caut_get(size, (void *)dev_addr,
17930Sstevel@tonic-gate (void *)host_addr);
17940Sstevel@tonic-gate
17950Sstevel@tonic-gate host_addr += size;
17960Sstevel@tonic-gate
17970Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR)
17980Sstevel@tonic-gate dev_addr += size;
17990Sstevel@tonic-gate }
18000Sstevel@tonic-gate } else {
18010Sstevel@tonic-gate err = DDI_FAILURE;
18020Sstevel@tonic-gate #ifdef DEBUG
18030Sstevel@tonic-gate px_peekfault_cnt++;
18040Sstevel@tonic-gate #endif
18050Sstevel@tonic-gate }
18060Sstevel@tonic-gate }
18070Sstevel@tonic-gate
18080Sstevel@tonic-gate i_ddi_notrap((ddi_acc_handle_t)hp);
18090Sstevel@tonic-gate pec_p->pec_ontrap_data = NULL;
181027Sjchu pec_p->pec_safeacc_type = DDI_FM_ERR_UNEXPECTED;
18110Sstevel@tonic-gate i_ndi_busop_access_exit(hp->ahi_common.ah_dip, (ddi_acc_handle_t)hp);
18120Sstevel@tonic-gate hp->ahi_err->err_expected = DDI_FM_ERR_UNEXPECTED;
18130Sstevel@tonic-gate
18140Sstevel@tonic-gate return (err);
18150Sstevel@tonic-gate }
18160Sstevel@tonic-gate
18170Sstevel@tonic-gate /*ARGSUSED*/
18180Sstevel@tonic-gate int
px_lib_ctlops_peek(dev_info_t * dip,dev_info_t * rdip,peekpoke_ctlops_t * in_args,void * result)18190Sstevel@tonic-gate px_lib_ctlops_peek(dev_info_t *dip, dev_info_t *rdip,
18200Sstevel@tonic-gate peekpoke_ctlops_t *in_args, void *result)
18210Sstevel@tonic-gate {
18220Sstevel@tonic-gate result = (void *)in_args->host_addr;
18230Sstevel@tonic-gate return (in_args->handle ? px_lib_do_caut_get(dip, in_args) :
18240Sstevel@tonic-gate px_lib_do_peek(dip, in_args));
18250Sstevel@tonic-gate }
1826118Sjchu
18270Sstevel@tonic-gate /*
18280Sstevel@tonic-gate * implements PPM interface
18290Sstevel@tonic-gate */
18300Sstevel@tonic-gate int
px_lib_pmctl(int cmd,px_t * px_p)18310Sstevel@tonic-gate px_lib_pmctl(int cmd, px_t *px_p)
18320Sstevel@tonic-gate {
18330Sstevel@tonic-gate ASSERT((cmd & ~PPMREQ_MASK) == PPMREQ);
18340Sstevel@tonic-gate switch (cmd) {
18350Sstevel@tonic-gate case PPMREQ_PRE_PWR_OFF:
18360Sstevel@tonic-gate /*
18370Sstevel@tonic-gate * Currently there is no device power management for
18380Sstevel@tonic-gate * the root complex (fire). When there is we need to make
18390Sstevel@tonic-gate * sure that it is at full power before trying to send the
18400Sstevel@tonic-gate * PME_Turn_Off message.
18410Sstevel@tonic-gate */
18420Sstevel@tonic-gate DBG(DBG_PWR, px_p->px_dip,
18430Sstevel@tonic-gate "ioctl: request to send PME_Turn_Off\n");
18440Sstevel@tonic-gate return (px_goto_l23ready(px_p));
18450Sstevel@tonic-gate
18460Sstevel@tonic-gate case PPMREQ_PRE_PWR_ON:
1847118Sjchu DBG(DBG_PWR, px_p->px_dip, "ioctl: PRE_PWR_ON request\n");
1848118Sjchu return (px_pre_pwron_check(px_p));
1849118Sjchu
18500Sstevel@tonic-gate case PPMREQ_POST_PWR_ON:
1851118Sjchu DBG(DBG_PWR, px_p->px_dip, "ioctl: POST_PWR_ON request\n");
1852118Sjchu return (px_goto_l0(px_p));
18530Sstevel@tonic-gate
18540Sstevel@tonic-gate default:
18550Sstevel@tonic-gate return (DDI_FAILURE);
18560Sstevel@tonic-gate }
18570Sstevel@tonic-gate }
18580Sstevel@tonic-gate
18590Sstevel@tonic-gate /*
18600Sstevel@tonic-gate * sends PME_Turn_Off message to put the link in L2/L3 ready state.
18610Sstevel@tonic-gate * called by px_ioctl.
18620Sstevel@tonic-gate * returns DDI_SUCCESS or DDI_FAILURE
18630Sstevel@tonic-gate * 1. Wait for link to be in L1 state (link status reg)
18640Sstevel@tonic-gate * 2. write to PME_Turn_off reg to boradcast
18650Sstevel@tonic-gate * 3. set timeout
18660Sstevel@tonic-gate * 4. If timeout, return failure.
18670Sstevel@tonic-gate * 5. If PM_TO_Ack, wait till link is in L2/L3 ready
18680Sstevel@tonic-gate */
18690Sstevel@tonic-gate static int
px_goto_l23ready(px_t * px_p)18700Sstevel@tonic-gate px_goto_l23ready(px_t *px_p)
18710Sstevel@tonic-gate {
18720Sstevel@tonic-gate pcie_pwr_t *pwr_p;
187327Sjchu pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
187427Sjchu caddr_t csr_base = (caddr_t)pxu_p->px_address[PX_REG_CSR];
18750Sstevel@tonic-gate int ret = DDI_SUCCESS;
18760Sstevel@tonic-gate clock_t end, timeleft;
1877118Sjchu int mutex_held = 1;
18780Sstevel@tonic-gate
18790Sstevel@tonic-gate /* If no PM info, return failure */
18800Sstevel@tonic-gate if (!PCIE_PMINFO(px_p->px_dip) ||
18810Sstevel@tonic-gate !(pwr_p = PCIE_NEXUS_PMINFO(px_p->px_dip)))
18820Sstevel@tonic-gate return (DDI_FAILURE);
18830Sstevel@tonic-gate
18840Sstevel@tonic-gate mutex_enter(&pwr_p->pwr_lock);
1885118Sjchu mutex_enter(&px_p->px_l23ready_lock);
18860Sstevel@tonic-gate /* Clear the PME_To_ACK receieved flag */
1887118Sjchu px_p->px_pm_flags &= ~PX_PMETOACK_RECVD;
1888287Smg140465 /*
1889287Smg140465 * When P25 is the downstream device, after receiving
1890287Smg140465 * PME_To_ACK, fire will go to Detect state, which causes
1891287Smg140465 * the link down event. Inform FMA that this is expected.
1892287Smg140465 * In case of all other cards complaint with the pci express
1893287Smg140465 * spec, this will happen when the power is re-applied. FMA
1894287Smg140465 * code will clear this flag after one instance of LDN. Since
1895287Smg140465 * there will not be a LDN event for the spec compliant cards,
1896287Smg140465 * we need to clear the flag after receiving PME_To_ACK.
1897287Smg140465 */
1898287Smg140465 px_p->px_pm_flags |= PX_LDN_EXPECTED;
18990Sstevel@tonic-gate if (px_send_pme_turnoff(csr_base) != DDI_SUCCESS) {
19000Sstevel@tonic-gate ret = DDI_FAILURE;
19010Sstevel@tonic-gate goto l23ready_done;
19020Sstevel@tonic-gate }
1903118Sjchu px_p->px_pm_flags |= PX_PME_TURNOFF_PENDING;
19040Sstevel@tonic-gate
19050Sstevel@tonic-gate end = ddi_get_lbolt() + drv_usectohz(px_pme_to_ack_timeout);
1906118Sjchu while (!(px_p->px_pm_flags & PX_PMETOACK_RECVD)) {
1907118Sjchu timeleft = cv_timedwait(&px_p->px_l23ready_cv,
1908118Sjchu &px_p->px_l23ready_lock, end);
19090Sstevel@tonic-gate /*
19100Sstevel@tonic-gate * if cv_timedwait returns -1, it is either
19110Sstevel@tonic-gate * 1) timed out or
19120Sstevel@tonic-gate * 2) there was a pre-mature wakeup but by the time
19130Sstevel@tonic-gate * cv_timedwait is called again end < lbolt i.e.
19140Sstevel@tonic-gate * end is in the past.
19150Sstevel@tonic-gate * 3) By the time we make first cv_timedwait call,
19160Sstevel@tonic-gate * end < lbolt is true.
19170Sstevel@tonic-gate */
19180Sstevel@tonic-gate if (timeleft == -1)
19190Sstevel@tonic-gate break;
19200Sstevel@tonic-gate }
1921118Sjchu if (!(px_p->px_pm_flags & PX_PMETOACK_RECVD)) {
19220Sstevel@tonic-gate /*
19230Sstevel@tonic-gate * Either timedout or interrupt didn't get a
19240Sstevel@tonic-gate * chance to grab the mutex and set the flag.
19250Sstevel@tonic-gate * release the mutex and delay for sometime.
19260Sstevel@tonic-gate * This will 1) give a chance for interrupt to
19270Sstevel@tonic-gate * set the flag 2) creates a delay between two
19280Sstevel@tonic-gate * consequetive requests.
19290Sstevel@tonic-gate */
1930118Sjchu mutex_exit(&px_p->px_l23ready_lock);
19311147Sjchu delay(drv_usectohz(50 * PX_MSEC_TO_USEC));
1932118Sjchu mutex_held = 0;
1933118Sjchu if (!(px_p->px_pm_flags & PX_PMETOACK_RECVD)) {
19340Sstevel@tonic-gate ret = DDI_FAILURE;
19350Sstevel@tonic-gate DBG(DBG_PWR, px_p->px_dip, " Timed out while waiting"
19360Sstevel@tonic-gate " for PME_TO_ACK\n");
19370Sstevel@tonic-gate }
19380Sstevel@tonic-gate }
1939287Smg140465 px_p->px_pm_flags &=
1940287Smg140465 ~(PX_PME_TURNOFF_PENDING | PX_PMETOACK_RECVD | PX_LDN_EXPECTED);
19410Sstevel@tonic-gate
19420Sstevel@tonic-gate l23ready_done:
1943118Sjchu if (mutex_held)
1944118Sjchu mutex_exit(&px_p->px_l23ready_lock);
1945118Sjchu /*
1946118Sjchu * Wait till link is in L1 idle, if sending PME_Turn_Off
1947118Sjchu * was succesful.
1948118Sjchu */
1949118Sjchu if (ret == DDI_SUCCESS) {
1950118Sjchu if (px_link_wait4l1idle(csr_base) != DDI_SUCCESS) {
1951118Sjchu DBG(DBG_PWR, px_p->px_dip, " Link is not at L1"
1952287Smg140465 " even though we received PME_To_ACK.\n");
1953287Smg140465 /*
1954287Smg140465 * Workaround for hardware bug with P25.
1955287Smg140465 * Due to a hardware bug with P25, link state
1956287Smg140465 * will be Detect state rather than L1 after
1957287Smg140465 * link is transitioned to L23Ready state. Since
1958287Smg140465 * we don't know whether link is L23ready state
1959287Smg140465 * without Fire's state being L1_idle, we delay
1960287Smg140465 * here just to make sure that we wait till link
1961287Smg140465 * is transitioned to L23Ready state.
1962287Smg140465 */
19631147Sjchu delay(drv_usectohz(100 * PX_MSEC_TO_USEC));
1964287Smg140465 }
1965287Smg140465 pwr_p->pwr_link_lvl = PM_LEVEL_L3;
1966118Sjchu
1967118Sjchu }
19680Sstevel@tonic-gate mutex_exit(&pwr_p->pwr_lock);
19690Sstevel@tonic-gate return (ret);
19700Sstevel@tonic-gate }
19710Sstevel@tonic-gate
1972118Sjchu /*
1973118Sjchu * Message interrupt handler intended to be shared for both
1974118Sjchu * PME and PME_TO_ACK msg handling, currently only handles
1975118Sjchu * PME_To_ACK message.
1976118Sjchu */
1977118Sjchu uint_t
px_pmeq_intr(caddr_t arg)1978118Sjchu px_pmeq_intr(caddr_t arg)
1979118Sjchu {
1980118Sjchu px_t *px_p = (px_t *)arg;
1981118Sjchu
1982287Smg140465 DBG(DBG_PWR, px_p->px_dip, " PME_To_ACK received \n");
1983118Sjchu mutex_enter(&px_p->px_l23ready_lock);
1984118Sjchu cv_broadcast(&px_p->px_l23ready_cv);
1985118Sjchu if (px_p->px_pm_flags & PX_PME_TURNOFF_PENDING) {
1986118Sjchu px_p->px_pm_flags |= PX_PMETOACK_RECVD;
1987118Sjchu } else {
1988118Sjchu /*
1989118Sjchu * This maybe the second ack received. If so then,
1990118Sjchu * we should be receiving it during wait4L1 stage.
1991118Sjchu */
1992118Sjchu px_p->px_pmetoack_ignored++;
1993118Sjchu }
1994118Sjchu mutex_exit(&px_p->px_l23ready_lock);
1995118Sjchu return (DDI_INTR_CLAIMED);
1996118Sjchu }
1997118Sjchu
1998118Sjchu static int
px_pre_pwron_check(px_t * px_p)1999118Sjchu px_pre_pwron_check(px_t *px_p)
2000118Sjchu {
2001118Sjchu pcie_pwr_t *pwr_p;
2002118Sjchu
2003118Sjchu /* If no PM info, return failure */
2004118Sjchu if (!PCIE_PMINFO(px_p->px_dip) ||
2005118Sjchu !(pwr_p = PCIE_NEXUS_PMINFO(px_p->px_dip)))
2006118Sjchu return (DDI_FAILURE);
2007118Sjchu
2008287Smg140465 /*
2009287Smg140465 * For the spec compliant downstream cards link down
2010287Smg140465 * is expected when the device is powered on.
2011287Smg140465 */
2012287Smg140465 px_p->px_pm_flags |= PX_LDN_EXPECTED;
2013118Sjchu return (pwr_p->pwr_link_lvl == PM_LEVEL_L3 ? DDI_SUCCESS : DDI_FAILURE);
2014118Sjchu }
2015118Sjchu
2016118Sjchu static int
px_goto_l0(px_t * px_p)2017118Sjchu px_goto_l0(px_t *px_p)
2018118Sjchu {
2019118Sjchu pcie_pwr_t *pwr_p;
2020118Sjchu pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
2021118Sjchu caddr_t csr_base = (caddr_t)pxu_p->px_address[PX_REG_CSR];
2022118Sjchu int ret = DDI_SUCCESS;
20231147Sjchu uint64_t time_spent = 0;
2024118Sjchu
2025118Sjchu /* If no PM info, return failure */
2026118Sjchu if (!PCIE_PMINFO(px_p->px_dip) ||
2027118Sjchu !(pwr_p = PCIE_NEXUS_PMINFO(px_p->px_dip)))
2028118Sjchu return (DDI_FAILURE);
2029118Sjchu
2030118Sjchu mutex_enter(&pwr_p->pwr_lock);
2031287Smg140465 /*
20321147Sjchu * The following link retrain activity will cause LDN and LUP event.
20331147Sjchu * Receiving LDN prior to receiving LUP is expected, not an error in
20341147Sjchu * this case. Receiving LUP indicates link is fully up to support
20351147Sjchu * powering up down stream device, and of course any further LDN and
20361147Sjchu * LUP outside this context will be error.
2037287Smg140465 */
20381147Sjchu px_p->px_lup_pending = 1;
2039118Sjchu if (px_link_retrain(csr_base) != DDI_SUCCESS) {
2040118Sjchu ret = DDI_FAILURE;
2041118Sjchu goto l0_done;
2042118Sjchu }
2043118Sjchu
20441147Sjchu /* LUP event takes the order of 15ms amount of time to occur */
20451147Sjchu for (; px_p->px_lup_pending && (time_spent < px_lup_poll_to);
20461147Sjchu time_spent += px_lup_poll_interval)
20471147Sjchu drv_usecwait(px_lup_poll_interval);
20481147Sjchu if (px_p->px_lup_pending)
20491147Sjchu ret = DDI_FAILURE;
2050118Sjchu l0_done:
2051287Smg140465 px_enable_detect_quiet(csr_base);
2052118Sjchu if (ret == DDI_SUCCESS)
2053287Smg140465 pwr_p->pwr_link_lvl = PM_LEVEL_L0;
2054118Sjchu mutex_exit(&pwr_p->pwr_lock);
2055118Sjchu return (ret);
2056118Sjchu }
2057118Sjchu
20580Sstevel@tonic-gate /*
20590Sstevel@tonic-gate * Extract the drivers binding name to identify which chip we're binding to.
20600Sstevel@tonic-gate * Whenever a new bus bridge is created, the driver alias entry should be
20610Sstevel@tonic-gate * added here to identify the device if needed. If a device isn't added,
20620Sstevel@tonic-gate * the identity defaults to PX_CHIP_UNIDENTIFIED.
20630Sstevel@tonic-gate */
20640Sstevel@tonic-gate static uint32_t
px_identity_init(px_t * px_p)20652426Sschwartz px_identity_init(px_t *px_p)
20660Sstevel@tonic-gate {
20670Sstevel@tonic-gate dev_info_t *dip = px_p->px_dip;
20680Sstevel@tonic-gate char *name = ddi_binding_name(dip);
20690Sstevel@tonic-gate uint32_t revision = 0;
20700Sstevel@tonic-gate
20710Sstevel@tonic-gate revision = ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
20720Sstevel@tonic-gate "module-revision#", 0);
20730Sstevel@tonic-gate
20740Sstevel@tonic-gate /* Check for Fire driver binding name */
20752426Sschwartz if (strcmp(name, "pciex108e,80f0") == 0) {
20762426Sschwartz DBG(DBG_ATTACH, dip, "px_identity_init: %s%d: "
20772426Sschwartz "(FIRE), module-revision %d\n", NAMEINST(dip),
20782426Sschwartz revision);
20792426Sschwartz
20802426Sschwartz return ((revision >= FIRE_MOD_REV_20) ?
20812426Sschwartz PX_CHIP_FIRE : PX_CHIP_UNIDENTIFIED);
20820Sstevel@tonic-gate }
20830Sstevel@tonic-gate
20841772Sjl139090 /* Check for Oberon driver binding name */
20851772Sjl139090 if (strcmp(name, "pciex108e,80f8") == 0) {
20862426Sschwartz DBG(DBG_ATTACH, dip, "px_identity_init: %s%d: "
20872426Sschwartz "(OBERON), module-revision %d\n", NAMEINST(dip),
20882426Sschwartz revision);
20892426Sschwartz
20902426Sschwartz return (PX_CHIP_OBERON);
20911772Sjl139090 }
20921772Sjl139090
20930Sstevel@tonic-gate DBG(DBG_ATTACH, dip, "%s%d: Unknown PCI Express Host bridge %s %x\n",
20940Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), name, revision);
20950Sstevel@tonic-gate
20960Sstevel@tonic-gate return (PX_CHIP_UNIDENTIFIED);
20970Sstevel@tonic-gate }
209827Sjchu
209927Sjchu int
px_err_add_intr(px_fault_t * px_fault_p)210027Sjchu px_err_add_intr(px_fault_t *px_fault_p)
210127Sjchu {
210227Sjchu dev_info_t *dip = px_fault_p->px_fh_dip;
210327Sjchu px_t *px_p = DIP_TO_STATE(dip);
210427Sjchu
210527Sjchu VERIFY(add_ivintr(px_fault_p->px_fh_sysino, PX_ERR_PIL,
21062973Sgovinda (intrfunc)px_fault_p->px_err_func, (caddr_t)px_fault_p,
21072973Sgovinda NULL, NULL) == 0);
210827Sjchu
210927Sjchu px_ib_intr_enable(px_p, intr_dist_cpuid(), px_fault_p->px_intr_ino);
211027Sjchu
211127Sjchu return (DDI_SUCCESS);
211227Sjchu }
211327Sjchu
211427Sjchu void
px_err_rem_intr(px_fault_t * px_fault_p)211527Sjchu px_err_rem_intr(px_fault_t *px_fault_p)
211627Sjchu {
211727Sjchu dev_info_t *dip = px_fault_p->px_fh_dip;
211827Sjchu px_t *px_p = DIP_TO_STATE(dip);
211927Sjchu
212027Sjchu px_ib_intr_disable(px_p->px_ib_p, px_fault_p->px_intr_ino,
21216313Skrishnae IB_INTR_WAIT);
2122965Sgovinda
21232973Sgovinda VERIFY(rem_ivintr(px_fault_p->px_fh_sysino, PX_ERR_PIL) == 0);
212427Sjchu }
212527Sjchu
21261648Sjchu /*
21273623Sjchu * px_cb_intr_redist() - sun4u only, CB interrupt redistribution
21283623Sjchu */
21293623Sjchu void
px_cb_intr_redist(void * arg)21303623Sjchu px_cb_intr_redist(void *arg)
21313623Sjchu {
21323623Sjchu px_cb_t *cb_p = (px_cb_t *)arg;
21333623Sjchu px_cb_list_t *pxl;
21343623Sjchu px_t *pxp = NULL;
21353623Sjchu px_fault_t *f_p = NULL;
21363623Sjchu uint32_t new_cpuid;
21373623Sjchu intr_valid_state_t enabled = 0;
21383623Sjchu
21393623Sjchu mutex_enter(&cb_p->cb_mutex);
21403623Sjchu
21413623Sjchu pxl = cb_p->pxl;
21423623Sjchu if (!pxl)
21433623Sjchu goto cb_done;
21443623Sjchu
21453623Sjchu pxp = pxl->pxp;
21463623Sjchu f_p = &pxp->px_cb_fault;
21473623Sjchu for (; pxl && (f_p->px_fh_sysino != cb_p->sysino); ) {
21483623Sjchu pxl = pxl->next;
21493623Sjchu pxp = pxl->pxp;
21503623Sjchu f_p = &pxp->px_cb_fault;
21513623Sjchu }
21523623Sjchu if (pxl == NULL)
21533623Sjchu goto cb_done;
21543623Sjchu
21553623Sjchu new_cpuid = intr_dist_cpuid();
21563623Sjchu if (new_cpuid == cb_p->cpuid)
21573623Sjchu goto cb_done;
21583623Sjchu
21593623Sjchu if ((px_lib_intr_getvalid(pxp->px_dip, f_p->px_fh_sysino, &enabled)
21603623Sjchu != DDI_SUCCESS) || !enabled) {
21613623Sjchu DBG(DBG_IB, pxp->px_dip, "px_cb_intr_redist: CB not enabled, "
21623623Sjchu "sysino(0x%x)\n", f_p->px_fh_sysino);
21633623Sjchu goto cb_done;
21643623Sjchu }
21653623Sjchu
21663623Sjchu PX_INTR_DISABLE(pxp->px_dip, f_p->px_fh_sysino);
21673623Sjchu
21683623Sjchu cb_p->cpuid = new_cpuid;
21693623Sjchu cb_p->sysino = f_p->px_fh_sysino;
21703623Sjchu PX_INTR_ENABLE(pxp->px_dip, cb_p->sysino, cb_p->cpuid);
21713623Sjchu
21723623Sjchu cb_done:
21733623Sjchu mutex_exit(&cb_p->cb_mutex);
21743623Sjchu }
21753623Sjchu
21763623Sjchu /*
21771648Sjchu * px_cb_add_intr() - Called from attach(9E) to create CB if not yet
21781648Sjchu * created, to add CB interrupt vector always, but enable only once.
21791648Sjchu */
21801648Sjchu int
px_cb_add_intr(px_fault_t * fault_p)21811648Sjchu px_cb_add_intr(px_fault_t *fault_p)
21821648Sjchu {
21831648Sjchu px_t *px_p = DIP_TO_STATE(fault_p->px_fh_dip);
21841648Sjchu pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
21851772Sjl139090 px_cb_t *cb_p = (px_cb_t *)px_get_cb(fault_p->px_fh_dip);
21861648Sjchu px_cb_list_t *pxl, *pxl_new;
21873623Sjchu boolean_t is_proxy = B_FALSE;
21883623Sjchu
21893623Sjchu /* create cb */
21901648Sjchu if (cb_p == NULL) {
21911648Sjchu cb_p = kmem_zalloc(sizeof (px_cb_t), KM_SLEEP);
21923623Sjchu
21933623Sjchu mutex_init(&cb_p->cb_mutex, NULL, MUTEX_DRIVER,
21943623Sjchu (void *) ipltospl(FM_ERR_PIL));
21953623Sjchu
21961648Sjchu cb_p->px_cb_func = px_cb_intr;
21971648Sjchu pxu_p->px_cb_p = cb_p;
21981772Sjl139090 px_set_cb(fault_p->px_fh_dip, (uint64_t)cb_p);
21992509Sschwartz
22002509Sschwartz /* px_lib_dev_init allows only FIRE and OBERON */
22012509Sschwartz px_err_reg_enable(
22022509Sschwartz (pxu_p->chip_type == PX_CHIP_FIRE) ?
22036313Skrishnae PX_ERR_JBC : PX_ERR_UBC,
22042509Sschwartz pxu_p->px_address[PX_REG_XBC]);
22051648Sjchu } else
22061648Sjchu pxu_p->px_cb_p = cb_p;
22071648Sjchu
22083623Sjchu /* register cb interrupt */
22091648Sjchu VERIFY(add_ivintr(fault_p->px_fh_sysino, PX_ERR_PIL,
22102973Sgovinda (intrfunc)cb_p->px_cb_func, (caddr_t)cb_p, NULL, NULL) == 0);
22111648Sjchu
22123623Sjchu
22133623Sjchu /* update cb list */
22143623Sjchu mutex_enter(&cb_p->cb_mutex);
22151648Sjchu if (cb_p->pxl == NULL) {
22163623Sjchu is_proxy = B_TRUE;
22171648Sjchu pxl = kmem_zalloc(sizeof (px_cb_list_t), KM_SLEEP);
22181648Sjchu pxl->pxp = px_p;
22191648Sjchu cb_p->pxl = pxl;
22201648Sjchu cb_p->sysino = fault_p->px_fh_sysino;
22213623Sjchu cb_p->cpuid = intr_dist_cpuid();
22221648Sjchu } else {
22231648Sjchu /*
22241648Sjchu * Find the last pxl or
22253623Sjchu * stop short at encountering a redundent entry, or
22261648Sjchu * both.
22271648Sjchu */
22281648Sjchu pxl = cb_p->pxl;
22296313Skrishnae for (; !(pxl->pxp == px_p) && pxl->next; pxl = pxl->next) {};
22303623Sjchu ASSERT(pxl->pxp != px_p);
22311648Sjchu
22321648Sjchu /* add to linked list */
22331648Sjchu pxl_new = kmem_zalloc(sizeof (px_cb_list_t), KM_SLEEP);
22341648Sjchu pxl_new->pxp = px_p;
22351648Sjchu pxl->next = pxl_new;
22361648Sjchu }
22371648Sjchu cb_p->attachcnt++;
22381648Sjchu mutex_exit(&cb_p->cb_mutex);
22391648Sjchu
22403623Sjchu if (is_proxy) {
22413623Sjchu /* add to interrupt redistribution list */
22423623Sjchu intr_dist_add(px_cb_intr_redist, cb_p);
22433623Sjchu
22443623Sjchu /* enable cb hw interrupt */
22453623Sjchu px_ib_intr_enable(px_p, cb_p->cpuid, fault_p->px_intr_ino);
22463623Sjchu }
22473623Sjchu
22481648Sjchu return (DDI_SUCCESS);
22491648Sjchu }
22501648Sjchu
22511648Sjchu /*
22521648Sjchu * px_cb_rem_intr() - Called from detach(9E) to remove its CB
22531648Sjchu * interrupt vector, to shift proxy to the next available px,
22541648Sjchu * or disable CB interrupt when itself is the last.
22551648Sjchu */
22561648Sjchu void
px_cb_rem_intr(px_fault_t * fault_p)22571648Sjchu px_cb_rem_intr(px_fault_t *fault_p)
22581648Sjchu {
22591648Sjchu px_t *px_p = DIP_TO_STATE(fault_p->px_fh_dip), *pxp;
22601648Sjchu pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
22611648Sjchu px_cb_t *cb_p = PX2CB(px_p);
22621648Sjchu px_cb_list_t *pxl, *prev;
22631648Sjchu px_fault_t *f_p;
22641648Sjchu
22651648Sjchu ASSERT(cb_p->pxl);
22661648Sjchu
22673623Sjchu /* find and remove this px, and update cb list */
22681648Sjchu mutex_enter(&cb_p->cb_mutex);
22691648Sjchu
22701648Sjchu pxl = cb_p->pxl;
22711648Sjchu if (pxl->pxp == px_p) {
22721648Sjchu cb_p->pxl = pxl->next;
22731648Sjchu } else {
22741648Sjchu prev = pxl;
22751648Sjchu pxl = pxl->next;
22766313Skrishnae for (; pxl && (pxl->pxp != px_p); prev = pxl, pxl = pxl->next) {
22776313Skrishnae };
22781648Sjchu if (!pxl) {
22791648Sjchu cmn_err(CE_WARN, "px_cb_rem_intr: can't find px_p 0x%p "
22801650Sjchu "in registered CB list.", (void *)px_p);
22813623Sjchu mutex_exit(&cb_p->cb_mutex);
22821648Sjchu return;
22831648Sjchu }
22841648Sjchu prev->next = pxl->next;
22851648Sjchu }
22863623Sjchu pxu_p->px_cb_p = NULL;
22873623Sjchu cb_p->attachcnt--;
22881648Sjchu kmem_free(pxl, sizeof (px_cb_list_t));
22893623Sjchu mutex_exit(&cb_p->cb_mutex);
22903623Sjchu
22913623Sjchu /* disable cb hw interrupt */
22923623Sjchu if (fault_p->px_fh_sysino == cb_p->sysino)
22931648Sjchu px_ib_intr_disable(px_p->px_ib_p, fault_p->px_intr_ino,
22941648Sjchu IB_INTR_WAIT);
22951648Sjchu
22963623Sjchu /* if last px, remove from interrupt redistribution list */
22973623Sjchu if (cb_p->pxl == NULL)
22983623Sjchu intr_dist_rem(px_cb_intr_redist, cb_p);
22993623Sjchu
23003623Sjchu /* de-register interrupt */
23013623Sjchu VERIFY(rem_ivintr(fault_p->px_fh_sysino, PX_ERR_PIL) == 0);
23023623Sjchu
23033623Sjchu /* if not last px, assign next px to manage cb */
23043623Sjchu mutex_enter(&cb_p->cb_mutex);
23053623Sjchu if (cb_p->pxl) {
23063623Sjchu if (fault_p->px_fh_sysino == cb_p->sysino) {
23071648Sjchu pxp = cb_p->pxl->pxp;
23081648Sjchu f_p = &pxp->px_cb_fault;
23091648Sjchu cb_p->sysino = f_p->px_fh_sysino;
23101648Sjchu
23111648Sjchu PX_INTR_ENABLE(pxp->px_dip, cb_p->sysino, cb_p->cpuid);
23121650Sjchu (void) px_lib_intr_setstate(pxp->px_dip, cb_p->sysino,
23131648Sjchu INTR_IDLE_STATE);
23141648Sjchu }
23151648Sjchu mutex_exit(&cb_p->cb_mutex);
23161648Sjchu return;
23171648Sjchu }
23183623Sjchu
23193623Sjchu /* clean up after the last px */
23201648Sjchu mutex_exit(&cb_p->cb_mutex);
23211648Sjchu
23222509Sschwartz /* px_lib_dev_init allows only FIRE and OBERON */
23232509Sschwartz px_err_reg_disable(
23242509Sschwartz (pxu_p->chip_type == PX_CHIP_FIRE) ? PX_ERR_JBC : PX_ERR_UBC,
23252509Sschwartz pxu_p->px_address[PX_REG_XBC]);
23262509Sschwartz
23271648Sjchu mutex_destroy(&cb_p->cb_mutex);
23281772Sjl139090 px_set_cb(fault_p->px_fh_dip, 0ull);
23291648Sjchu kmem_free(cb_p, sizeof (px_cb_t));
23301648Sjchu }
23311648Sjchu
23321648Sjchu /*
23331648Sjchu * px_cb_intr() - sun4u only, CB interrupt dispatcher
23341648Sjchu */
23351648Sjchu uint_t
px_cb_intr(caddr_t arg)23361648Sjchu px_cb_intr(caddr_t arg)
23371648Sjchu {
23381648Sjchu px_cb_t *cb_p = (px_cb_t *)arg;
23393623Sjchu px_t *pxp;
23403623Sjchu px_fault_t *f_p;
23413623Sjchu int ret;
23423354Sjl139090
23431648Sjchu mutex_enter(&cb_p->cb_mutex);
23441648Sjchu
23453623Sjchu if (!cb_p->pxl) {
23461648Sjchu mutex_exit(&cb_p->cb_mutex);
23473623Sjchu return (DDI_INTR_UNCLAIMED);
23481648Sjchu }
23491648Sjchu
23503623Sjchu pxp = cb_p->pxl->pxp;
23513623Sjchu f_p = &pxp->px_cb_fault;
23523623Sjchu
23533623Sjchu ret = f_p->px_err_func((caddr_t)f_p);
23541648Sjchu
23551648Sjchu mutex_exit(&cb_p->cb_mutex);
23563623Sjchu return (ret);
23571648Sjchu }
23581648Sjchu
23593623Sjchu #ifdef FMA
236027Sjchu void
px_fill_rc_status(px_fault_t * px_fault_p,pciex_rc_error_regs_t * rc_status)236127Sjchu px_fill_rc_status(px_fault_t *px_fault_p, pciex_rc_error_regs_t *rc_status)
236227Sjchu {
236327Sjchu /* populate the rc_status by reading the registers - TBD */
236427Sjchu }
236527Sjchu #endif /* FMA */
2366383Set142600
2367383Set142600 /*
2368435Sjchu * cpr callback
2369435Sjchu *
2370435Sjchu * disable fabric error msg interrupt prior to suspending
2371435Sjchu * all device drivers; re-enable fabric error msg interrupt
2372435Sjchu * after all devices are resumed.
2373435Sjchu */
2374435Sjchu static boolean_t
px_cpr_callb(void * arg,int code)2375435Sjchu px_cpr_callb(void *arg, int code)
2376435Sjchu {
2377435Sjchu px_t *px_p = (px_t *)arg;
2378435Sjchu px_ib_t *ib_p = px_p->px_ib_p;
2379435Sjchu px_pec_t *pec_p = px_p->px_pec_p;
2380435Sjchu pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
2381435Sjchu caddr_t csr_base;
2382435Sjchu devino_t ce_ino, nf_ino, f_ino;
23832973Sgovinda px_ino_t *ce_ino_p, *nf_ino_p, *f_ino_p;
2384435Sjchu uint64_t imu_log_enable, imu_intr_enable;
2385435Sjchu uint64_t imu_log_mask, imu_intr_mask;
2386435Sjchu
2387435Sjchu ce_ino = px_msiqid_to_devino(px_p, pec_p->pec_corr_msg_msiq_id);
2388435Sjchu nf_ino = px_msiqid_to_devino(px_p, pec_p->pec_non_fatal_msg_msiq_id);
2389435Sjchu f_ino = px_msiqid_to_devino(px_p, pec_p->pec_fatal_msg_msiq_id);
2390435Sjchu csr_base = (caddr_t)pxu_p->px_address[PX_REG_CSR];
2391435Sjchu
2392435Sjchu imu_log_enable = CSR_XR(csr_base, IMU_ERROR_LOG_ENABLE);
2393435Sjchu imu_intr_enable = CSR_XR(csr_base, IMU_INTERRUPT_ENABLE);
2394435Sjchu
2395435Sjchu imu_log_mask = BITMASK(IMU_ERROR_LOG_ENABLE_FATAL_MES_NOT_EN_LOG_EN) |
2396435Sjchu BITMASK(IMU_ERROR_LOG_ENABLE_NONFATAL_MES_NOT_EN_LOG_EN) |
2397435Sjchu BITMASK(IMU_ERROR_LOG_ENABLE_COR_MES_NOT_EN_LOG_EN);
2398435Sjchu
2399435Sjchu imu_intr_mask =
2400435Sjchu BITMASK(IMU_INTERRUPT_ENABLE_FATAL_MES_NOT_EN_S_INT_EN) |
2401435Sjchu BITMASK(IMU_INTERRUPT_ENABLE_NONFATAL_MES_NOT_EN_S_INT_EN) |
2402435Sjchu BITMASK(IMU_INTERRUPT_ENABLE_COR_MES_NOT_EN_S_INT_EN) |
2403435Sjchu BITMASK(IMU_INTERRUPT_ENABLE_FATAL_MES_NOT_EN_P_INT_EN) |
2404435Sjchu BITMASK(IMU_INTERRUPT_ENABLE_NONFATAL_MES_NOT_EN_P_INT_EN) |
2405435Sjchu BITMASK(IMU_INTERRUPT_ENABLE_COR_MES_NOT_EN_P_INT_EN);
2406435Sjchu
2407435Sjchu switch (code) {
2408435Sjchu case CB_CODE_CPR_CHKPT:
2409435Sjchu /* disable imu rbne on corr/nonfatal/fatal errors */
2410435Sjchu CSR_XS(csr_base, IMU_ERROR_LOG_ENABLE,
2411435Sjchu imu_log_enable & (~imu_log_mask));
2412435Sjchu
2413435Sjchu CSR_XS(csr_base, IMU_INTERRUPT_ENABLE,
2414435Sjchu imu_intr_enable & (~imu_intr_mask));
2415435Sjchu
2416435Sjchu /* disable CORR intr mapping */
2417435Sjchu px_ib_intr_disable(ib_p, ce_ino, IB_INTR_NOWAIT);
2418435Sjchu
2419435Sjchu /* disable NON FATAL intr mapping */
2420435Sjchu px_ib_intr_disable(ib_p, nf_ino, IB_INTR_NOWAIT);
2421435Sjchu
2422435Sjchu /* disable FATAL intr mapping */
2423435Sjchu px_ib_intr_disable(ib_p, f_ino, IB_INTR_NOWAIT);
2424435Sjchu
2425435Sjchu break;
2426435Sjchu
2427435Sjchu case CB_CODE_CPR_RESUME:
24283274Set142600 pxu_p->cpr_flag = PX_NOT_CPR;
2429435Sjchu mutex_enter(&ib_p->ib_ino_lst_mutex);
2430435Sjchu
2431435Sjchu ce_ino_p = px_ib_locate_ino(ib_p, ce_ino);
2432435Sjchu nf_ino_p = px_ib_locate_ino(ib_p, nf_ino);
2433435Sjchu f_ino_p = px_ib_locate_ino(ib_p, f_ino);
2434435Sjchu
2435435Sjchu /* enable CORR intr mapping */
2436435Sjchu if (ce_ino_p)
2437435Sjchu px_ib_intr_enable(px_p, ce_ino_p->ino_cpuid, ce_ino);
2438435Sjchu else
2439435Sjchu cmn_err(CE_WARN, "px_cpr_callb: RESUME unable to "
2440435Sjchu "reenable PCIe Correctable msg intr.\n");
2441435Sjchu
2442435Sjchu /* enable NON FATAL intr mapping */
2443435Sjchu if (nf_ino_p)
2444435Sjchu px_ib_intr_enable(px_p, nf_ino_p->ino_cpuid, nf_ino);
2445435Sjchu else
2446435Sjchu cmn_err(CE_WARN, "px_cpr_callb: RESUME unable to "
2447435Sjchu "reenable PCIe Non Fatal msg intr.\n");
2448435Sjchu
2449435Sjchu /* enable FATAL intr mapping */
2450435Sjchu if (f_ino_p)
2451435Sjchu px_ib_intr_enable(px_p, f_ino_p->ino_cpuid, f_ino);
2452435Sjchu else
2453435Sjchu cmn_err(CE_WARN, "px_cpr_callb: RESUME unable to "
2454435Sjchu "reenable PCIe Fatal msg intr.\n");
2455435Sjchu
2456435Sjchu mutex_exit(&ib_p->ib_ino_lst_mutex);
2457435Sjchu
2458435Sjchu /* enable corr/nonfatal/fatal not enable error */
2459435Sjchu CSR_XS(csr_base, IMU_ERROR_LOG_ENABLE, (imu_log_enable |
2460435Sjchu (imu_log_mask & px_imu_log_mask)));
2461435Sjchu CSR_XS(csr_base, IMU_INTERRUPT_ENABLE, (imu_intr_enable |
2462435Sjchu (imu_intr_mask & px_imu_intr_mask)));
2463435Sjchu
2464435Sjchu break;
2465435Sjchu }
2466435Sjchu
2467435Sjchu return (B_TRUE);
2468435Sjchu }
2469435Sjchu
24702053Sschwartz uint64_t
px_get_rng_parent_hi_mask(px_t * px_p)24712053Sschwartz px_get_rng_parent_hi_mask(px_t *px_p)
24722053Sschwartz {
24732053Sschwartz pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
24742053Sschwartz uint64_t mask;
24752053Sschwartz
24762053Sschwartz switch (PX_CHIP_TYPE(pxu_p)) {
24772053Sschwartz case PX_CHIP_OBERON:
24782053Sschwartz mask = OBERON_RANGE_PROP_MASK;
24792053Sschwartz break;
24802053Sschwartz case PX_CHIP_FIRE:
24812053Sschwartz mask = PX_RANGE_PROP_MASK;
24822053Sschwartz break;
24832053Sschwartz default:
24842053Sschwartz mask = PX_RANGE_PROP_MASK;
24852053Sschwartz }
24862053Sschwartz
24872053Sschwartz return (mask);
24882053Sschwartz }
24892053Sschwartz
2490435Sjchu /*
24911772Sjl139090 * fetch chip's range propery's value
24921772Sjl139090 */
24931772Sjl139090 uint64_t
px_get_range_prop(px_t * px_p,pci_ranges_t * rp,int bank)249410923SEvan.Yan@Sun.COM px_get_range_prop(px_t *px_p, pci_ranges_t *rp, int bank)
24951772Sjl139090 {
24961772Sjl139090 uint64_t mask, range_prop;
24971772Sjl139090
24982053Sschwartz mask = px_get_rng_parent_hi_mask(px_p);
24991772Sjl139090 range_prop = (((uint64_t)(rp[bank].parent_high & mask)) << 32) |
25006313Skrishnae rp[bank].parent_low;
25011772Sjl139090
25021772Sjl139090 return (range_prop);
25031772Sjl139090 }
25041772Sjl139090
25051772Sjl139090 /*
250611245SZhijun.Fu@Sun.COM * fetch the config space base addr of the root complex
250711245SZhijun.Fu@Sun.COM * note this depends on px structure being initialized
250811245SZhijun.Fu@Sun.COM */
250911245SZhijun.Fu@Sun.COM uint64_t
px_lib_get_cfgacc_base(dev_info_t * dip)251011245SZhijun.Fu@Sun.COM px_lib_get_cfgacc_base(dev_info_t *dip)
251111245SZhijun.Fu@Sun.COM {
251211245SZhijun.Fu@Sun.COM int instance = DIP_TO_INST(dip);
251311245SZhijun.Fu@Sun.COM px_t *px_p = INST_TO_STATE(instance);
251411245SZhijun.Fu@Sun.COM pci_ranges_t *rp = px_p->px_ranges_p;
251511245SZhijun.Fu@Sun.COM int bank = PCI_REG_ADDR_G(PCI_ADDR_CONFIG);
251611245SZhijun.Fu@Sun.COM
251711245SZhijun.Fu@Sun.COM /* Get Fire's Physical Base Address */
251811245SZhijun.Fu@Sun.COM return (px_get_range_prop(px_p, rp, bank));
251911245SZhijun.Fu@Sun.COM }
252011245SZhijun.Fu@Sun.COM
252111245SZhijun.Fu@Sun.COM /*
2522435Sjchu * add cpr callback
2523435Sjchu */
2524435Sjchu void
px_cpr_add_callb(px_t * px_p)2525435Sjchu px_cpr_add_callb(px_t *px_p)
2526435Sjchu {
2527435Sjchu px_p->px_cprcb_id = callb_add(px_cpr_callb, (void *)px_p,
25286313Skrishnae CB_CL_CPR_POST_USER, "px_cpr");
2529435Sjchu }
2530435Sjchu
2531435Sjchu /*
2532435Sjchu * remove cpr callback
2533435Sjchu */
2534435Sjchu void
px_cpr_rem_callb(px_t * px_p)2535435Sjchu px_cpr_rem_callb(px_t *px_p)
2536435Sjchu {
2537435Sjchu (void) callb_delete(px_p->px_cprcb_id);
2538435Sjchu }
25391531Skini
25401531Skini /*ARGSUSED*/
25411772Sjl139090 static uint_t
px_hp_intr(caddr_t arg1,caddr_t arg2)25421772Sjl139090 px_hp_intr(caddr_t arg1, caddr_t arg2)
25431772Sjl139090 {
254410923SEvan.Yan@Sun.COM px_t *px_p = (px_t *)arg1;
254510923SEvan.Yan@Sun.COM pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
254610923SEvan.Yan@Sun.COM int rval;
254710923SEvan.Yan@Sun.COM
254810923SEvan.Yan@Sun.COM rval = pcie_intr(px_p->px_dip);
25491772Sjl139090
25501772Sjl139090 #ifdef DEBUG
25511772Sjl139090 if (rval == DDI_INTR_UNCLAIMED)
25526313Skrishnae cmn_err(CE_WARN, "%s%d: UNCLAIMED intr\n",
25536313Skrishnae ddi_driver_name(px_p->px_dip),
25546313Skrishnae ddi_get_instance(px_p->px_dip));
25551772Sjl139090 #endif
25561772Sjl139090
25574701Sgovinda /* Set the interrupt state to idle */
25584701Sgovinda if (px_lib_intr_setstate(px_p->px_dip,
25594701Sgovinda pxu_p->hp_sysino, INTR_IDLE_STATE) != DDI_SUCCESS)
25604701Sgovinda return (DDI_INTR_UNCLAIMED);
25614701Sgovinda
25621772Sjl139090 return (rval);
25631772Sjl139090 }
25641772Sjl139090
25651531Skini int
px_lib_hotplug_init(dev_info_t * dip,void * arg)25661531Skini px_lib_hotplug_init(dev_info_t *dip, void *arg)
25671531Skini {
25681772Sjl139090 px_t *px_p = DIP_TO_STATE(dip);
25694701Sgovinda pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
25701772Sjl139090 uint64_t ret;
25711772Sjl139090
257210923SEvan.Yan@Sun.COM if (ddi_prop_exists(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
257310923SEvan.Yan@Sun.COM "hotplug-capable") == 0)
257410923SEvan.Yan@Sun.COM return (DDI_FAILURE);
257510923SEvan.Yan@Sun.COM
25761772Sjl139090 if ((ret = hvio_hotplug_init(dip, arg)) == DDI_SUCCESS) {
25771772Sjl139090 if (px_lib_intr_devino_to_sysino(px_p->px_dip,
25784701Sgovinda px_p->px_inos[PX_INTR_HOTPLUG], &pxu_p->hp_sysino) !=
25791772Sjl139090 DDI_SUCCESS) {
25801772Sjl139090 #ifdef DEBUG
25811772Sjl139090 cmn_err(CE_WARN, "%s%d: devino_to_sysino fails\n",
25821772Sjl139090 ddi_driver_name(px_p->px_dip),
25831772Sjl139090 ddi_get_instance(px_p->px_dip));
25841772Sjl139090 #endif
25851772Sjl139090 return (DDI_FAILURE);
25861772Sjl139090 }
25871772Sjl139090
258810923SEvan.Yan@Sun.COM VERIFY(add_ivintr(pxu_p->hp_sysino, PCIE_INTR_PRI,
25892973Sgovinda (intrfunc)px_hp_intr, (caddr_t)px_p, NULL, NULL) == 0);
25903953Sscarter
25913953Sscarter px_ib_intr_enable(px_p, intr_dist_cpuid(),
25923953Sscarter px_p->px_inos[PX_INTR_HOTPLUG]);
25931772Sjl139090 }
25941772Sjl139090
25951772Sjl139090 return (ret);
25961531Skini }
25971531Skini
25981531Skini void
px_lib_hotplug_uninit(dev_info_t * dip)25991531Skini px_lib_hotplug_uninit(dev_info_t *dip)
26001531Skini {
26011772Sjl139090 if (hvio_hotplug_uninit(dip) == DDI_SUCCESS) {
26021772Sjl139090 px_t *px_p = DIP_TO_STATE(dip);
26034701Sgovinda pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
26041772Sjl139090
26053953Sscarter px_ib_intr_disable(px_p->px_ib_p,
26063953Sscarter px_p->px_inos[PX_INTR_HOTPLUG], IB_INTR_WAIT);
26073953Sscarter
260810923SEvan.Yan@Sun.COM VERIFY(rem_ivintr(pxu_p->hp_sysino, PCIE_INTR_PRI) == 0);
26091772Sjl139090 }
26101531Skini }
26112476Sdwoods
26123953Sscarter /*
26133953Sscarter * px_hp_intr_redist() - sun4u only, HP interrupt redistribution
26143953Sscarter */
26153953Sscarter void
px_hp_intr_redist(px_t * px_p)26163953Sscarter px_hp_intr_redist(px_t *px_p)
26173953Sscarter {
261810923SEvan.Yan@Sun.COM pcie_bus_t *bus_p = PCIE_DIP2BUS(px_p->px_dip);
261910923SEvan.Yan@Sun.COM
262010923SEvan.Yan@Sun.COM if (px_p && PCIE_IS_PCIE_HOTPLUG_ENABLED(bus_p)) {
26213953Sscarter px_ib_intr_dist_en(px_p->px_dip, intr_dist_cpuid(),
26223953Sscarter px_p->px_inos[PX_INTR_HOTPLUG], B_FALSE);
26233953Sscarter }
26243953Sscarter }
26253953Sscarter
26262476Sdwoods boolean_t
px_lib_is_in_drain_state(px_t * px_p)26272476Sdwoods px_lib_is_in_drain_state(px_t *px_p)
26282476Sdwoods {
26292476Sdwoods pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
26302476Sdwoods caddr_t csr_base = (caddr_t)pxu_p->px_address[PX_REG_CSR];
26312476Sdwoods uint64_t drain_status;
26322476Sdwoods
26332476Sdwoods if (PX_CHIP_TYPE(pxu_p) == PX_CHIP_OBERON) {
26342476Sdwoods drain_status = CSR_BR(csr_base, DRAIN_CONTROL_STATUS, DRAIN);
26352476Sdwoods } else {
26362476Sdwoods drain_status = CSR_BR(csr_base, TLU_STATUS, DRAIN);
26372476Sdwoods }
26382476Sdwoods
26392476Sdwoods return (drain_status);
26402476Sdwoods }
26413613Set142600
26423613Set142600 pcie_req_id_t
px_lib_get_bdf(px_t * px_p)26433613Set142600 px_lib_get_bdf(px_t *px_p)
26443613Set142600 {
26453613Set142600 pxu_t *pxu_p = (pxu_t *)px_p->px_plat_p;
26463613Set142600 caddr_t csr_base = (caddr_t)pxu_p->px_address[PX_REG_CSR];
26473613Set142600 pcie_req_id_t bdf;
26483613Set142600
26493613Set142600 bdf = CSR_BR(csr_base, DMC_PCI_EXPRESS_CONFIGURATION, REQ_ID);
26503613Set142600
26513613Set142600 return (bdf);
26523613Set142600 }
26537596SAlan.Adamson@Sun.COM
26547596SAlan.Adamson@Sun.COM /*ARGSUSED*/
26557596SAlan.Adamson@Sun.COM int
px_lib_get_root_complex_mps(px_t * px_p,dev_info_t * dip,int * mps)26567596SAlan.Adamson@Sun.COM px_lib_get_root_complex_mps(px_t *px_p, dev_info_t *dip, int *mps)
26577596SAlan.Adamson@Sun.COM {
26587596SAlan.Adamson@Sun.COM pxu_t *pxu_p;
26597596SAlan.Adamson@Sun.COM caddr_t csr_base;
26607596SAlan.Adamson@Sun.COM
26617596SAlan.Adamson@Sun.COM pxu_p = (pxu_t *)px_p->px_plat_p;
26627596SAlan.Adamson@Sun.COM
26637596SAlan.Adamson@Sun.COM if (pxu_p == NULL)
26647596SAlan.Adamson@Sun.COM return (DDI_FAILURE);
26657596SAlan.Adamson@Sun.COM
26667596SAlan.Adamson@Sun.COM csr_base = (caddr_t)pxu_p->px_address[PX_REG_CSR];
26677596SAlan.Adamson@Sun.COM
26687596SAlan.Adamson@Sun.COM
26697596SAlan.Adamson@Sun.COM *mps = CSR_XR(csr_base, TLU_DEVICE_CAPABILITIES) &
26707596SAlan.Adamson@Sun.COM TLU_DEVICE_CAPABILITIES_MPS_MASK;
26717596SAlan.Adamson@Sun.COM
26727596SAlan.Adamson@Sun.COM return (DDI_SUCCESS);
26737596SAlan.Adamson@Sun.COM }
26747596SAlan.Adamson@Sun.COM
26757596SAlan.Adamson@Sun.COM /*ARGSUSED*/
26767596SAlan.Adamson@Sun.COM int
px_lib_set_root_complex_mps(px_t * px_p,dev_info_t * dip,int mps)26777596SAlan.Adamson@Sun.COM px_lib_set_root_complex_mps(px_t *px_p, dev_info_t *dip, int mps)
26787596SAlan.Adamson@Sun.COM {
26797596SAlan.Adamson@Sun.COM pxu_t *pxu_p;
26807596SAlan.Adamson@Sun.COM caddr_t csr_base;
26817596SAlan.Adamson@Sun.COM uint64_t dev_ctrl;
26827596SAlan.Adamson@Sun.COM int link_width, val;
26837596SAlan.Adamson@Sun.COM px_chip_type_t chip_type = px_identity_init(px_p);
26847596SAlan.Adamson@Sun.COM
26857596SAlan.Adamson@Sun.COM pxu_p = (pxu_t *)px_p->px_plat_p;
26867596SAlan.Adamson@Sun.COM
26877596SAlan.Adamson@Sun.COM if (pxu_p == NULL)
26887596SAlan.Adamson@Sun.COM return (DDI_FAILURE);
26897596SAlan.Adamson@Sun.COM
26907596SAlan.Adamson@Sun.COM csr_base = (caddr_t)pxu_p->px_address[PX_REG_CSR];
26917596SAlan.Adamson@Sun.COM
26927596SAlan.Adamson@Sun.COM dev_ctrl = CSR_XR(csr_base, TLU_DEVICE_CONTROL);
26937596SAlan.Adamson@Sun.COM dev_ctrl |= (mps << TLU_DEVICE_CONTROL_MPS);
26947596SAlan.Adamson@Sun.COM
26957596SAlan.Adamson@Sun.COM CSR_XS(csr_base, TLU_DEVICE_CONTROL, dev_ctrl);
26967596SAlan.Adamson@Sun.COM
26977596SAlan.Adamson@Sun.COM link_width = CSR_FR(csr_base, TLU_LINK_STATUS, WIDTH);
26987596SAlan.Adamson@Sun.COM
26997596SAlan.Adamson@Sun.COM /*
27007596SAlan.Adamson@Sun.COM * Convert link_width to match timer array configuration.
27017596SAlan.Adamson@Sun.COM */
27027596SAlan.Adamson@Sun.COM switch (link_width) {
27037596SAlan.Adamson@Sun.COM case 1:
27047596SAlan.Adamson@Sun.COM link_width = 0;
27057596SAlan.Adamson@Sun.COM break;
27067596SAlan.Adamson@Sun.COM case 4:
27077596SAlan.Adamson@Sun.COM link_width = 1;
27087596SAlan.Adamson@Sun.COM break;
27097596SAlan.Adamson@Sun.COM case 8:
27107596SAlan.Adamson@Sun.COM link_width = 2;
27117596SAlan.Adamson@Sun.COM break;
27127596SAlan.Adamson@Sun.COM case 16:
27137596SAlan.Adamson@Sun.COM link_width = 3;
27147596SAlan.Adamson@Sun.COM break;
27157596SAlan.Adamson@Sun.COM default:
27167596SAlan.Adamson@Sun.COM link_width = 0;
27177596SAlan.Adamson@Sun.COM }
27187596SAlan.Adamson@Sun.COM
27197596SAlan.Adamson@Sun.COM val = px_replay_timer_table[mps][link_width];
27207596SAlan.Adamson@Sun.COM CSR_XS(csr_base, LPU_TXLINK_REPLAY_TIMER_THRESHOLD, val);
27217596SAlan.Adamson@Sun.COM
27227596SAlan.Adamson@Sun.COM if (chip_type == PX_CHIP_OBERON)
27237596SAlan.Adamson@Sun.COM return (DDI_SUCCESS);
27247596SAlan.Adamson@Sun.COM
27257596SAlan.Adamson@Sun.COM val = px_acknak_timer_table[mps][link_width];
27267596SAlan.Adamson@Sun.COM CSR_XS(csr_base, LPU_TXLINK_FREQUENT_NAK_LATENCY_TIMER_THRESHOLD, val);
27277596SAlan.Adamson@Sun.COM
27287596SAlan.Adamson@Sun.COM return (DDI_SUCCESS);
27297596SAlan.Adamson@Sun.COM }
273011596SJason.Beloro@Sun.COM
273111596SJason.Beloro@Sun.COM /*ARGSUSED*/
273211596SJason.Beloro@Sun.COM int
px_lib_fabric_sync(dev_info_t * dip)273311596SJason.Beloro@Sun.COM px_lib_fabric_sync(dev_info_t *dip)
273411596SJason.Beloro@Sun.COM {
273511596SJason.Beloro@Sun.COM /* an no-op on sun4u platform */
273611596SJason.Beloro@Sun.COM return (DDI_SUCCESS);
273711596SJason.Beloro@Sun.COM }
2738