xref: /onnv-gate/usr/src/uts/sun4u/io/px/px_hlib.c (revision 225:7c209fbd5a09)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <sys/cmn_err.h>
310Sstevel@tonic-gate #include <sys/vmsystm.h>
320Sstevel@tonic-gate #include <sys/vmem.h>
330Sstevel@tonic-gate #include <sys/machsystm.h>	/* lddphys() */
340Sstevel@tonic-gate #include <sys/iommutsb.h>
350Sstevel@tonic-gate #include <sys/pci.h>
360Sstevel@tonic-gate #include <pcie_pwr.h>
370Sstevel@tonic-gate #include <px_obj.h>
380Sstevel@tonic-gate #include "px_regs.h"
390Sstevel@tonic-gate #include "px_csr.h"
400Sstevel@tonic-gate #include "px_lib4u.h"
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate  * Registers that need to be saved and restored during suspend/resume.
440Sstevel@tonic-gate  */
450Sstevel@tonic-gate 
460Sstevel@tonic-gate /*
470Sstevel@tonic-gate  * Registers in the PEC Module.
480Sstevel@tonic-gate  * LPU_RESET should be set to 0ull during resume
490Sstevel@tonic-gate  */
500Sstevel@tonic-gate static uint64_t	pec_config_state_regs[] = {
510Sstevel@tonic-gate 	PEC_CORE_AND_BLOCK_INTERRUPT_ENABLE,
520Sstevel@tonic-gate 	ILU_ERROR_LOG_ENABLE,
530Sstevel@tonic-gate 	ILU_INTERRUPT_ENABLE,
540Sstevel@tonic-gate 	TLU_CONTROL,
550Sstevel@tonic-gate 	TLU_OTHER_EVENT_LOG_ENABLE,
560Sstevel@tonic-gate 	TLU_OTHER_EVENT_INTERRUPT_ENABLE,
570Sstevel@tonic-gate 	TLU_DEVICE_CONTROL,
580Sstevel@tonic-gate 	TLU_LINK_CONTROL,
590Sstevel@tonic-gate 	TLU_UNCORRECTABLE_ERROR_LOG_ENABLE,
600Sstevel@tonic-gate 	TLU_UNCORRECTABLE_ERROR_INTERRUPT_ENABLE,
610Sstevel@tonic-gate 	TLU_CORRECTABLE_ERROR_LOG_ENABLE,
620Sstevel@tonic-gate 	TLU_CORRECTABLE_ERROR_INTERRUPT_ENABLE,
6327Sjchu 	LPU_LINK_LAYER_INTERRUPT_MASK,
6427Sjchu 	LPU_PHY_INTERRUPT_MASK,
6527Sjchu 	LPU_RECEIVE_PHY_INTERRUPT_MASK,
6627Sjchu 	LPU_TRANSMIT_PHY_INTERRUPT_MASK,
6727Sjchu 	LPU_GIGABLAZE_GLUE_INTERRUPT_MASK,
6827Sjchu 	LPU_LTSSM_INTERRUPT_MASK,
6927Sjchu 	LPU_RESET,
700Sstevel@tonic-gate 	LPU_DEBUG_CONFIG,
710Sstevel@tonic-gate 	LPU_INTERRUPT_MASK,
720Sstevel@tonic-gate 	LPU_LINK_LAYER_CONFIG,
730Sstevel@tonic-gate 	LPU_FLOW_CONTROL_UPDATE_CONTROL,
740Sstevel@tonic-gate 	LPU_TXLINK_FREQUENT_NAK_LATENCY_TIMER_THRESHOLD,
750Sstevel@tonic-gate 	LPU_TXLINK_REPLAY_TIMER_THRESHOLD,
760Sstevel@tonic-gate 	LPU_REPLAY_BUFFER_MAX_ADDRESS,
770Sstevel@tonic-gate 	LPU_TXLINK_RETRY_FIFO_POINTER,
780Sstevel@tonic-gate 	LPU_LTSSM_CONFIG2,
790Sstevel@tonic-gate 	LPU_LTSSM_CONFIG3,
800Sstevel@tonic-gate 	LPU_LTSSM_CONFIG4,
810Sstevel@tonic-gate 	LPU_LTSSM_CONFIG5,
820Sstevel@tonic-gate 	DMC_CORE_AND_BLOCK_INTERRUPT_ENABLE,
830Sstevel@tonic-gate 	DMC_DEBUG_SELECT_FOR_PORT_A,
840Sstevel@tonic-gate 	DMC_DEBUG_SELECT_FOR_PORT_B
850Sstevel@tonic-gate };
860Sstevel@tonic-gate #define	PEC_SIZE (sizeof (pec_config_state_regs))
870Sstevel@tonic-gate #define	PEC_KEYS (PEC_SIZE / sizeof (uint64_t))
880Sstevel@tonic-gate 
890Sstevel@tonic-gate /*
900Sstevel@tonic-gate  * Registers for the MMU module.
910Sstevel@tonic-gate  * MMU_TTE_CACHE_INVALIDATE needs to be cleared. (-1ull)
920Sstevel@tonic-gate  */
930Sstevel@tonic-gate static uint64_t mmu_config_state_regs[] = {
940Sstevel@tonic-gate 	MMU_TSB_CONTROL,
950Sstevel@tonic-gate 	MMU_CONTROL_AND_STATUS,
9627Sjchu 	MMU_ERROR_LOG_ENABLE,
970Sstevel@tonic-gate 	MMU_INTERRUPT_ENABLE
980Sstevel@tonic-gate };
990Sstevel@tonic-gate #define	MMU_SIZE (sizeof (mmu_config_state_regs))
1000Sstevel@tonic-gate #define	MMU_KEYS (MMU_SIZE / sizeof (uint64_t))
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate /*
1030Sstevel@tonic-gate  * Registers for the IB Module
1040Sstevel@tonic-gate  */
1050Sstevel@tonic-gate static uint64_t ib_config_state_regs[] = {
1060Sstevel@tonic-gate 	IMU_ERROR_LOG_ENABLE,
1070Sstevel@tonic-gate 	IMU_INTERRUPT_ENABLE
1080Sstevel@tonic-gate };
1090Sstevel@tonic-gate #define	IB_SIZE (sizeof (ib_config_state_regs))
1100Sstevel@tonic-gate #define	IB_KEYS (IB_SIZE / sizeof (uint64_t))
1110Sstevel@tonic-gate #define	IB_MAP_SIZE (INTERRUPT_MAPPING_ENTRIES * sizeof (uint64_t))
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate /*
1140Sstevel@tonic-gate  * Registers for the CB module.
1150Sstevel@tonic-gate  * JBC_ERROR_STATUS_CLEAR needs to be cleared. (-1ull)
1160Sstevel@tonic-gate  */
1170Sstevel@tonic-gate static uint64_t	cb_config_state_regs[] = {
1180Sstevel@tonic-gate 	JBUS_PARITY_CONTROL,
1190Sstevel@tonic-gate 	JBC_FATAL_RESET_ENABLE,
1200Sstevel@tonic-gate 	JBC_CORE_AND_BLOCK_INTERRUPT_ENABLE,
1210Sstevel@tonic-gate 	JBC_ERROR_LOG_ENABLE,
1220Sstevel@tonic-gate 	JBC_INTERRUPT_ENABLE
1230Sstevel@tonic-gate };
1240Sstevel@tonic-gate #define	CB_SIZE (sizeof (cb_config_state_regs))
1250Sstevel@tonic-gate #define	CB_KEYS (CB_SIZE / sizeof (uint64_t))
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate static uint64_t	msiq_config_other_regs[] = {
1280Sstevel@tonic-gate 	ERR_COR_MAPPING,
1290Sstevel@tonic-gate 	ERR_NONFATAL_MAPPING,
1300Sstevel@tonic-gate 	ERR_FATAL_MAPPING,
1310Sstevel@tonic-gate 	PM_PME_MAPPING,
1320Sstevel@tonic-gate 	PME_TO_ACK_MAPPING,
1330Sstevel@tonic-gate 	MSI_32_BIT_ADDRESS,
1340Sstevel@tonic-gate 	MSI_64_BIT_ADDRESS
1350Sstevel@tonic-gate };
1360Sstevel@tonic-gate #define	MSIQ_OTHER_SIZE	(sizeof (msiq_config_other_regs))
1370Sstevel@tonic-gate #define	MSIQ_OTHER_KEYS	(MSIQ_OTHER_SIZE / sizeof (uint64_t))
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate #define	MSIQ_STATE_SIZE		(EVENT_QUEUE_STATE_ENTRIES * sizeof (uint64_t))
1400Sstevel@tonic-gate #define	MSIQ_MAPPING_SIZE	(MSI_MAPPING_ENTRIES * sizeof (uint64_t))
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate static uint64_t msiq_suspend(devhandle_t dev_hdl, pxu_t *pxu_p);
1430Sstevel@tonic-gate static void msiq_resume(devhandle_t dev_hdl, pxu_t *pxu_p);
1440Sstevel@tonic-gate 
14527Sjchu /*
14627Sjchu  * Initialize the module, but do not enable interrupts.
14727Sjchu  */
1480Sstevel@tonic-gate /* ARGSUSED */
1490Sstevel@tonic-gate void
1500Sstevel@tonic-gate hvio_cb_init(caddr_t xbc_csr_base, pxu_t *pxu_p)
1510Sstevel@tonic-gate {
1520Sstevel@tonic-gate 	uint64_t val;
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate 	/* Check if we need to enable inverted parity */
1550Sstevel@tonic-gate 	val = (1ULL << JBUS_PARITY_CONTROL_P_EN);
1560Sstevel@tonic-gate 	CSR_XS(xbc_csr_base, JBUS_PARITY_CONTROL, val);
1570Sstevel@tonic-gate 	DBG(DBG_CB, NULL, "hvio_cb_init, JBUS_PARITY_CONTROL: 0x%llx\n",
15827Sjchu 	    CSR_XR(xbc_csr_base, JBUS_PARITY_CONTROL));
15927Sjchu 
16027Sjchu 	val = (1 << JBC_FATAL_RESET_ENABLE_SPARE_P_INT_EN) |
16127Sjchu 	    (1 << JBC_FATAL_RESET_ENABLE_MB_PEA_P_INT_EN) |
16227Sjchu 	    (1 << JBC_FATAL_RESET_ENABLE_CPE_P_INT_EN) |
16327Sjchu 	    (1 << JBC_FATAL_RESET_ENABLE_APE_P_INT_EN) |
16427Sjchu 	    (1 << JBC_FATAL_RESET_ENABLE_PIO_CPE_INT_EN) |
16527Sjchu 	    (1 << JBC_FATAL_RESET_ENABLE_JTCEEW_P_INT_EN) |
16627Sjchu 	    (1 << JBC_FATAL_RESET_ENABLE_JTCEEI_P_INT_EN) |
16727Sjchu 	    (1 << JBC_FATAL_RESET_ENABLE_JTCEER_P_INT_EN);
1680Sstevel@tonic-gate 	CSR_XS(xbc_csr_base, JBC_FATAL_RESET_ENABLE, val);
1690Sstevel@tonic-gate 	DBG(DBG_CB, NULL, "hvio_cb_init, JBC_FATAL_RESET_ENABLE: 0x%llx\n",
1700Sstevel@tonic-gate 		CSR_XR(xbc_csr_base, JBC_FATAL_RESET_ENABLE));
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate 	/*
1730Sstevel@tonic-gate 	 * Enable merge, jbc and dmc interrupts.
1740Sstevel@tonic-gate 	 */
1750Sstevel@tonic-gate 	CSR_XS(xbc_csr_base, JBC_CORE_AND_BLOCK_INTERRUPT_ENABLE, -1ull);
1760Sstevel@tonic-gate 	DBG(DBG_CB, NULL,
17727Sjchu 	    "hvio_cb_init, JBC_CORE_AND_BLOCK_INTERRUPT_ENABLE: 0x%llx\n",
17827Sjchu 	    CSR_XR(xbc_csr_base, JBC_CORE_AND_BLOCK_INTERRUPT_ENABLE));
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate 	/*
18127Sjchu 	 * CSR_V CB's interrupt regs (log, enable, status, clear)
1820Sstevel@tonic-gate 	 */
18327Sjchu 	DBG(DBG_CB, NULL, "hvio_cb_init, JBC_ERROR_LOG_ENABLE: 0x%llx\n",
18427Sjchu 	    CSR_XR(xbc_csr_base, JBC_ERROR_LOG_ENABLE));
18527Sjchu 
1860Sstevel@tonic-gate 	DBG(DBG_CB, NULL, "hvio_cb_init, JBC_INTERRUPT_ENABLE: 0x%llx\n",
18727Sjchu 	    CSR_XR(xbc_csr_base, JBC_INTERRUPT_ENABLE));
18827Sjchu 
18927Sjchu 	DBG(DBG_CB, NULL, "hvio_cb_init, JBC_INTERRUPT_STATUS: 0x%llx\n",
19027Sjchu 	    CSR_XR(xbc_csr_base, JBC_INTERRUPT_STATUS));
19127Sjchu 
1920Sstevel@tonic-gate 	DBG(DBG_CB, NULL, "hvio_cb_init, JBC_ERROR_STATUS_CLEAR: 0x%llx\n",
19327Sjchu 	    CSR_XR(xbc_csr_base, JBC_ERROR_STATUS_CLEAR));
1940Sstevel@tonic-gate }
1950Sstevel@tonic-gate 
19627Sjchu /*
19727Sjchu  * Initialize the module, but do not enable interrupts.
19827Sjchu  */
1990Sstevel@tonic-gate /* ARGSUSED */
2000Sstevel@tonic-gate void
2010Sstevel@tonic-gate hvio_ib_init(caddr_t csr_base, pxu_t *pxu_p)
2020Sstevel@tonic-gate {
2030Sstevel@tonic-gate 	/*
20427Sjchu 	 * CSR_V IB's interrupt regs (log, enable, status, clear)
2050Sstevel@tonic-gate 	 */
2060Sstevel@tonic-gate 	DBG(DBG_IB, NULL, "hvio_ib_init - IMU_ERROR_LOG_ENABLE: 0x%llx\n",
20727Sjchu 	    CSR_XR(csr_base, IMU_ERROR_LOG_ENABLE));
20827Sjchu 
2090Sstevel@tonic-gate 	DBG(DBG_IB, NULL, "hvio_ib_init - IMU_INTERRUPT_ENABLE: 0x%llx\n",
21027Sjchu 	    CSR_XR(csr_base, IMU_INTERRUPT_ENABLE));
21127Sjchu 
2120Sstevel@tonic-gate 	DBG(DBG_IB, NULL, "hvio_ib_init - IMU_INTERRUPT_STATUS: 0x%llx\n",
21327Sjchu 	    CSR_XR(csr_base, IMU_INTERRUPT_STATUS));
21427Sjchu 
2150Sstevel@tonic-gate 	DBG(DBG_IB, NULL, "hvio_ib_init - IMU_ERROR_STATUS_CLEAR: 0x%llx\n",
21627Sjchu 	    CSR_XR(csr_base, IMU_ERROR_STATUS_CLEAR));
2170Sstevel@tonic-gate }
2180Sstevel@tonic-gate 
21927Sjchu /*
22027Sjchu  * Initialize the module, but do not enable interrupts.
22127Sjchu  */
2220Sstevel@tonic-gate /* ARGSUSED */
2230Sstevel@tonic-gate static void
2240Sstevel@tonic-gate ilu_init(caddr_t csr_base, pxu_t *pxu_p)
2250Sstevel@tonic-gate {
2260Sstevel@tonic-gate 	/*
22727Sjchu 	 * CSR_V ILU's interrupt regs (log, enable, status, clear)
2280Sstevel@tonic-gate 	 */
22927Sjchu 	DBG(DBG_ILU, NULL, "ilu_init - ILU_ERROR_LOG_ENABLE: 0x%llx\n",
23027Sjchu 	    CSR_XR(csr_base, ILU_ERROR_LOG_ENABLE));
23127Sjchu 
2320Sstevel@tonic-gate 	DBG(DBG_ILU, NULL, "ilu_init - ILU_INTERRUPT_ENABLE: 0x%llx\n",
23327Sjchu 	    CSR_XR(csr_base, ILU_INTERRUPT_ENABLE));
23427Sjchu 
2350Sstevel@tonic-gate 	DBG(DBG_ILU, NULL, "ilu_init - ILU_INTERRUPT_STATUS: 0x%llx\n",
23627Sjchu 	    CSR_XR(csr_base, ILU_INTERRUPT_STATUS));
23727Sjchu 
2380Sstevel@tonic-gate 	DBG(DBG_ILU, NULL, "ilu_init - ILU_ERROR_STATUS_CLEAR: 0x%llx\n",
23927Sjchu 	    CSR_XR(csr_base, ILU_ERROR_STATUS_CLEAR));
2400Sstevel@tonic-gate }
2410Sstevel@tonic-gate 
24227Sjchu /*
24327Sjchu  * Initialize the module, but do not enable interrupts.
24427Sjchu  */
245*225Sess /* ARGSUSED */
2460Sstevel@tonic-gate static void
2470Sstevel@tonic-gate tlu_init(caddr_t csr_base, pxu_t *pxu_p)
2480Sstevel@tonic-gate {
2490Sstevel@tonic-gate 	uint64_t val;
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate 	/*
2520Sstevel@tonic-gate 	 * CSR_V TLU_CONTROL Expect OBP ???
2530Sstevel@tonic-gate 	 */
2540Sstevel@tonic-gate 
2550Sstevel@tonic-gate 	/*
2560Sstevel@tonic-gate 	 * L0s entry default timer value - 7.0 us
2570Sstevel@tonic-gate 	 * Completion timeout select default value - 67.1 ms and
2580Sstevel@tonic-gate 	 * OBP will set this value.
2590Sstevel@tonic-gate 	 *
2600Sstevel@tonic-gate 	 * Configuration - Bit 0 should always be 0 for upstream port.
2610Sstevel@tonic-gate 	 * Bit 1 is clock - how is this related to the clock bit in TLU
2620Sstevel@tonic-gate 	 * Link Control register?  Both are hardware dependent and likely
2630Sstevel@tonic-gate 	 * set by OBP.
2640Sstevel@tonic-gate 	 *
2650Sstevel@tonic-gate 	 * Disable non-posted write bit - ordering by setting
2660Sstevel@tonic-gate 	 * NPWR_EN bit to force serialization of writes.
2670Sstevel@tonic-gate 	 */
2680Sstevel@tonic-gate 	val = CSR_XR(csr_base, TLU_CONTROL);
269*225Sess 	val |= (TLU_CONTROL_L0S_TIM_DEFAULT << TLU_CONTROL_L0S_TIM) |
270*225Sess 	    (1ull << TLU_CONTROL_NPWR_EN) | TLU_CONTROL_CONFIG_DEFAULT;
2710Sstevel@tonic-gate 
272118Sjchu 	/*
273118Sjchu 	 * Set Detect.Quiet. This will disable automatic link
274118Sjchu 	 * re-training, if the link goes down e.g. power management
275118Sjchu 	 * turns off power to the downstream device. This will enable
276118Sjchu 	 * Fire to go to Drain state, after link down. The drain state
277118Sjchu 	 * forces a reset to the FC state machine, which is required for
278118Sjchu 	 * proper link re-training.
279118Sjchu 	 */
280118Sjchu 	val |= (1ull << TLU_REMAIN_DETECT_QUIET);
2810Sstevel@tonic-gate 	CSR_XS(csr_base, TLU_CONTROL, val);
2820Sstevel@tonic-gate 	DBG(DBG_TLU, NULL, "tlu_init - TLU_CONTROL: 0x%llx\n",
2830Sstevel@tonic-gate 	    CSR_XR(csr_base, TLU_CONTROL));
2840Sstevel@tonic-gate 
2850Sstevel@tonic-gate 	/*
2860Sstevel@tonic-gate 	 * CSR_V TLU_STATUS Expect HW 0x4
2870Sstevel@tonic-gate 	 */
2880Sstevel@tonic-gate 
2890Sstevel@tonic-gate 	/*
2900Sstevel@tonic-gate 	 * Only bit [7:0] are currently defined.  Bits [2:0]
2910Sstevel@tonic-gate 	 * are the state, which should likely be in state active,
2920Sstevel@tonic-gate 	 * 100b.  Bit three is 'recovery', which is not understood.
2930Sstevel@tonic-gate 	 * All other bits are reserved.
2940Sstevel@tonic-gate 	 */
2950Sstevel@tonic-gate 	DBG(DBG_TLU, NULL, "tlu_init - TLU_STATUS: 0x%llx\n",
29627Sjchu 	    CSR_XR(csr_base, TLU_STATUS));
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate 	/*
2990Sstevel@tonic-gate 	 * CSR_V TLU_PME_TURN_OFF_GENERATE Expect HW 0x0
3000Sstevel@tonic-gate 	 */
3010Sstevel@tonic-gate 	DBG(DBG_TLU, NULL, "tlu_init - TLU_PME_TURN_OFF_GENERATE: 0x%llx\n",
30227Sjchu 	    CSR_XR(csr_base, TLU_PME_TURN_OFF_GENERATE));
3030Sstevel@tonic-gate 
3040Sstevel@tonic-gate 	/*
3050Sstevel@tonic-gate 	 * CSR_V TLU_INGRESS_CREDITS_INITIAL Expect HW 0x10000200C0
3060Sstevel@tonic-gate 	 */
3070Sstevel@tonic-gate 
3080Sstevel@tonic-gate 	/*
3090Sstevel@tonic-gate 	 * Ingress credits initial register.  Bits [39:32] should be
3100Sstevel@tonic-gate 	 * 0x10, bits [19:12] should be 0x20, and bits [11:0] should
3110Sstevel@tonic-gate 	 * be 0xC0.  These are the reset values, and should be set by
3120Sstevel@tonic-gate 	 * HW.
3130Sstevel@tonic-gate 	 */
3140Sstevel@tonic-gate 	DBG(DBG_TLU, NULL, "tlu_init - TLU_INGRESS_CREDITS_INITIAL: 0x%llx\n",
31527Sjchu 	    CSR_XR(csr_base, TLU_INGRESS_CREDITS_INITIAL));
3160Sstevel@tonic-gate 
3170Sstevel@tonic-gate 	/*
3180Sstevel@tonic-gate 	 * CSR_V TLU_DIAGNOSTIC Expect HW 0x0
3190Sstevel@tonic-gate 	 */
3200Sstevel@tonic-gate 
3210Sstevel@tonic-gate 	/*
3220Sstevel@tonic-gate 	 * Diagnostic register - always zero unless we are debugging.
3230Sstevel@tonic-gate 	 */
3240Sstevel@tonic-gate 	DBG(DBG_TLU, NULL, "tlu_init - TLU_DIAGNOSTIC: 0x%llx\n",
32527Sjchu 	    CSR_XR(csr_base, TLU_DIAGNOSTIC));
3260Sstevel@tonic-gate 
3270Sstevel@tonic-gate 	/*
3280Sstevel@tonic-gate 	 * CSR_V TLU_EGRESS_CREDITS_CONSUMED Expect HW 0x0
3290Sstevel@tonic-gate 	 */
3300Sstevel@tonic-gate 	DBG(DBG_TLU, NULL, "tlu_init - TLU_EGRESS_CREDITS_CONSUMED: 0x%llx\n",
33127Sjchu 	    CSR_XR(csr_base, TLU_EGRESS_CREDITS_CONSUMED));
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate 	/*
3340Sstevel@tonic-gate 	 * CSR_V TLU_EGRESS_CREDIT_LIMIT Expect HW 0x0
3350Sstevel@tonic-gate 	 */
3360Sstevel@tonic-gate 	DBG(DBG_TLU, NULL, "tlu_init - TLU_EGRESS_CREDIT_LIMIT: 0x%llx\n",
33727Sjchu 	    CSR_XR(csr_base, TLU_EGRESS_CREDIT_LIMIT));
3380Sstevel@tonic-gate 
3390Sstevel@tonic-gate 	/*
3400Sstevel@tonic-gate 	 * CSR_V TLU_EGRESS_RETRY_BUFFER Expect HW 0x0
3410Sstevel@tonic-gate 	 */
3420Sstevel@tonic-gate 	DBG(DBG_TLU, NULL, "tlu_init - TLU_EGRESS_RETRY_BUFFER: 0x%llx\n",
34327Sjchu 	    CSR_XR(csr_base, TLU_EGRESS_RETRY_BUFFER));
3440Sstevel@tonic-gate 
3450Sstevel@tonic-gate 	/*
3460Sstevel@tonic-gate 	 * CSR_V TLU_INGRESS_CREDITS_ALLOCATED Expected HW 0x0
3470Sstevel@tonic-gate 	 */
3480Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
34927Sjchu 	    "tlu_init - TLU_INGRESS_CREDITS_ALLOCATED: 0x%llx\n",
35027Sjchu 	    CSR_XR(csr_base, TLU_INGRESS_CREDITS_ALLOCATED));
3510Sstevel@tonic-gate 
3520Sstevel@tonic-gate 	/*
3530Sstevel@tonic-gate 	 * CSR_V TLU_INGRESS_CREDITS_RECEIVED Expected HW 0x0
3540Sstevel@tonic-gate 	 */
3550Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
35627Sjchu 	    "tlu_init - TLU_INGRESS_CREDITS_RECEIVED: 0x%llx\n",
35727Sjchu 	    CSR_XR(csr_base, TLU_INGRESS_CREDITS_RECEIVED));
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate 	/*
36027Sjchu 	 * CSR_V TLU's interrupt regs (log, enable, status, clear)
3610Sstevel@tonic-gate 	 */
3620Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
36327Sjchu 	    "tlu_init - TLU_OTHER_EVENT_LOG_ENABLE: 0x%llx\n",
36427Sjchu 	    CSR_XR(csr_base, TLU_OTHER_EVENT_LOG_ENABLE));
36527Sjchu 
3660Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
36727Sjchu 	    "tlu_init - TLU_OTHER_EVENT_INTERRUPT_ENABLE: 0x%llx\n",
36827Sjchu 	    CSR_XR(csr_base, TLU_OTHER_EVENT_INTERRUPT_ENABLE));
36927Sjchu 
37027Sjchu 	DBG(DBG_TLU, NULL,
37127Sjchu 	    "tlu_init - TLU_OTHER_EVENT_INTERRUPT_STATUS: 0x%llx\n",
37227Sjchu 	    CSR_XR(csr_base, TLU_OTHER_EVENT_INTERRUPT_STATUS));
37327Sjchu 
37427Sjchu 	DBG(DBG_TLU, NULL,
37527Sjchu 	    "tlu_init - TLU_OTHER_EVENT_STATUS_CLEAR: 0x%llx\n",
37627Sjchu 	    CSR_XR(csr_base, TLU_OTHER_EVENT_STATUS_CLEAR));
3770Sstevel@tonic-gate 
3780Sstevel@tonic-gate 	/*
3790Sstevel@tonic-gate 	 * CSR_V TLU_RECEIVE_OTHER_EVENT_HEADER1_LOG Expect HW 0x0
3800Sstevel@tonic-gate 	 */
3810Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
38227Sjchu 	    "tlu_init - TLU_RECEIVE_OTHER_EVENT_HEADER1_LOG: 0x%llx\n",
38327Sjchu 	    CSR_XR(csr_base, TLU_RECEIVE_OTHER_EVENT_HEADER1_LOG));
3840Sstevel@tonic-gate 
3850Sstevel@tonic-gate 	/*
3860Sstevel@tonic-gate 	 * CSR_V TLU_RECEIVE_OTHER_EVENT_HEADER2_LOG Expect HW 0x0
3870Sstevel@tonic-gate 	 */
3880Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
38927Sjchu 	    "tlu_init - TLU_RECEIVE_OTHER_EVENT_HEADER2_LOG: 0x%llx\n",
39027Sjchu 	    CSR_XR(csr_base, TLU_RECEIVE_OTHER_EVENT_HEADER2_LOG));
3910Sstevel@tonic-gate 
3920Sstevel@tonic-gate 	/*
3930Sstevel@tonic-gate 	 * CSR_V TLU_TRANSMIT_OTHER_EVENT_HEADER1_LOG Expect HW 0x0
3940Sstevel@tonic-gate 	 */
3950Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
39627Sjchu 	    "tlu_init - TLU_TRANSMIT_OTHER_EVENT_HEADER1_LOG: 0x%llx\n",
39727Sjchu 	    CSR_XR(csr_base, TLU_TRANSMIT_OTHER_EVENT_HEADER1_LOG));
3980Sstevel@tonic-gate 
3990Sstevel@tonic-gate 	/*
4000Sstevel@tonic-gate 	 * CSR_V TLU_TRANSMIT_OTHER_EVENT_HEADER2_LOG Expect HW 0x0
4010Sstevel@tonic-gate 	 */
4020Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
40327Sjchu 	    "tlu_init - TLU_TRANSMIT_OTHER_EVENT_HEADER2_LOG: 0x%llx\n",
40427Sjchu 	    CSR_XR(csr_base, TLU_TRANSMIT_OTHER_EVENT_HEADER2_LOG));
4050Sstevel@tonic-gate 
4060Sstevel@tonic-gate 	/*
4070Sstevel@tonic-gate 	 * CSR_V TLU_PERFORMANCE_COUNTER_SELECT Expect HW 0x0
4080Sstevel@tonic-gate 	 */
4090Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
41027Sjchu 	    "tlu_init - TLU_PERFORMANCE_COUNTER_SELECT: 0x%llx\n",
41127Sjchu 	    CSR_XR(csr_base, TLU_PERFORMANCE_COUNTER_SELECT));
4120Sstevel@tonic-gate 
4130Sstevel@tonic-gate 	/*
4140Sstevel@tonic-gate 	 * CSR_V TLU_PERFORMANCE_COUNTER_ZERO Expect HW 0x0
4150Sstevel@tonic-gate 	 */
4160Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
41727Sjchu 	    "tlu_init - TLU_PERFORMANCE_COUNTER_ZERO: 0x%llx\n",
41827Sjchu 	    CSR_XR(csr_base, TLU_PERFORMANCE_COUNTER_ZERO));
4190Sstevel@tonic-gate 
4200Sstevel@tonic-gate 	/*
4210Sstevel@tonic-gate 	 * CSR_V TLU_PERFORMANCE_COUNTER_ONE Expect HW 0x0
4220Sstevel@tonic-gate 	 */
4230Sstevel@tonic-gate 	DBG(DBG_TLU, NULL, "tlu_init - TLU_PERFORMANCE_COUNTER_ONE: 0x%llx\n",
42427Sjchu 	    CSR_XR(csr_base, TLU_PERFORMANCE_COUNTER_ONE));
4250Sstevel@tonic-gate 
4260Sstevel@tonic-gate 	/*
4270Sstevel@tonic-gate 	 * CSR_V TLU_PERFORMANCE_COUNTER_TWO Expect HW 0x0
4280Sstevel@tonic-gate 	 */
4290Sstevel@tonic-gate 	DBG(DBG_TLU, NULL, "tlu_init - TLU_PERFORMANCE_COUNTER_TWO: 0x%llx\n",
43027Sjchu 	    CSR_XR(csr_base, TLU_PERFORMANCE_COUNTER_TWO));
4310Sstevel@tonic-gate 
4320Sstevel@tonic-gate 	/*
4330Sstevel@tonic-gate 	 * CSR_V TLU_DEBUG_SELECT_A Expect HW 0x0
4340Sstevel@tonic-gate 	 */
4350Sstevel@tonic-gate 
4360Sstevel@tonic-gate 	DBG(DBG_TLU, NULL, "tlu_init - TLU_DEBUG_SELECT_A: 0x%llx\n",
43727Sjchu 	    CSR_XR(csr_base, TLU_DEBUG_SELECT_A));
4380Sstevel@tonic-gate 
4390Sstevel@tonic-gate 	/*
4400Sstevel@tonic-gate 	 * CSR_V TLU_DEBUG_SELECT_B Expect HW 0x0
4410Sstevel@tonic-gate 	 */
4420Sstevel@tonic-gate 	DBG(DBG_TLU, NULL, "tlu_init - TLU_DEBUG_SELECT_B: 0x%llx\n",
44327Sjchu 	    CSR_XR(csr_base, TLU_DEBUG_SELECT_B));
4440Sstevel@tonic-gate 
4450Sstevel@tonic-gate 	/*
4460Sstevel@tonic-gate 	 * CSR_V TLU_DEVICE_CAPABILITIES Expect HW 0xFC2
4470Sstevel@tonic-gate 	 */
4480Sstevel@tonic-gate 	DBG(DBG_TLU, NULL, "tlu_init - TLU_DEVICE_CAPABILITIES: 0x%llx\n",
44927Sjchu 	    CSR_XR(csr_base, TLU_DEVICE_CAPABILITIES));
4500Sstevel@tonic-gate 
4510Sstevel@tonic-gate 	/*
4520Sstevel@tonic-gate 	 * CSR_V TLU_DEVICE_CONTROL Expect HW 0x0
4530Sstevel@tonic-gate 	 */
4540Sstevel@tonic-gate 
4550Sstevel@tonic-gate 	/*
4560Sstevel@tonic-gate 	 * Bits [14:12] are the Max Read Request Size, which is always 64
4570Sstevel@tonic-gate 	 * bytes which is 000b.  Bits [7:5] are Max Payload Size, which
4580Sstevel@tonic-gate 	 * start at 128 bytes which is 000b.  This may be revisited if
4590Sstevel@tonic-gate 	 * init_child finds greater values.
4600Sstevel@tonic-gate 	 */
4610Sstevel@tonic-gate 	val = 0x0ull;
4620Sstevel@tonic-gate 	CSR_XS(csr_base, TLU_DEVICE_CONTROL, val);
4630Sstevel@tonic-gate 	DBG(DBG_TLU, NULL, "tlu_init - TLU_DEVICE_CONTROL: 0x%llx\n",
46427Sjchu 	    CSR_XR(csr_base, TLU_DEVICE_CONTROL));
4650Sstevel@tonic-gate 
4660Sstevel@tonic-gate 	/*
4670Sstevel@tonic-gate 	 * CSR_V TLU_DEVICE_STATUS Expect HW 0x0
4680Sstevel@tonic-gate 	 */
4690Sstevel@tonic-gate 	DBG(DBG_TLU, NULL, "tlu_init - TLU_DEVICE_STATUS: 0x%llx\n",
47027Sjchu 	    CSR_XR(csr_base, TLU_DEVICE_STATUS));
4710Sstevel@tonic-gate 
4720Sstevel@tonic-gate 	/*
4730Sstevel@tonic-gate 	 * CSR_V TLU_LINK_CAPABILITIES Expect HW 0x15C81
4740Sstevel@tonic-gate 	 */
4750Sstevel@tonic-gate 	DBG(DBG_TLU, NULL, "tlu_init - TLU_LINK_CAPABILITIES: 0x%llx\n",
47627Sjchu 	    CSR_XR(csr_base, TLU_LINK_CAPABILITIES));
4770Sstevel@tonic-gate 
4780Sstevel@tonic-gate 	/*
4790Sstevel@tonic-gate 	 * CSR_V TLU_LINK_CONTROL Expect OBP 0x40
4800Sstevel@tonic-gate 	 */
4810Sstevel@tonic-gate 
4820Sstevel@tonic-gate 	/*
4830Sstevel@tonic-gate 	 * The CLOCK bit should be set by OBP if the hardware dictates,
4840Sstevel@tonic-gate 	 * and if it is set then ASPM should be used since then L0s exit
4850Sstevel@tonic-gate 	 * latency should be lower than L1 exit latency.
4860Sstevel@tonic-gate 	 *
4870Sstevel@tonic-gate 	 * Note that we will not enable power management during bringup
4880Sstevel@tonic-gate 	 * since it has not been test and is creating some problems in
4890Sstevel@tonic-gate 	 * simulation.
4900Sstevel@tonic-gate 	 */
4910Sstevel@tonic-gate 	val = (1ull << TLU_LINK_CONTROL_CLOCK);
4920Sstevel@tonic-gate 
4930Sstevel@tonic-gate 	CSR_XS(csr_base, TLU_LINK_CONTROL, val);
4940Sstevel@tonic-gate 	DBG(DBG_TLU, NULL, "tlu_init - TLU_LINK_CONTROL: 0x%llx\n",
49527Sjchu 	    CSR_XR(csr_base, TLU_LINK_CONTROL));
4960Sstevel@tonic-gate 
4970Sstevel@tonic-gate 	/*
4980Sstevel@tonic-gate 	 * CSR_V TLU_LINK_STATUS Expect OBP 0x1011
4990Sstevel@tonic-gate 	 */
5000Sstevel@tonic-gate 
5010Sstevel@tonic-gate 	/*
5020Sstevel@tonic-gate 	 * Not sure if HW or OBP will be setting this read only
5030Sstevel@tonic-gate 	 * register.  Bit 12 is Clock, and it should always be 1
5040Sstevel@tonic-gate 	 * signifying that the component uses the same physical
5050Sstevel@tonic-gate 	 * clock as the platform.  Bits [9:4] are for the width,
5060Sstevel@tonic-gate 	 * with the expected value above signifying a x1 width.
5070Sstevel@tonic-gate 	 * Bits [3:0] are the speed, with 1b signifying 2.5 Gb/s,
5080Sstevel@tonic-gate 	 * the only speed as yet supported by the PCI-E spec.
5090Sstevel@tonic-gate 	 */
5100Sstevel@tonic-gate 	DBG(DBG_TLU, NULL, "tlu_init - TLU_LINK_STATUS: 0x%llx\n",
51127Sjchu 	    CSR_XR(csr_base, TLU_LINK_STATUS));
5120Sstevel@tonic-gate 
5130Sstevel@tonic-gate 	/*
5140Sstevel@tonic-gate 	 * CSR_V TLU_SLOT_CAPABILITIES Expect OBP ???
5150Sstevel@tonic-gate 	 */
5160Sstevel@tonic-gate 
5170Sstevel@tonic-gate 	/*
5180Sstevel@tonic-gate 	 * Power Limits for the slots.  Will be platform
5190Sstevel@tonic-gate 	 * dependent, and OBP will need to set after consulting
5200Sstevel@tonic-gate 	 * with the HW guys.
5210Sstevel@tonic-gate 	 *
5220Sstevel@tonic-gate 	 * Bits [16:15] are power limit scale, which most likely
5230Sstevel@tonic-gate 	 * will be 0b signifying 1x.  Bits [14:7] are the Set
5240Sstevel@tonic-gate 	 * Power Limit Value, which is a number which is multiplied
5250Sstevel@tonic-gate 	 * by the power limit scale to get the actual power limit.
5260Sstevel@tonic-gate 	 */
5270Sstevel@tonic-gate 	DBG(DBG_TLU, NULL, "tlu_init - TLU_SLOT_CAPABILITIES: 0x%llx\n",
52827Sjchu 	    CSR_XR(csr_base, TLU_SLOT_CAPABILITIES));
5290Sstevel@tonic-gate 
5300Sstevel@tonic-gate 	/*
5310Sstevel@tonic-gate 	 * CSR_V TLU_UNCORRECTABLE_ERROR_LOG_ENABLE Expect Kernel 0x17F011
5320Sstevel@tonic-gate 	 */
5330Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
53427Sjchu 	    "tlu_init - TLU_UNCORRECTABLE_ERROR_LOG_ENABLE: 0x%llx\n",
53527Sjchu 	    CSR_XR(csr_base, TLU_UNCORRECTABLE_ERROR_LOG_ENABLE));
5360Sstevel@tonic-gate 
5370Sstevel@tonic-gate 	/*
53827Sjchu 	 * CSR_V TLU_UNCORRECTABLE_ERROR_INTERRUPT_ENABLE Expect
53927Sjchu 	 * Kernel 0x17F0110017F011
5400Sstevel@tonic-gate 	 */
5410Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
54227Sjchu 	    "tlu_init - TLU_UNCORRECTABLE_ERROR_INTERRUPT_ENABLE: 0x%llx\n",
54327Sjchu 	    CSR_XR(csr_base, TLU_UNCORRECTABLE_ERROR_INTERRUPT_ENABLE));
5440Sstevel@tonic-gate 
5450Sstevel@tonic-gate 	/*
5460Sstevel@tonic-gate 	 * CSR_V TLU_UNCORRECTABLE_ERROR_INTERRUPT_STATUS Expect HW 0x0
5470Sstevel@tonic-gate 	 */
5480Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
54927Sjchu 	    "tlu_init - TLU_UNCORRECTABLE_ERROR_INTERRUPT_STATUS: 0x%llx\n",
55027Sjchu 	    CSR_XR(csr_base, TLU_UNCORRECTABLE_ERROR_INTERRUPT_STATUS));
5510Sstevel@tonic-gate 
5520Sstevel@tonic-gate 	/*
5530Sstevel@tonic-gate 	 * CSR_V TLU_UNCORRECTABLE_ERROR_STATUS_CLEAR Expect HW 0x0
5540Sstevel@tonic-gate 	 */
5550Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
55627Sjchu 	    "tlu_init - TLU_UNCORRECTABLE_ERROR_STATUS_CLEAR: 0x%llx\n",
55727Sjchu 	    CSR_XR(csr_base, TLU_UNCORRECTABLE_ERROR_STATUS_CLEAR));
5580Sstevel@tonic-gate 
5590Sstevel@tonic-gate 	/*
5600Sstevel@tonic-gate 	 * CSR_V TLU_RECEIVE_UNCORRECTABLE_ERROR_HEADER1_LOG HW 0x0
5610Sstevel@tonic-gate 	 */
5620Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
5630Sstevel@tonic-gate 	    "tlu_init - TLU_RECEIVE_UNCORRECTABLE_ERROR_HEADER1_LOG: 0x%llx\n",
5640Sstevel@tonic-gate 	    CSR_XR(csr_base, TLU_RECEIVE_UNCORRECTABLE_ERROR_HEADER1_LOG));
5650Sstevel@tonic-gate 
5660Sstevel@tonic-gate 	/*
5670Sstevel@tonic-gate 	 * CSR_V TLU_RECEIVE_UNCORRECTABLE_ERROR_HEADER2_LOG HW 0x0
5680Sstevel@tonic-gate 	 */
5690Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
5700Sstevel@tonic-gate 	    "tlu_init - TLU_RECEIVE_UNCORRECTABLE_ERROR_HEADER2_LOG: 0x%llx\n",
5710Sstevel@tonic-gate 	    CSR_XR(csr_base, TLU_RECEIVE_UNCORRECTABLE_ERROR_HEADER2_LOG));
5720Sstevel@tonic-gate 
5730Sstevel@tonic-gate 	/*
5740Sstevel@tonic-gate 	 * CSR_V TLU_TRANSMIT_UNCORRECTABLE_ERROR_HEADER1_LOG HW 0x0
5750Sstevel@tonic-gate 	 */
5760Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
5770Sstevel@tonic-gate 	    "tlu_init - TLU_TRANSMIT_UNCORRECTABLE_ERROR_HEADER1_LOG: 0x%llx\n",
5780Sstevel@tonic-gate 	    CSR_XR(csr_base, TLU_TRANSMIT_UNCORRECTABLE_ERROR_HEADER1_LOG));
5790Sstevel@tonic-gate 
5800Sstevel@tonic-gate 	/*
5810Sstevel@tonic-gate 	 * CSR_V TLU_TRANSMIT_UNCORRECTABLE_ERROR_HEADER2_LOG HW 0x0
5820Sstevel@tonic-gate 	 */
5830Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
5840Sstevel@tonic-gate 	    "tlu_init - TLU_TRANSMIT_UNCORRECTABLE_ERROR_HEADER2_LOG: 0x%llx\n",
5850Sstevel@tonic-gate 	    CSR_XR(csr_base, TLU_TRANSMIT_UNCORRECTABLE_ERROR_HEADER2_LOG));
5860Sstevel@tonic-gate 
58727Sjchu 
5880Sstevel@tonic-gate 	/*
58927Sjchu 	 * CSR_V TLU's CE interrupt regs (log, enable, status, clear)
59027Sjchu 	 * Plus header logs
5910Sstevel@tonic-gate 	 */
5920Sstevel@tonic-gate 
5930Sstevel@tonic-gate 	/*
59427Sjchu 	 * CSR_V TLU_CORRECTABLE_ERROR_LOG_ENABLE Expect Kernel 0x11C1
5950Sstevel@tonic-gate 	 */
5960Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
59727Sjchu 	    "tlu_init - TLU_CORRECTABLE_ERROR_LOG_ENABLE: 0x%llx\n",
59827Sjchu 	    CSR_XR(csr_base, TLU_CORRECTABLE_ERROR_LOG_ENABLE));
5990Sstevel@tonic-gate 
6000Sstevel@tonic-gate 	/*
6010Sstevel@tonic-gate 	 * CSR_V TLU_CORRECTABLE_ERROR_INTERRUPT_ENABLE Kernel 0x11C1000011C1
6020Sstevel@tonic-gate 	 */
6030Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
60427Sjchu 	    "tlu_init - TLU_CORRECTABLE_ERROR_INTERRUPT_ENABLE: 0x%llx\n",
60527Sjchu 	    CSR_XR(csr_base, TLU_CORRECTABLE_ERROR_INTERRUPT_ENABLE));
6060Sstevel@tonic-gate 
6070Sstevel@tonic-gate 	/*
6080Sstevel@tonic-gate 	 * CSR_V TLU_CORRECTABLE_ERROR_INTERRUPT_STATUS Expect HW 0x0
6090Sstevel@tonic-gate 	 */
6100Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
61127Sjchu 	    "tlu_init - TLU_CORRECTABLE_ERROR_INTERRUPT_STATUS: 0x%llx\n",
61227Sjchu 	    CSR_XR(csr_base, TLU_CORRECTABLE_ERROR_INTERRUPT_STATUS));
6130Sstevel@tonic-gate 
6140Sstevel@tonic-gate 	/*
6150Sstevel@tonic-gate 	 * CSR_V TLU_CORRECTABLE_ERROR_STATUS_CLEAR Expect HW 0x0
6160Sstevel@tonic-gate 	 */
6170Sstevel@tonic-gate 	DBG(DBG_TLU, NULL,
61827Sjchu 	    "tlu_init - TLU_CORRECTABLE_ERROR_STATUS_CLEAR: 0x%llx\n",
61927Sjchu 	    CSR_XR(csr_base, TLU_CORRECTABLE_ERROR_STATUS_CLEAR));
6200Sstevel@tonic-gate }
6210Sstevel@tonic-gate 
622*225Sess /* ARGSUSED */
6230Sstevel@tonic-gate static void
6240Sstevel@tonic-gate lpu_init(caddr_t csr_base, pxu_t *pxu_p)
6250Sstevel@tonic-gate {
6260Sstevel@tonic-gate 	/* Variables used to set the ACKNAK Latency Timer and Replay Timer */
6270Sstevel@tonic-gate 	int link_width, max_payload;
6280Sstevel@tonic-gate 
6290Sstevel@tonic-gate 	uint64_t val;
6300Sstevel@tonic-gate 
6310Sstevel@tonic-gate 	/*
6320Sstevel@tonic-gate 	 * ACKNAK Latency Threshold Table.
6330Sstevel@tonic-gate 	 * See Fire PRM 2.0 section 1.2.12.2, table 1-17.
6340Sstevel@tonic-gate 	 */
6350Sstevel@tonic-gate 	int acknak_timer_table[LINK_MAX_PKT_ARR_SIZE][LINK_WIDTH_ARR_SIZE] = {
6360Sstevel@tonic-gate 		{0xED,   0x49,  0x43,  0x30},
6370Sstevel@tonic-gate 		{0x1A0,  0x76,  0x6B,  0x48},
6380Sstevel@tonic-gate 		{0x22F,  0x9A,  0x56,  0x56},
6390Sstevel@tonic-gate 		{0x42F,  0x11A, 0x96,  0x96},
6400Sstevel@tonic-gate 		{0x82F,  0x21A, 0x116, 0x116},
6410Sstevel@tonic-gate 		{0x102F, 0x41A, 0x216, 0x216}
6420Sstevel@tonic-gate 	};
6430Sstevel@tonic-gate 
6440Sstevel@tonic-gate 	/*
6450Sstevel@tonic-gate 	 * TxLink Replay Timer Latency Table
6460Sstevel@tonic-gate 	 * See Fire PRM 2.0 sections 1.2.12.3, table 1-18.
6470Sstevel@tonic-gate 	 */
6480Sstevel@tonic-gate 	int replay_timer_table[LINK_MAX_PKT_ARR_SIZE][LINK_WIDTH_ARR_SIZE] = {
6490Sstevel@tonic-gate 		{0x379,  0x112, 0xFC,  0xB4},
6500Sstevel@tonic-gate 		{0x618,  0x1BA, 0x192, 0x10E},
6510Sstevel@tonic-gate 		{0x831,  0x242, 0x143, 0x143},
6520Sstevel@tonic-gate 		{0xFB1,  0x422, 0x233, 0x233},
6530Sstevel@tonic-gate 		{0x1EB0, 0x7E1, 0x412, 0x412},
6540Sstevel@tonic-gate 		{0x3CB0, 0xF61, 0x7D2, 0x7D2}
6550Sstevel@tonic-gate 	};
656*225Sess 
6570Sstevel@tonic-gate 	/*
6580Sstevel@tonic-gate 	 * Get the Link Width.  See table above LINK_WIDTH_ARR_SIZE #define
6590Sstevel@tonic-gate 	 * Only Link Widths of x1, x4, and x8 are supported.
6600Sstevel@tonic-gate 	 * If any width is reported other than x8, set default to x8.
6610Sstevel@tonic-gate 	 */
6620Sstevel@tonic-gate 	link_width = CSR_FR(csr_base, TLU_LINK_STATUS, WIDTH);
6630Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - Link Width: x%d\n", link_width);
6640Sstevel@tonic-gate 
6650Sstevel@tonic-gate 	/*
6660Sstevel@tonic-gate 	 * Convert link_width to match timer array configuration.
6670Sstevel@tonic-gate 	 */
6680Sstevel@tonic-gate 	switch (link_width) {
6690Sstevel@tonic-gate 	case 1:
6700Sstevel@tonic-gate 		link_width = 0;
6710Sstevel@tonic-gate 		break;
6720Sstevel@tonic-gate 	case 4:
6730Sstevel@tonic-gate 		link_width = 1;
6740Sstevel@tonic-gate 		break;
6750Sstevel@tonic-gate 	case 8:
6760Sstevel@tonic-gate 		link_width = 2;
6770Sstevel@tonic-gate 		break;
6780Sstevel@tonic-gate 	case 16:
6790Sstevel@tonic-gate 		link_width = 3;
6800Sstevel@tonic-gate 		break;
6810Sstevel@tonic-gate 	default:
6820Sstevel@tonic-gate 		link_width = 0;
6830Sstevel@tonic-gate 	}
6840Sstevel@tonic-gate 
6850Sstevel@tonic-gate 	/*
6860Sstevel@tonic-gate 	 * Get the Max Payload Size.
6870Sstevel@tonic-gate 	 * See table above LINK_MAX_PKT_ARR_SIZE #define
6880Sstevel@tonic-gate 	 */
689*225Sess 	max_payload = ((CSR_FR(csr_base, TLU_CONTROL, CONFIG) &
690*225Sess 	    TLU_CONTROL_MPS_MASK) >> TLU_CONTROL_MPS_SHIFT);
6910Sstevel@tonic-gate 
6920Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - May Payload: %d\n",
6930Sstevel@tonic-gate 	    (0x80 << max_payload));
6940Sstevel@tonic-gate 
6950Sstevel@tonic-gate 	/* Make sure the packet size is not greater than 4096 */
6960Sstevel@tonic-gate 	max_payload = (max_payload >= LINK_MAX_PKT_ARR_SIZE) ?
6970Sstevel@tonic-gate 	    (LINK_MAX_PKT_ARR_SIZE - 1) : max_payload;
6980Sstevel@tonic-gate 
6990Sstevel@tonic-gate 	/*
7000Sstevel@tonic-gate 	 * CSR_V LPU_ID Expect HW 0x0
7010Sstevel@tonic-gate 	 */
7020Sstevel@tonic-gate 
7030Sstevel@tonic-gate 	/*
7040Sstevel@tonic-gate 	 * This register has link id, phy id and gigablaze id.
7050Sstevel@tonic-gate 	 * Should be set by HW.
7060Sstevel@tonic-gate 	 */
7070Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_ID: 0x%llx\n",
70827Sjchu 	    CSR_XR(csr_base, LPU_ID));
7090Sstevel@tonic-gate 
7100Sstevel@tonic-gate 	/*
7110Sstevel@tonic-gate 	 * CSR_V LPU_RESET Expect Kernel 0x0
7120Sstevel@tonic-gate 	 */
7130Sstevel@tonic-gate 
7140Sstevel@tonic-gate 	/*
7150Sstevel@tonic-gate 	 * No reason to have any reset bits high until an error is
7160Sstevel@tonic-gate 	 * detected on the link.
7170Sstevel@tonic-gate 	 */
7180Sstevel@tonic-gate 	val = 0ull;
7190Sstevel@tonic-gate 	CSR_XS(csr_base, LPU_RESET, val);
7200Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_RESET: 0x%llx\n",
72127Sjchu 	    CSR_XR(csr_base, LPU_RESET));
7220Sstevel@tonic-gate 
7230Sstevel@tonic-gate 	/*
7240Sstevel@tonic-gate 	 * CSR_V LPU_DEBUG_STATUS Expect HW 0x0
7250Sstevel@tonic-gate 	 */
7260Sstevel@tonic-gate 
7270Sstevel@tonic-gate 	/*
7280Sstevel@tonic-gate 	 * Bits [15:8] are Debug B, and bit [7:0] are Debug A.
7290Sstevel@tonic-gate 	 * They are read-only.  What do the 8 bits mean, and
7300Sstevel@tonic-gate 	 * how do they get set if they are read only?
7310Sstevel@tonic-gate 	 */
7320Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_DEBUG_STATUS: 0x%llx\n",
73327Sjchu 	    CSR_XR(csr_base, LPU_DEBUG_STATUS));
7340Sstevel@tonic-gate 
7350Sstevel@tonic-gate 	/*
7360Sstevel@tonic-gate 	 * CSR_V LPU_DEBUG_CONFIG Expect Kernel 0x0
7370Sstevel@tonic-gate 	 */
7380Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_DEBUG_CONFIG: 0x%llx\n",
73927Sjchu 	    CSR_XR(csr_base, LPU_DEBUG_CONFIG));
7400Sstevel@tonic-gate 
7410Sstevel@tonic-gate 	/*
7420Sstevel@tonic-gate 	 * CSR_V LPU_LTSSM_CONTROL Expect HW 0x0
7430Sstevel@tonic-gate 	 */
7440Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_LTSSM_CONTROL: 0x%llx\n",
74527Sjchu 	    CSR_XR(csr_base, LPU_LTSSM_CONTROL));
7460Sstevel@tonic-gate 
7470Sstevel@tonic-gate 	/*
7480Sstevel@tonic-gate 	 * CSR_V LPU_LINK_STATUS Expect HW 0x101
7490Sstevel@tonic-gate 	 */
7500Sstevel@tonic-gate 
7510Sstevel@tonic-gate 	/*
7520Sstevel@tonic-gate 	 * This register has bits [9:4] for link width, and the
7530Sstevel@tonic-gate 	 * default 0x10, means a width of x16.  The problem is
7540Sstevel@tonic-gate 	 * this width is not supported according to the TLU
7550Sstevel@tonic-gate 	 * link status register.
7560Sstevel@tonic-gate 	 */
7570Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_LINK_STATUS: 0x%llx\n",
75827Sjchu 	    CSR_XR(csr_base, LPU_LINK_STATUS));
7590Sstevel@tonic-gate 
7600Sstevel@tonic-gate 	/*
7610Sstevel@tonic-gate 	 * CSR_V LPU_INTERRUPT_STATUS Expect HW 0x0
7620Sstevel@tonic-gate 	 */
7630Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_INTERRUPT_STATUS: 0x%llx\n",
76427Sjchu 	    CSR_XR(csr_base, LPU_INTERRUPT_STATUS));
7650Sstevel@tonic-gate 
7660Sstevel@tonic-gate 	/*
7670Sstevel@tonic-gate 	 * CSR_V LPU_INTERRUPT_MASK Expect HW 0x0
7680Sstevel@tonic-gate 	 */
7690Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_INTERRUPT_MASK: 0x%llx\n",
77027Sjchu 	    CSR_XR(csr_base, LPU_INTERRUPT_MASK));
7710Sstevel@tonic-gate 
7720Sstevel@tonic-gate 	/*
7730Sstevel@tonic-gate 	 * CSR_V LPU_LINK_PERFORMANCE_COUNTER_SELECT Expect HW 0x0
7740Sstevel@tonic-gate 	 */
7750Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
77627Sjchu 	    "lpu_init - LPU_LINK_PERFORMANCE_COUNTER_SELECT: 0x%llx\n",
77727Sjchu 	    CSR_XR(csr_base, LPU_LINK_PERFORMANCE_COUNTER_SELECT));
7780Sstevel@tonic-gate 
7790Sstevel@tonic-gate 	/*
7800Sstevel@tonic-gate 	 * CSR_V LPU_LINK_PERFORMANCE_COUNTER_CONTROL Expect HW 0x0
7810Sstevel@tonic-gate 	 */
7820Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
78327Sjchu 	    "lpu_init - LPU_LINK_PERFORMANCE_COUNTER_CONTROL: 0x%llx\n",
78427Sjchu 	    CSR_XR(csr_base, LPU_LINK_PERFORMANCE_COUNTER_CONTROL));
7850Sstevel@tonic-gate 
7860Sstevel@tonic-gate 	/*
7870Sstevel@tonic-gate 	 * CSR_V LPU_LINK_PERFORMANCE_COUNTER1 Expect HW 0x0
7880Sstevel@tonic-gate 	 */
7890Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
79027Sjchu 	    "lpu_init - LPU_LINK_PERFORMANCE_COUNTER1: 0x%llx\n",
79127Sjchu 	    CSR_XR(csr_base, LPU_LINK_PERFORMANCE_COUNTER1));
7920Sstevel@tonic-gate 
7930Sstevel@tonic-gate 	/*
7940Sstevel@tonic-gate 	 * CSR_V LPU_LINK_PERFORMANCE_COUNTER1_TEST Expect HW 0x0
7950Sstevel@tonic-gate 	 */
7960Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
79727Sjchu 	    "lpu_init - LPU_LINK_PERFORMANCE_COUNTER1_TEST: 0x%llx\n",
79827Sjchu 	    CSR_XR(csr_base, LPU_LINK_PERFORMANCE_COUNTER1_TEST));
7990Sstevel@tonic-gate 
8000Sstevel@tonic-gate 	/*
8010Sstevel@tonic-gate 	 * CSR_V LPU_LINK_PERFORMANCE_COUNTER2 Expect HW 0x0
8020Sstevel@tonic-gate 	 */
8030Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
80427Sjchu 	    "lpu_init - LPU_LINK_PERFORMANCE_COUNTER2: 0x%llx\n",
80527Sjchu 	    CSR_XR(csr_base, LPU_LINK_PERFORMANCE_COUNTER2));
8060Sstevel@tonic-gate 
8070Sstevel@tonic-gate 	/*
8080Sstevel@tonic-gate 	 * CSR_V LPU_LINK_PERFORMANCE_COUNTER2_TEST Expect HW 0x0
8090Sstevel@tonic-gate 	 */
8100Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
81127Sjchu 	    "lpu_init - LPU_LINK_PERFORMANCE_COUNTER2_TEST: 0x%llx\n",
81227Sjchu 	    CSR_XR(csr_base, LPU_LINK_PERFORMANCE_COUNTER2_TEST));
8130Sstevel@tonic-gate 
8140Sstevel@tonic-gate 	/*
8150Sstevel@tonic-gate 	 * CSR_V LPU_LINK_LAYER_CONFIG Expect HW 0x100
8160Sstevel@tonic-gate 	 */
8170Sstevel@tonic-gate 
8180Sstevel@tonic-gate 	/*
8190Sstevel@tonic-gate 	 * This is another place where Max Payload can be set,
8200Sstevel@tonic-gate 	 * this time for the link layer.  It will be set to
8210Sstevel@tonic-gate 	 * 128B, which is the default, but this will need to
8220Sstevel@tonic-gate 	 * be revisited.
8230Sstevel@tonic-gate 	 */
8240Sstevel@tonic-gate 	val = (1ull << LPU_LINK_LAYER_CONFIG_VC0_EN);
8250Sstevel@tonic-gate 	CSR_XS(csr_base, LPU_LINK_LAYER_CONFIG, val);
8260Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_LINK_LAYER_CONFIG: 0x%llx\n",
82727Sjchu 	    CSR_XR(csr_base, LPU_LINK_LAYER_CONFIG));
8280Sstevel@tonic-gate 
8290Sstevel@tonic-gate 	/*
8300Sstevel@tonic-gate 	 * CSR_V LPU_LINK_LAYER_STATUS Expect OBP 0x5
8310Sstevel@tonic-gate 	 */
8320Sstevel@tonic-gate 
8330Sstevel@tonic-gate 	/*
8340Sstevel@tonic-gate 	 * Another R/W status register.  Bit 3, DL up Status, will
8350Sstevel@tonic-gate 	 * be set high.  The link state machine status bits [2:0]
8360Sstevel@tonic-gate 	 * are set to 0x1, but the status bits are not defined in the
8370Sstevel@tonic-gate 	 * PRM.  What does 0x1 mean, what others values are possible
8380Sstevel@tonic-gate 	 * and what are thier meanings?
8390Sstevel@tonic-gate 	 *
8400Sstevel@tonic-gate 	 * This register has been giving us problems in simulation.
8410Sstevel@tonic-gate 	 * It has been mentioned that software should not program
8420Sstevel@tonic-gate 	 * any registers with WE bits except during debug.  So
8430Sstevel@tonic-gate 	 * this register will no longer be programmed.
8440Sstevel@tonic-gate 	 */
8450Sstevel@tonic-gate 
8460Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_LINK_LAYER_STATUS: 0x%llx\n",
84727Sjchu 	    CSR_XR(csr_base, LPU_LINK_LAYER_STATUS));
8480Sstevel@tonic-gate 
8490Sstevel@tonic-gate 	/*
8500Sstevel@tonic-gate 	 * CSR_V LPU_LINK_LAYER_INTERRUPT_AND_STATUS_TEST Expect HW 0x0
8510Sstevel@tonic-gate 	 */
8520Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
85327Sjchu 	    "lpu_init - LPU_LINK_LAYER_INTERRUPT_AND_STATUS_TEST: 0x%llx\n",
85427Sjchu 	    CSR_XR(csr_base, LPU_LINK_LAYER_INTERRUPT_AND_STATUS_TEST));
8550Sstevel@tonic-gate 
8560Sstevel@tonic-gate 	/*
85727Sjchu 	 * CSR_V LPU Link Layer interrupt regs (mask, status)
8580Sstevel@tonic-gate 	 */
8590Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
86027Sjchu 	    "lpu_init - LPU_LINK_LAYER_INTERRUPT_MASK: 0x%llx\n",
86127Sjchu 	    CSR_XR(csr_base, LPU_LINK_LAYER_INTERRUPT_MASK));
86227Sjchu 
86327Sjchu 	DBG(DBG_LPU, NULL,
86427Sjchu 	    "lpu_init - LPU_LINK_LAYER_INTERRUPT_AND_STATUS: 0x%llx\n",
86527Sjchu 	    CSR_XR(csr_base, LPU_LINK_LAYER_INTERRUPT_AND_STATUS));
8660Sstevel@tonic-gate 
8670Sstevel@tonic-gate 	/*
8680Sstevel@tonic-gate 	 * CSR_V LPU_FLOW_CONTROL_UPDATE_CONTROL Expect OBP 0x7
8690Sstevel@tonic-gate 	 */
8700Sstevel@tonic-gate 
8710Sstevel@tonic-gate 	/*
8720Sstevel@tonic-gate 	 * The PRM says that only the first two bits will be set
8730Sstevel@tonic-gate 	 * high by default, which will enable flow control for
8740Sstevel@tonic-gate 	 * posted and non-posted updates, but NOT completetion
8750Sstevel@tonic-gate 	 * updates.
8760Sstevel@tonic-gate 	 */
8770Sstevel@tonic-gate 	val = (1ull << LPU_FLOW_CONTROL_UPDATE_CONTROL_FC0_U_NP_EN) |
87827Sjchu 	    (1ull << LPU_FLOW_CONTROL_UPDATE_CONTROL_FC0_U_P_EN);
8790Sstevel@tonic-gate 	CSR_XS(csr_base, LPU_FLOW_CONTROL_UPDATE_CONTROL, val);
8800Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
88127Sjchu 	    "lpu_init - LPU_FLOW_CONTROL_UPDATE_CONTROL: 0x%llx\n",
88227Sjchu 	    CSR_XR(csr_base, LPU_FLOW_CONTROL_UPDATE_CONTROL));
8830Sstevel@tonic-gate 
8840Sstevel@tonic-gate 	/*
8850Sstevel@tonic-gate 	 * CSR_V LPU_LINK_LAYER_FLOW_CONTROL_UPDATE_TIMEOUT_VALUE
8860Sstevel@tonic-gate 	 * Expect OBP 0x1D4C
8870Sstevel@tonic-gate 	 */
8880Sstevel@tonic-gate 
8890Sstevel@tonic-gate 	/*
8900Sstevel@tonic-gate 	 * This should be set by OBP.  We'll check to make sure.
8910Sstevel@tonic-gate 	 */
89227Sjchu 	DBG(DBG_LPU, NULL, "lpu_init - "
89327Sjchu 	    "LPU_LINK_LAYER_FLOW_CONTROL_UPDATE_TIMEOUT_VALUE: 0x%llx\n",
89427Sjchu 	    CSR_XR(csr_base,
89527Sjchu 	    LPU_LINK_LAYER_FLOW_CONTROL_UPDATE_TIMEOUT_VALUE));
8960Sstevel@tonic-gate 
8970Sstevel@tonic-gate 	/*
8980Sstevel@tonic-gate 	 * CSR_V LPU_LINK_LAYER_VC0_FLOW_CONTROL_UPDATE_TIMER0 Expect OBP ???
8990Sstevel@tonic-gate 	 */
9000Sstevel@tonic-gate 
9010Sstevel@tonic-gate 	/*
9020Sstevel@tonic-gate 	 * This register has Flow Control Update Timer values for
9030Sstevel@tonic-gate 	 * non-posted and posted requests, bits [30:16] and bits
9040Sstevel@tonic-gate 	 * [14:0], respectively.  These are read-only to SW so
9050Sstevel@tonic-gate 	 * either HW or OBP needs to set them.
9060Sstevel@tonic-gate 	 */
90727Sjchu 	DBG(DBG_LPU, NULL, "lpu_init - "
90827Sjchu 	    "LPU_LINK_LAYER_VC0_FLOW_CONTROL_UPDATE_TIMER0: 0x%llx\n",
90927Sjchu 	    CSR_XR(csr_base,
91027Sjchu 	    LPU_LINK_LAYER_VC0_FLOW_CONTROL_UPDATE_TIMER0));
9110Sstevel@tonic-gate 
9120Sstevel@tonic-gate 	/*
9130Sstevel@tonic-gate 	 * CSR_V LPU_LINK_LAYER_VC0_FLOW_CONTROL_UPDATE_TIMER1 Expect OBP ???
9140Sstevel@tonic-gate 	 */
9150Sstevel@tonic-gate 
9160Sstevel@tonic-gate 	/*
9170Sstevel@tonic-gate 	 * Same as timer0 register above, except for bits [14:0]
9180Sstevel@tonic-gate 	 * have the timer values for completetions.  Read-only to
9190Sstevel@tonic-gate 	 * SW; OBP or HW need to set it.
9200Sstevel@tonic-gate 	 */
92127Sjchu 	DBG(DBG_LPU, NULL, "lpu_init - "
92227Sjchu 	    "LPU_LINK_LAYER_VC0_FLOW_CONTROL_UPDATE_TIMER1: 0x%llx\n",
92327Sjchu 	    CSR_XR(csr_base,
92427Sjchu 	    LPU_LINK_LAYER_VC0_FLOW_CONTROL_UPDATE_TIMER1));
9250Sstevel@tonic-gate 
9260Sstevel@tonic-gate 	/*
9270Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_FREQUENT_NAK_LATENCY_TIMER_THRESHOLD
9280Sstevel@tonic-gate 	 */
929*225Sess 	val = acknak_timer_table[max_payload][link_width];
930*225Sess 	CSR_XS(csr_base, LPU_TXLINK_FREQUENT_NAK_LATENCY_TIMER_THRESHOLD, val);
9310Sstevel@tonic-gate 
9320Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - "
9330Sstevel@tonic-gate 	    "LPU_TXLINK_FREQUENT_NAK_LATENCY_TIMER_THRESHOLD: 0x%llx\n",
9340Sstevel@tonic-gate 	    CSR_XR(csr_base, LPU_TXLINK_FREQUENT_NAK_LATENCY_TIMER_THRESHOLD));
9350Sstevel@tonic-gate 
9360Sstevel@tonic-gate 	/*
9370Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_ACKNAK_LATENCY_TIMER Expect HW 0x0
9380Sstevel@tonic-gate 	 */
9390Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
94027Sjchu 	    "lpu_init - LPU_TXLINK_ACKNAK_LATENCY_TIMER: 0x%llx\n",
94127Sjchu 	    CSR_XR(csr_base, LPU_TXLINK_ACKNAK_LATENCY_TIMER));
9420Sstevel@tonic-gate 
9430Sstevel@tonic-gate 	/*
9440Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_REPLAY_TIMER_THRESHOLD
9450Sstevel@tonic-gate 	 */
946*225Sess 	val = replay_timer_table[max_payload][link_width];
9470Sstevel@tonic-gate 	CSR_XS(csr_base, LPU_TXLINK_REPLAY_TIMER_THRESHOLD, val);
9480Sstevel@tonic-gate 
9490Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
9500Sstevel@tonic-gate 	    "lpu_init - LPU_TXLINK_REPLAY_TIMER_THRESHOLD: 0x%llx\n",
9510Sstevel@tonic-gate 	    CSR_XR(csr_base, LPU_TXLINK_REPLAY_TIMER_THRESHOLD));
9520Sstevel@tonic-gate 
9530Sstevel@tonic-gate 	/*
9540Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_REPLAY_TIMER Expect HW 0x0
9550Sstevel@tonic-gate 	 */
9560Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_TXLINK_REPLAY_TIMER: 0x%llx\n",
95727Sjchu 	    CSR_XR(csr_base, LPU_TXLINK_REPLAY_TIMER));
9580Sstevel@tonic-gate 
9590Sstevel@tonic-gate 	/*
9600Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_REPLAY_NUMBER_STATUS Expect OBP 0x3
9610Sstevel@tonic-gate 	 */
9620Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
96327Sjchu 	    "lpu_init - LPU_TXLINK_REPLAY_NUMBER_STATUS: 0x%llx\n",
96427Sjchu 	    CSR_XR(csr_base, LPU_TXLINK_REPLAY_NUMBER_STATUS));
9650Sstevel@tonic-gate 
9660Sstevel@tonic-gate 	/*
9670Sstevel@tonic-gate 	 * CSR_V LPU_REPLAY_BUFFER_MAX_ADDRESS Expect OBP 0xB3F
9680Sstevel@tonic-gate 	 */
9690Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
9700Sstevel@tonic-gate 	    "lpu_init - LPU_REPLAY_BUFFER_MAX_ADDRESS: 0x%llx\n",
9710Sstevel@tonic-gate 	    CSR_XR(csr_base, LPU_REPLAY_BUFFER_MAX_ADDRESS));
9720Sstevel@tonic-gate 
9730Sstevel@tonic-gate 	/*
9740Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_RETRY_FIFO_POINTER Expect OBP 0xFFFF0000
9750Sstevel@tonic-gate 	 */
9760Sstevel@tonic-gate 	val = ((LPU_TXLINK_RETRY_FIFO_POINTER_RTRY_FIFO_TLPTR_DEFAULT <<
97727Sjchu 	    LPU_TXLINK_RETRY_FIFO_POINTER_RTRY_FIFO_TLPTR) |
97827Sjchu 	    (LPU_TXLINK_RETRY_FIFO_POINTER_RTRY_FIFO_HDPTR_DEFAULT <<
97927Sjchu 	    LPU_TXLINK_RETRY_FIFO_POINTER_RTRY_FIFO_HDPTR));
9800Sstevel@tonic-gate 
9810Sstevel@tonic-gate 	CSR_XS(csr_base, LPU_TXLINK_RETRY_FIFO_POINTER, val);
9820Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
98327Sjchu 	    "lpu_init - LPU_TXLINK_RETRY_FIFO_POINTER: 0x%llx\n",
98427Sjchu 	    CSR_XR(csr_base, LPU_TXLINK_RETRY_FIFO_POINTER));
9850Sstevel@tonic-gate 
9860Sstevel@tonic-gate 	/*
9870Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_RETRY_FIFO_R_W_POINTER Expect OBP 0x0
9880Sstevel@tonic-gate 	 */
9890Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
9900Sstevel@tonic-gate 	    "lpu_init - LPU_TXLINK_RETRY_FIFO_R_W_POINTER: 0x%llx\n",
9910Sstevel@tonic-gate 	    CSR_XR(csr_base, LPU_TXLINK_RETRY_FIFO_R_W_POINTER));
9920Sstevel@tonic-gate 
9930Sstevel@tonic-gate 	/*
9940Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_RETRY_FIFO_CREDIT Expect HW 0x1580
9950Sstevel@tonic-gate 	 */
9960Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
99727Sjchu 	    "lpu_init - LPU_TXLINK_RETRY_FIFO_CREDIT: 0x%llx\n",
99827Sjchu 	    CSR_XR(csr_base, LPU_TXLINK_RETRY_FIFO_CREDIT));
9990Sstevel@tonic-gate 
10000Sstevel@tonic-gate 	/*
10010Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_SEQUENCE_COUNTER Expect OBP 0xFFF0000
10020Sstevel@tonic-gate 	 */
10030Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_TXLINK_SEQUENCE_COUNTER: 0x%llx\n",
100427Sjchu 	    CSR_XR(csr_base, LPU_TXLINK_SEQUENCE_COUNTER));
10050Sstevel@tonic-gate 
10060Sstevel@tonic-gate 	/*
10070Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_ACK_SENT_SEQUENCE_NUMBER Expect HW 0xFFF
10080Sstevel@tonic-gate 	 */
10090Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
101027Sjchu 	    "lpu_init - LPU_TXLINK_ACK_SENT_SEQUENCE_NUMBER: 0x%llx\n",
101127Sjchu 	    CSR_XR(csr_base, LPU_TXLINK_ACK_SENT_SEQUENCE_NUMBER));
10120Sstevel@tonic-gate 
10130Sstevel@tonic-gate 	/*
10140Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_SEQUENCE_COUNT_FIFO_MAX_ADDR Expect OBP 0x157
10150Sstevel@tonic-gate 	 */
10160Sstevel@tonic-gate 
10170Sstevel@tonic-gate 	/*
10180Sstevel@tonic-gate 	 * Test only register.  Will not be programmed.
10190Sstevel@tonic-gate 	 */
10200Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
102127Sjchu 	    "lpu_init - LPU_TXLINK_SEQUENCE_COUNT_FIFO_MAX_ADDR: 0x%llx\n",
102227Sjchu 	    CSR_XR(csr_base, LPU_TXLINK_SEQUENCE_COUNT_FIFO_MAX_ADDR));
10230Sstevel@tonic-gate 
10240Sstevel@tonic-gate 	/*
10250Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_SEQUENCE_COUNT_FIFO_POINTERS Expect HW 0xFFF0000
10260Sstevel@tonic-gate 	 */
10270Sstevel@tonic-gate 
10280Sstevel@tonic-gate 	/*
10290Sstevel@tonic-gate 	 * Test only register.  Will not be programmed.
10300Sstevel@tonic-gate 	 */
10310Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
103227Sjchu 	    "lpu_init - LPU_TXLINK_SEQUENCE_COUNT_FIFO_POINTERS: 0x%llx\n",
103327Sjchu 	    CSR_XR(csr_base, LPU_TXLINK_SEQUENCE_COUNT_FIFO_POINTERS));
10340Sstevel@tonic-gate 
10350Sstevel@tonic-gate 	/*
10360Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_SEQUENCE_COUNT_R_W_POINTERS Expect HW 0x0
10370Sstevel@tonic-gate 	 */
10380Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
103927Sjchu 	    "lpu_init - LPU_TXLINK_SEQUENCE_COUNT_R_W_POINTERS: 0x%llx\n",
104027Sjchu 	    CSR_XR(csr_base, LPU_TXLINK_SEQUENCE_COUNT_R_W_POINTERS));
10410Sstevel@tonic-gate 
10420Sstevel@tonic-gate 	/*
10430Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_TEST_CONTROL Expect HW 0x0
10440Sstevel@tonic-gate 	 */
10450Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_TXLINK_TEST_CONTROL: 0x%llx\n",
104627Sjchu 	    CSR_XR(csr_base, LPU_TXLINK_TEST_CONTROL));
10470Sstevel@tonic-gate 
10480Sstevel@tonic-gate 	/*
10490Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_MEMORY_ADDRESS_CONTROL Expect HW 0x0
10500Sstevel@tonic-gate 	 */
10510Sstevel@tonic-gate 
10520Sstevel@tonic-gate 	/*
10530Sstevel@tonic-gate 	 * Test only register.  Will not be programmed.
10540Sstevel@tonic-gate 	 */
10550Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
10560Sstevel@tonic-gate 	    "lpu_init - LPU_TXLINK_MEMORY_ADDRESS_CONTROL: 0x%llx\n",
10570Sstevel@tonic-gate 	    CSR_XR(csr_base, LPU_TXLINK_MEMORY_ADDRESS_CONTROL));
10580Sstevel@tonic-gate 
10590Sstevel@tonic-gate 	/*
10600Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_MEMORY_DATA_LOAD0 Expect HW 0x0
10610Sstevel@tonic-gate 	 */
10620Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
106327Sjchu 	    "lpu_init - LPU_TXLINK_MEMORY_DATA_LOAD0: 0x%llx\n",
106427Sjchu 	    CSR_XR(csr_base, LPU_TXLINK_MEMORY_DATA_LOAD0));
10650Sstevel@tonic-gate 
10660Sstevel@tonic-gate 	/*
10670Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_MEMORY_DATA_LOAD1 Expect HW 0x0
10680Sstevel@tonic-gate 	 */
10690Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
107027Sjchu 	    "lpu_init - LPU_TXLINK_MEMORY_DATA_LOAD1: 0x%llx\n",
107127Sjchu 	    CSR_XR(csr_base, LPU_TXLINK_MEMORY_DATA_LOAD1));
10720Sstevel@tonic-gate 
10730Sstevel@tonic-gate 	/*
10740Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_MEMORY_DATA_LOAD2 Expect HW 0x0
10750Sstevel@tonic-gate 	 */
10760Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
107727Sjchu 	    "lpu_init - LPU_TXLINK_MEMORY_DATA_LOAD2: 0x%llx\n",
107827Sjchu 	    CSR_XR(csr_base, LPU_TXLINK_MEMORY_DATA_LOAD2));
10790Sstevel@tonic-gate 
10800Sstevel@tonic-gate 	/*
10810Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_MEMORY_DATA_LOAD3 Expect HW 0x0
10820Sstevel@tonic-gate 	 */
10830Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
108427Sjchu 	    "lpu_init - LPU_TXLINK_MEMORY_DATA_LOAD3: 0x%llx\n",
108527Sjchu 	    CSR_XR(csr_base, LPU_TXLINK_MEMORY_DATA_LOAD3));
10860Sstevel@tonic-gate 
10870Sstevel@tonic-gate 	/*
10880Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_MEMORY_DATA_LOAD4 Expect HW 0x0
10890Sstevel@tonic-gate 	 */
10900Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
109127Sjchu 	    "lpu_init - LPU_TXLINK_MEMORY_DATA_LOAD4: 0x%llx\n",
109227Sjchu 	    CSR_XR(csr_base, LPU_TXLINK_MEMORY_DATA_LOAD4));
10930Sstevel@tonic-gate 
10940Sstevel@tonic-gate 	/*
10950Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_RETRY_DATA_COUNT Expect HW 0x0
10960Sstevel@tonic-gate 	 */
10970Sstevel@tonic-gate 
10980Sstevel@tonic-gate 	/*
10990Sstevel@tonic-gate 	 * Test only register.  Will not be programmed.
11000Sstevel@tonic-gate 	 */
11010Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_TXLINK_RETRY_DATA_COUNT: 0x%llx\n",
110227Sjchu 	    CSR_XR(csr_base, LPU_TXLINK_RETRY_DATA_COUNT));
11030Sstevel@tonic-gate 
11040Sstevel@tonic-gate 	/*
11050Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_SEQUENCE_BUFFER_COUNT Expect HW 0x0
11060Sstevel@tonic-gate 	 */
11070Sstevel@tonic-gate 
11080Sstevel@tonic-gate 	/*
11090Sstevel@tonic-gate 	 * Test only register.  Will not be programmed.
11100Sstevel@tonic-gate 	 */
11110Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
111227Sjchu 	    "lpu_init - LPU_TXLINK_SEQUENCE_BUFFER_COUNT: 0x%llx\n",
111327Sjchu 	    CSR_XR(csr_base, LPU_TXLINK_SEQUENCE_BUFFER_COUNT));
11140Sstevel@tonic-gate 
11150Sstevel@tonic-gate 	/*
11160Sstevel@tonic-gate 	 * CSR_V LPU_TXLINK_SEQUENCE_BUFFER_BOTTOM_DATA Expect HW 0x0
11170Sstevel@tonic-gate 	 */
11180Sstevel@tonic-gate 
11190Sstevel@tonic-gate 	/*
11200Sstevel@tonic-gate 	 * Test only register.
11210Sstevel@tonic-gate 	 */
11220Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
112327Sjchu 	    "lpu_init - LPU_TXLINK_SEQUENCE_BUFFER_BOTTOM_DATA: 0x%llx\n",
112427Sjchu 	    CSR_XR(csr_base, LPU_TXLINK_SEQUENCE_BUFFER_BOTTOM_DATA));
11250Sstevel@tonic-gate 
11260Sstevel@tonic-gate 	/*
11270Sstevel@tonic-gate 	 * CSR_V LPU_RXLINK_NEXT_RECEIVE_SEQUENCE_1_COUNTER Expect HW 0x0
11280Sstevel@tonic-gate 	 */
11290Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - "
113027Sjchu 	    "LPU_RXLINK_NEXT_RECEIVE_SEQUENCE_1_COUNTER: 0x%llx\n",
113127Sjchu 	    CSR_XR(csr_base, LPU_RXLINK_NEXT_RECEIVE_SEQUENCE_1_COUNTER));
11320Sstevel@tonic-gate 
11330Sstevel@tonic-gate 	/*
11340Sstevel@tonic-gate 	 * CSR_V LPU_RXLINK_UNSUPPORTED_DLLP_RECEIVED Expect HW 0x0
11350Sstevel@tonic-gate 	 */
11360Sstevel@tonic-gate 
11370Sstevel@tonic-gate 	/*
11380Sstevel@tonic-gate 	 * test only register.
11390Sstevel@tonic-gate 	 */
11400Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
114127Sjchu 	    "lpu_init - LPU_RXLINK_UNSUPPORTED_DLLP_RECEIVED: 0x%llx\n",
114227Sjchu 	    CSR_XR(csr_base, LPU_RXLINK_UNSUPPORTED_DLLP_RECEIVED));
11430Sstevel@tonic-gate 
11440Sstevel@tonic-gate 	/*
11450Sstevel@tonic-gate 	 * CSR_V LPU_RXLINK_TEST_CONTROL Expect HW 0x0
11460Sstevel@tonic-gate 	 */
11470Sstevel@tonic-gate 
11480Sstevel@tonic-gate 	/*
11490Sstevel@tonic-gate 	 * test only register.
11500Sstevel@tonic-gate 	 */
11510Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_RXLINK_TEST_CONTROL: 0x%llx\n",
115227Sjchu 	    CSR_XR(csr_base, LPU_RXLINK_TEST_CONTROL));
11530Sstevel@tonic-gate 
11540Sstevel@tonic-gate 	/*
11550Sstevel@tonic-gate 	 * CSR_V LPU_PHYSICAL_LAYER_CONFIGURATION Expect HW 0x10
11560Sstevel@tonic-gate 	 */
11570Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
115827Sjchu 	    "lpu_init - LPU_PHYSICAL_LAYER_CONFIGURATION: 0x%llx\n",
115927Sjchu 	    CSR_XR(csr_base, LPU_PHYSICAL_LAYER_CONFIGURATION));
11600Sstevel@tonic-gate 
11610Sstevel@tonic-gate 	/*
11620Sstevel@tonic-gate 	 * CSR_V LPU_PHY_LAYER_STATUS Expect HW 0x0
11630Sstevel@tonic-gate 	 */
11640Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_PHY_LAYER_STATUS: 0x%llx\n",
116527Sjchu 	    CSR_XR(csr_base, LPU_PHY_LAYER_STATUS));
11660Sstevel@tonic-gate 
11670Sstevel@tonic-gate 	/*
11680Sstevel@tonic-gate 	 * CSR_V LPU_PHY_INTERRUPT_AND_STATUS_TEST Expect HW 0x0
11690Sstevel@tonic-gate 	 */
11700Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
11710Sstevel@tonic-gate 	    "lpu_init - LPU_PHY_INTERRUPT_AND_STATUS_TEST: 0x%llx\n",
11720Sstevel@tonic-gate 	    CSR_XR(csr_base, LPU_PHY_INTERRUPT_AND_STATUS_TEST));
11730Sstevel@tonic-gate 
11740Sstevel@tonic-gate 	/*
117527Sjchu 	 * CSR_V LPU PHY LAYER interrupt regs (mask, status)
11760Sstevel@tonic-gate 	 */
11770Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_PHY_INTERRUPT_MASK: 0x%llx\n",
117827Sjchu 	    CSR_XR(csr_base, LPU_PHY_INTERRUPT_MASK));
117927Sjchu 
118027Sjchu 	DBG(DBG_LPU, NULL,
118127Sjchu 	    "lpu_init - LPU_PHY_LAYER_INTERRUPT_AND_STATUS: 0x%llx\n",
118227Sjchu 	    CSR_XR(csr_base, LPU_PHY_LAYER_INTERRUPT_AND_STATUS));
11830Sstevel@tonic-gate 
11840Sstevel@tonic-gate 	/*
11850Sstevel@tonic-gate 	 * CSR_V LPU_RECEIVE_PHY_CONFIG Expect HW 0x0
11860Sstevel@tonic-gate 	 */
11870Sstevel@tonic-gate 
11880Sstevel@tonic-gate 	/*
11890Sstevel@tonic-gate 	 * This also needs some explanation.  What is the best value
11900Sstevel@tonic-gate 	 * for the water mark?  Test mode enables which test mode?
11910Sstevel@tonic-gate 	 * Programming model needed for the Receiver Reset Lane N
11920Sstevel@tonic-gate 	 * bits.
11930Sstevel@tonic-gate 	 */
11940Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_RECEIVE_PHY_CONFIG: 0x%llx\n",
119527Sjchu 	    CSR_XR(csr_base, LPU_RECEIVE_PHY_CONFIG));
11960Sstevel@tonic-gate 
11970Sstevel@tonic-gate 	/*
11980Sstevel@tonic-gate 	 * CSR_V LPU_RECEIVE_PHY_STATUS1 Expect HW 0x0
11990Sstevel@tonic-gate 	 */
12000Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_RECEIVE_PHY_STATUS1: 0x%llx\n",
120127Sjchu 	    CSR_XR(csr_base, LPU_RECEIVE_PHY_STATUS1));
12020Sstevel@tonic-gate 
12030Sstevel@tonic-gate 	/*
12040Sstevel@tonic-gate 	 * CSR_V LPU_RECEIVE_PHY_STATUS2 Expect HW 0x0
12050Sstevel@tonic-gate 	 */
12060Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_RECEIVE_PHY_STATUS2: 0x%llx\n",
120727Sjchu 	    CSR_XR(csr_base, LPU_RECEIVE_PHY_STATUS2));
12080Sstevel@tonic-gate 
12090Sstevel@tonic-gate 	/*
12100Sstevel@tonic-gate 	 * CSR_V LPU_RECEIVE_PHY_STATUS3 Expect HW 0x0
12110Sstevel@tonic-gate 	 */
12120Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_RECEIVE_PHY_STATUS3: 0x%llx\n",
121327Sjchu 	    CSR_XR(csr_base, LPU_RECEIVE_PHY_STATUS3));
12140Sstevel@tonic-gate 
12150Sstevel@tonic-gate 	/*
12160Sstevel@tonic-gate 	 * CSR_V LPU_RECEIVE_PHY_INTERRUPT_AND_STATUS_TEST Expect HW 0x0
12170Sstevel@tonic-gate 	 */
12180Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
12190Sstevel@tonic-gate 	    "lpu_init - LPU_RECEIVE_PHY_INTERRUPT_AND_STATUS_TEST: 0x%llx\n",
12200Sstevel@tonic-gate 	    CSR_XR(csr_base, LPU_RECEIVE_PHY_INTERRUPT_AND_STATUS_TEST));
12210Sstevel@tonic-gate 
12220Sstevel@tonic-gate 	/*
122327Sjchu 	 * CSR_V LPU RX LAYER interrupt regs (mask, status)
12240Sstevel@tonic-gate 	 */
12250Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
122627Sjchu 	    "lpu_init - LPU_RECEIVE_PHY_INTERRUPT_MASK: 0x%llx\n",
122727Sjchu 	    CSR_XR(csr_base, LPU_RECEIVE_PHY_INTERRUPT_MASK));
122827Sjchu 
122927Sjchu 	DBG(DBG_LPU, NULL,
123027Sjchu 	    "lpu_init - LPU_RECEIVE_PHY_INTERRUPT_AND_STATUS: 0x%llx\n",
123127Sjchu 	    CSR_XR(csr_base, LPU_RECEIVE_PHY_INTERRUPT_AND_STATUS));
12320Sstevel@tonic-gate 
12330Sstevel@tonic-gate 	/*
12340Sstevel@tonic-gate 	 * CSR_V LPU_TRANSMIT_PHY_CONFIG Expect HW 0x0
12350Sstevel@tonic-gate 	 */
12360Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_TRANSMIT_PHY_CONFIG: 0x%llx\n",
123727Sjchu 	    CSR_XR(csr_base, LPU_TRANSMIT_PHY_CONFIG));
12380Sstevel@tonic-gate 
12390Sstevel@tonic-gate 	/*
12400Sstevel@tonic-gate 	 * CSR_V LPU_TRANSMIT_PHY_STATUS Expect HW 0x0
12410Sstevel@tonic-gate 	 */
12420Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_TRANSMIT_PHY_STATUS: 0x%llx\n",
12430Sstevel@tonic-gate 		CSR_XR(csr_base, LPU_TRANSMIT_PHY_STATUS));
12440Sstevel@tonic-gate 
12450Sstevel@tonic-gate 	/*
12460Sstevel@tonic-gate 	 * CSR_V LPU_TRANSMIT_PHY_INTERRUPT_AND_STATUS_TEST Expect HW 0x0
12470Sstevel@tonic-gate 	 */
12480Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
12490Sstevel@tonic-gate 	    "lpu_init - LPU_TRANSMIT_PHY_INTERRUPT_AND_STATUS_TEST: 0x%llx\n",
12500Sstevel@tonic-gate 	    CSR_XR(csr_base,
12510Sstevel@tonic-gate 	    LPU_TRANSMIT_PHY_INTERRUPT_AND_STATUS_TEST));
12520Sstevel@tonic-gate 
12530Sstevel@tonic-gate 	/*
125427Sjchu 	 * CSR_V LPU TX LAYER interrupt regs (mask, status)
12550Sstevel@tonic-gate 	 */
12560Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
125727Sjchu 	    "lpu_init - LPU_TRANSMIT_PHY_INTERRUPT_MASK: 0x%llx\n",
125827Sjchu 	    CSR_XR(csr_base, LPU_TRANSMIT_PHY_INTERRUPT_MASK));
125927Sjchu 
126027Sjchu 	DBG(DBG_LPU, NULL,
126127Sjchu 	    "lpu_init - LPU_TRANSMIT_PHY_INTERRUPT_AND_STATUS: 0x%llx\n",
126227Sjchu 	    CSR_XR(csr_base, LPU_TRANSMIT_PHY_INTERRUPT_AND_STATUS));
12630Sstevel@tonic-gate 
12640Sstevel@tonic-gate 	/*
12650Sstevel@tonic-gate 	 * CSR_V LPU_TRANSMIT_PHY_STATUS_2 Expect HW 0x0
12660Sstevel@tonic-gate 	 */
12670Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_TRANSMIT_PHY_STATUS_2: 0x%llx\n",
126827Sjchu 	    CSR_XR(csr_base, LPU_TRANSMIT_PHY_STATUS_2));
12690Sstevel@tonic-gate 
12700Sstevel@tonic-gate 	/*
12710Sstevel@tonic-gate 	 * CSR_V LPU_LTSSM_CONFIG1 Expect OBP 0x205
12720Sstevel@tonic-gate 	 */
12730Sstevel@tonic-gate 
12740Sstevel@tonic-gate 	/*
12750Sstevel@tonic-gate 	 * The new PRM has values for LTSSM 8 ns timeout value and
12760Sstevel@tonic-gate 	 * LTSSM 20 ns timeout value.  But what do these values mean?
12770Sstevel@tonic-gate 	 * Most of the other bits are questions as well.
12780Sstevel@tonic-gate 	 *
12790Sstevel@tonic-gate 	 * As such we will use the reset value.
12800Sstevel@tonic-gate 	 */
12810Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_LTSSM_CONFIG1: 0x%llx\n",
128227Sjchu 	    CSR_XR(csr_base, LPU_LTSSM_CONFIG1));
12830Sstevel@tonic-gate 
12840Sstevel@tonic-gate 	/*
12850Sstevel@tonic-gate 	 * CSR_V LPU_LTSSM_CONFIG2 Expect OBP 0x2DC6C0
12860Sstevel@tonic-gate 	 */
12870Sstevel@tonic-gate 
12880Sstevel@tonic-gate 	/*
12890Sstevel@tonic-gate 	 * Again, what does '12 ms timeout value mean'?
12900Sstevel@tonic-gate 	 */
12910Sstevel@tonic-gate 	val = (LPU_LTSSM_CONFIG2_LTSSM_12_TO_DEFAULT <<
129227Sjchu 	    LPU_LTSSM_CONFIG2_LTSSM_12_TO);
12930Sstevel@tonic-gate 	CSR_XS(csr_base, LPU_LTSSM_CONFIG2, val);
12940Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_LTSSM_CONFIG2: 0x%llx\n",
129527Sjchu 	    CSR_XR(csr_base, LPU_LTSSM_CONFIG2));
12960Sstevel@tonic-gate 
12970Sstevel@tonic-gate 	/*
12980Sstevel@tonic-gate 	 * CSR_V LPU_LTSSM_CONFIG3 Expect OBP 0x7A120
12990Sstevel@tonic-gate 	 */
13000Sstevel@tonic-gate 	val = (LPU_LTSSM_CONFIG3_LTSSM_2_TO_DEFAULT <<
130127Sjchu 	    LPU_LTSSM_CONFIG3_LTSSM_2_TO);
13020Sstevel@tonic-gate 	CSR_XS(csr_base, LPU_LTSSM_CONFIG3, val);
13030Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_LTSSM_CONFIG3: 0x%llx\n",
130427Sjchu 	    CSR_XR(csr_base, LPU_LTSSM_CONFIG3));
13050Sstevel@tonic-gate 
13060Sstevel@tonic-gate 	/*
13070Sstevel@tonic-gate 	 * CSR_V LPU_LTSSM_CONFIG4 Expect OBP 0x21300
13080Sstevel@tonic-gate 	 */
13090Sstevel@tonic-gate 	val = ((LPU_LTSSM_CONFIG4_DATA_RATE_DEFAULT <<
131027Sjchu 	    LPU_LTSSM_CONFIG4_DATA_RATE) |
13110Sstevel@tonic-gate 		(LPU_LTSSM_CONFIG4_N_FTS_DEFAULT <<
13120Sstevel@tonic-gate 		LPU_LTSSM_CONFIG4_N_FTS));
13130Sstevel@tonic-gate 	CSR_XS(csr_base, LPU_LTSSM_CONFIG4, val);
13140Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_LTSSM_CONFIG4: 0x%llx\n",
131527Sjchu 	    CSR_XR(csr_base, LPU_LTSSM_CONFIG4));
13160Sstevel@tonic-gate 
13170Sstevel@tonic-gate 	/*
13180Sstevel@tonic-gate 	 * CSR_V LPU_LTSSM_CONFIG5 Expect OBP 0x0
13190Sstevel@tonic-gate 	 */
13200Sstevel@tonic-gate 	val = 0ull;
13210Sstevel@tonic-gate 	CSR_XS(csr_base, LPU_LTSSM_CONFIG5, val);
13220Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_LTSSM_CONFIG5: 0x%llx\n",
132327Sjchu 	    CSR_XR(csr_base, LPU_LTSSM_CONFIG5));
13240Sstevel@tonic-gate 
13250Sstevel@tonic-gate 	/*
13260Sstevel@tonic-gate 	 * CSR_V LPU_LTSSM_STATUS1 Expect OBP 0x0
13270Sstevel@tonic-gate 	 */
13280Sstevel@tonic-gate 
13290Sstevel@tonic-gate 	/*
13300Sstevel@tonic-gate 	 * LTSSM Status registers are test only.
13310Sstevel@tonic-gate 	 */
13320Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_LTSSM_STATUS1: 0x%llx\n",
133327Sjchu 	    CSR_XR(csr_base, LPU_LTSSM_STATUS1));
13340Sstevel@tonic-gate 
13350Sstevel@tonic-gate 	/*
13360Sstevel@tonic-gate 	 * CSR_V LPU_LTSSM_STATUS2 Expect OBP 0x0
13370Sstevel@tonic-gate 	 */
13380Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_LTSSM_STATUS2: 0x%llx\n",
133927Sjchu 	    CSR_XR(csr_base, LPU_LTSSM_STATUS2));
13400Sstevel@tonic-gate 
13410Sstevel@tonic-gate 	/*
13420Sstevel@tonic-gate 	 * CSR_V LPU_LTSSM_INTERRUPT_AND_STATUS_TEST Expect HW 0x0
13430Sstevel@tonic-gate 	 */
13440Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
134527Sjchu 	    "lpu_init - LPU_LTSSM_INTERRUPT_AND_STATUS_TEST: 0x%llx\n",
134627Sjchu 	    CSR_XR(csr_base, LPU_LTSSM_INTERRUPT_AND_STATUS_TEST));
13470Sstevel@tonic-gate 
13480Sstevel@tonic-gate 	/*
134927Sjchu 	 * CSR_V LPU LTSSM  LAYER interrupt regs (mask, status)
13500Sstevel@tonic-gate 	 */
13510Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_LTSSM_INTERRUPT_MASK: 0x%llx\n",
135227Sjchu 	    CSR_XR(csr_base, LPU_LTSSM_INTERRUPT_MASK));
135327Sjchu 
135427Sjchu 	DBG(DBG_LPU, NULL,
135527Sjchu 	    "lpu_init - LPU_LTSSM_INTERRUPT_AND_STATUS: 0x%llx\n",
135627Sjchu 	    CSR_XR(csr_base, LPU_LTSSM_INTERRUPT_AND_STATUS));
13570Sstevel@tonic-gate 
13580Sstevel@tonic-gate 	/*
13590Sstevel@tonic-gate 	 * CSR_V LPU_LTSSM_STATUS_WRITE_ENABLE Expect OBP 0x0
13600Sstevel@tonic-gate 	 */
13610Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
136227Sjchu 	    "lpu_init - LPU_LTSSM_STATUS_WRITE_ENABLE: 0x%llx\n",
136327Sjchu 	    CSR_XR(csr_base, LPU_LTSSM_STATUS_WRITE_ENABLE));
13640Sstevel@tonic-gate 
13650Sstevel@tonic-gate 	/*
13660Sstevel@tonic-gate 	 * CSR_V LPU_GIGABLAZE_GLUE_CONFIG1 Expect OBP 0x88407
13670Sstevel@tonic-gate 	 */
13680Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_GIGABLAZE_GLUE_CONFIG1: 0x%llx\n",
136927Sjchu 	    CSR_XR(csr_base, LPU_GIGABLAZE_GLUE_CONFIG1));
13700Sstevel@tonic-gate 
13710Sstevel@tonic-gate 	/*
13720Sstevel@tonic-gate 	 * CSR_V LPU_GIGABLAZE_GLUE_CONFIG2 Expect OBP 0x35
13730Sstevel@tonic-gate 	 */
13740Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_GIGABLAZE_GLUE_CONFIG2: 0x%llx\n",
137527Sjchu 	    CSR_XR(csr_base, LPU_GIGABLAZE_GLUE_CONFIG2));
13760Sstevel@tonic-gate 
13770Sstevel@tonic-gate 	/*
13780Sstevel@tonic-gate 	 * CSR_V LPU_GIGABLAZE_GLUE_CONFIG3 Expect OBP 0x4400FA
13790Sstevel@tonic-gate 	 */
13800Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_GIGABLAZE_GLUE_CONFIG3: 0x%llx\n",
138127Sjchu 	    CSR_XR(csr_base, LPU_GIGABLAZE_GLUE_CONFIG3));
13820Sstevel@tonic-gate 
13830Sstevel@tonic-gate 	/*
13840Sstevel@tonic-gate 	 * CSR_V LPU_GIGABLAZE_GLUE_CONFIG4 Expect OBP 0x1E848
13850Sstevel@tonic-gate 	 */
13860Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_GIGABLAZE_GLUE_CONFIG4: 0x%llx\n",
138727Sjchu 	    CSR_XR(csr_base, LPU_GIGABLAZE_GLUE_CONFIG4));
13880Sstevel@tonic-gate 
13890Sstevel@tonic-gate 	/*
13900Sstevel@tonic-gate 	 * CSR_V LPU_GIGABLAZE_GLUE_STATUS Expect OBP 0x0
13910Sstevel@tonic-gate 	 */
13920Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_GIGABLAZE_GLUE_STATUS: 0x%llx\n",
139327Sjchu 	    CSR_XR(csr_base, LPU_GIGABLAZE_GLUE_STATUS));
13940Sstevel@tonic-gate 
13950Sstevel@tonic-gate 	/*
13960Sstevel@tonic-gate 	 * CSR_V LPU_GIGABLAZE_GLUE_INTERRUPT_AND_STATUS_TEST Expect OBP 0x0
13970Sstevel@tonic-gate 	 */
139827Sjchu 	DBG(DBG_LPU, NULL, "lpu_init - "
139927Sjchu 	    "LPU_GIGABLAZE_GLUE_INTERRUPT_AND_STATUS_TEST: 0x%llx\n",
140027Sjchu 	    CSR_XR(csr_base,
140127Sjchu 	    LPU_GIGABLAZE_GLUE_INTERRUPT_AND_STATUS_TEST));
14020Sstevel@tonic-gate 
14030Sstevel@tonic-gate 	/*
140427Sjchu 	 * CSR_V LPU GIGABLASE LAYER interrupt regs (mask, status)
14050Sstevel@tonic-gate 	 */
14060Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
14070Sstevel@tonic-gate 	    "lpu_init - LPU_GIGABLAZE_GLUE_INTERRUPT_MASK: 0x%llx\n",
14080Sstevel@tonic-gate 	    CSR_XR(csr_base, LPU_GIGABLAZE_GLUE_INTERRUPT_MASK));
14090Sstevel@tonic-gate 
141027Sjchu 	DBG(DBG_LPU, NULL,
141127Sjchu 	    "lpu_init - LPU_GIGABLAZE_GLUE_INTERRUPT_AND_STATUS: 0x%llx\n",
141227Sjchu 	    CSR_XR(csr_base, LPU_GIGABLAZE_GLUE_INTERRUPT_AND_STATUS));
141327Sjchu 
14140Sstevel@tonic-gate 	/*
14150Sstevel@tonic-gate 	 * CSR_V LPU_GIGABLAZE_GLUE_POWER_DOWN1 Expect HW 0x0
14160Sstevel@tonic-gate 	 */
14170Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
141827Sjchu 	    "lpu_init - LPU_GIGABLAZE_GLUE_POWER_DOWN1: 0x%llx\n",
141927Sjchu 	    CSR_XR(csr_base, LPU_GIGABLAZE_GLUE_POWER_DOWN1));
14200Sstevel@tonic-gate 
14210Sstevel@tonic-gate 	/*
14220Sstevel@tonic-gate 	 * CSR_V LPU_GIGABLAZE_GLUE_POWER_DOWN2 Expect HW 0x0
14230Sstevel@tonic-gate 	 */
14240Sstevel@tonic-gate 	DBG(DBG_LPU, NULL,
142527Sjchu 	    "lpu_init - LPU_GIGABLAZE_GLUE_POWER_DOWN2: 0x%llx\n",
142627Sjchu 	    CSR_XR(csr_base, LPU_GIGABLAZE_GLUE_POWER_DOWN2));
14270Sstevel@tonic-gate 
14280Sstevel@tonic-gate 	/*
14290Sstevel@tonic-gate 	 * CSR_V LPU_GIGABLAZE_GLUE_CONFIG5 Expect OBP 0x0
14300Sstevel@tonic-gate 	 */
14310Sstevel@tonic-gate 	DBG(DBG_LPU, NULL, "lpu_init - LPU_GIGABLAZE_GLUE_CONFIG5: 0x%llx\n",
143227Sjchu 	    CSR_XR(csr_base, LPU_GIGABLAZE_GLUE_CONFIG5));
14330Sstevel@tonic-gate }
14340Sstevel@tonic-gate 
14350Sstevel@tonic-gate /* ARGSUSED */
14360Sstevel@tonic-gate static void
14370Sstevel@tonic-gate dmc_init(caddr_t csr_base, pxu_t *pxu_p)
14380Sstevel@tonic-gate {
14390Sstevel@tonic-gate 	uint64_t val;
14400Sstevel@tonic-gate 
14410Sstevel@tonic-gate /*
14420Sstevel@tonic-gate  * CSR_V DMC_CORE_AND_BLOCK_INTERRUPT_ENABLE Expect OBP 0x8000000000000003
14430Sstevel@tonic-gate  */
14440Sstevel@tonic-gate 
14450Sstevel@tonic-gate 	val = -1ull;
14460Sstevel@tonic-gate 	CSR_XS(csr_base, DMC_CORE_AND_BLOCK_INTERRUPT_ENABLE, val);
14470Sstevel@tonic-gate 	DBG(DBG_DMC, NULL,
144827Sjchu 	    "dmc_init - DMC_CORE_AND_BLOCK_INTERRUPT_ENABLE: 0x%llx\n",
144927Sjchu 	    CSR_XR(csr_base, DMC_CORE_AND_BLOCK_INTERRUPT_ENABLE));
14500Sstevel@tonic-gate 
14510Sstevel@tonic-gate 	/*
14520Sstevel@tonic-gate 	 * CSR_V DMC_CORE_AND_BLOCK_ERROR_STATUS Expect HW 0x0
14530Sstevel@tonic-gate 	 */
14540Sstevel@tonic-gate 	DBG(DBG_DMC, NULL,
145527Sjchu 	    "dmc_init - DMC_CORE_AND_BLOCK_ERROR_STATUS: 0x%llx\n",
145627Sjchu 	    CSR_XR(csr_base, DMC_CORE_AND_BLOCK_ERROR_STATUS));
14570Sstevel@tonic-gate 
14580Sstevel@tonic-gate 	/*
14590Sstevel@tonic-gate 	 * CSR_V DMC_DEBUG_SELECT_FOR_PORT_A Expect HW 0x0
14600Sstevel@tonic-gate 	 */
14610Sstevel@tonic-gate 	val = 0x0ull;
14620Sstevel@tonic-gate 	CSR_XS(csr_base, DMC_DEBUG_SELECT_FOR_PORT_A, val);
14630Sstevel@tonic-gate 	DBG(DBG_DMC, NULL, "dmc_init - DMC_DEBUG_SELECT_FOR_PORT_A: 0x%llx\n",
146427Sjchu 	    CSR_XR(csr_base, DMC_DEBUG_SELECT_FOR_PORT_A));
14650Sstevel@tonic-gate 
14660Sstevel@tonic-gate 	/*
14670Sstevel@tonic-gate 	 * CSR_V DMC_DEBUG_SELECT_FOR_PORT_B Expect HW 0x0
14680Sstevel@tonic-gate 	 */
14690Sstevel@tonic-gate 	val = 0x0ull;
14700Sstevel@tonic-gate 	CSR_XS(csr_base, DMC_DEBUG_SELECT_FOR_PORT_B, val);
14710Sstevel@tonic-gate 	DBG(DBG_DMC, NULL, "dmc_init - DMC_DEBUG_SELECT_FOR_PORT_B: 0x%llx\n",
147227Sjchu 	    CSR_XR(csr_base, DMC_DEBUG_SELECT_FOR_PORT_B));
14730Sstevel@tonic-gate }
14740Sstevel@tonic-gate 
14750Sstevel@tonic-gate void
14760Sstevel@tonic-gate hvio_pec_init(caddr_t csr_base, pxu_t *pxu_p)
14770Sstevel@tonic-gate {
14780Sstevel@tonic-gate 	uint64_t val;
14790Sstevel@tonic-gate 
14800Sstevel@tonic-gate 	ilu_init(csr_base, pxu_p);
14810Sstevel@tonic-gate 	tlu_init(csr_base, pxu_p);
14820Sstevel@tonic-gate 	lpu_init(csr_base, pxu_p);
14830Sstevel@tonic-gate 	dmc_init(csr_base, pxu_p);
14840Sstevel@tonic-gate 
14850Sstevel@tonic-gate /*
14860Sstevel@tonic-gate  * CSR_V PEC_CORE_AND_BLOCK_INTERRUPT_ENABLE Expect Kernel 0x800000000000000F
14870Sstevel@tonic-gate  */
14880Sstevel@tonic-gate 
14890Sstevel@tonic-gate 	val = -1ull;
14900Sstevel@tonic-gate 	CSR_XS(csr_base, PEC_CORE_AND_BLOCK_INTERRUPT_ENABLE, val);
14910Sstevel@tonic-gate 	DBG(DBG_PEC, NULL,
149227Sjchu 	    "hvio_pec_init - PEC_CORE_AND_BLOCK_INTERRUPT_ENABLE: 0x%llx\n",
149327Sjchu 	    CSR_XR(csr_base, PEC_CORE_AND_BLOCK_INTERRUPT_ENABLE));
14940Sstevel@tonic-gate 
14950Sstevel@tonic-gate 	/*
14960Sstevel@tonic-gate 	 * CSR_V PEC_CORE_AND_BLOCK_INTERRUPT_STATUS Expect HW 0x0
14970Sstevel@tonic-gate 	 */
14980Sstevel@tonic-gate 	DBG(DBG_PEC, NULL,
149927Sjchu 	    "hvio_pec_init - PEC_CORE_AND_BLOCK_INTERRUPT_STATUS: 0x%llx\n",
150027Sjchu 	    CSR_XR(csr_base, PEC_CORE_AND_BLOCK_INTERRUPT_STATUS));
15010Sstevel@tonic-gate }
15020Sstevel@tonic-gate 
150327Sjchu /*
150427Sjchu  * Initialize the module, but do not enable interrupts.
150527Sjchu  */
15060Sstevel@tonic-gate void
15070Sstevel@tonic-gate hvio_mmu_init(caddr_t csr_base, pxu_t *pxu_p)
15080Sstevel@tonic-gate {
15090Sstevel@tonic-gate 	uint64_t	val, i, tsb_ctrl, obp_tsb_pa, *base_tte_addr;
15100Sstevel@tonic-gate 	uint_t		obp_tsb_entries, obp_tsb_size;
15110Sstevel@tonic-gate 
15120Sstevel@tonic-gate 	bzero(pxu_p->tsb_vaddr, pxu_p->tsb_size);
15130Sstevel@tonic-gate 
15140Sstevel@tonic-gate 	/*
15150Sstevel@tonic-gate 	 * Preserve OBP's TSB
15160Sstevel@tonic-gate 	 */
15170Sstevel@tonic-gate 	val = CSR_XR(csr_base, MMU_TSB_CONTROL);
15180Sstevel@tonic-gate 
15190Sstevel@tonic-gate 	tsb_ctrl = CSR_XR(csr_base, MMU_TSB_CONTROL);
15200Sstevel@tonic-gate 
15210Sstevel@tonic-gate 	obp_tsb_pa = tsb_ctrl &  0x7FFFFFFE000;
15220Sstevel@tonic-gate 	obp_tsb_size = tsb_ctrl & 0xF;
15230Sstevel@tonic-gate 
15240Sstevel@tonic-gate 	obp_tsb_entries = MMU_TSBSIZE_TO_TSBENTRIES(obp_tsb_size);
15250Sstevel@tonic-gate 
15260Sstevel@tonic-gate 	base_tte_addr = pxu_p->tsb_vaddr +
15270Sstevel@tonic-gate 		((pxu_p->tsb_size >> 3) - obp_tsb_entries);
15280Sstevel@tonic-gate 
15290Sstevel@tonic-gate 	for (i = 0; i < obp_tsb_entries; i++) {
15300Sstevel@tonic-gate 		uint64_t tte = lddphys(obp_tsb_pa + i * 8);
15310Sstevel@tonic-gate 
15320Sstevel@tonic-gate 		if (!MMU_TTE_VALID(tte))
15330Sstevel@tonic-gate 			continue;
15340Sstevel@tonic-gate 
15350Sstevel@tonic-gate 		base_tte_addr[i] = tte;
15360Sstevel@tonic-gate 	}
15370Sstevel@tonic-gate 
15380Sstevel@tonic-gate 	/*
15390Sstevel@tonic-gate 	 * Invalidate the TLB through the diagnostic register.
15400Sstevel@tonic-gate 	 */
15410Sstevel@tonic-gate 
15420Sstevel@tonic-gate 	CSR_XS(csr_base, MMU_TTE_CACHE_INVALIDATE, -1ull);
15430Sstevel@tonic-gate 
15440Sstevel@tonic-gate 	/*
15450Sstevel@tonic-gate 	 * Configure the Fire MMU TSB Control Register.  Determine
15460Sstevel@tonic-gate 	 * the encoding for either 8KB pages (0) or 64KB pages (1).
15470Sstevel@tonic-gate 	 *
15480Sstevel@tonic-gate 	 * Write the most significant 30 bits of the TSB physical address
15490Sstevel@tonic-gate 	 * and the encoded TSB table size.
15500Sstevel@tonic-gate 	 */
15510Sstevel@tonic-gate 	for (i = 8; i && (pxu_p->tsb_size < (0x2000 << i)); i--);
15520Sstevel@tonic-gate 
15530Sstevel@tonic-gate 	val = (((((va_to_pa(pxu_p->tsb_vaddr)) >> 13) << 13) |
15540Sstevel@tonic-gate 	    ((MMU_PAGE_SHIFT == 13) ? 0 : 1) << 8) | i);
15550Sstevel@tonic-gate 
15560Sstevel@tonic-gate 	CSR_XS(csr_base, MMU_TSB_CONTROL, val);
15570Sstevel@tonic-gate 
15580Sstevel@tonic-gate 	/*
15590Sstevel@tonic-gate 	 * Enable the MMU, set the "TSB Cache Snoop Enable",
15600Sstevel@tonic-gate 	 * the "Cache Mode", the "Bypass Enable" and
15610Sstevel@tonic-gate 	 * the "Translation Enable" bits.
15620Sstevel@tonic-gate 	 */
15630Sstevel@tonic-gate 	val = CSR_XR(csr_base, MMU_CONTROL_AND_STATUS);
15640Sstevel@tonic-gate 	val |= ((1ull << MMU_CONTROL_AND_STATUS_SE)
156527Sjchu 	    | (MMU_CONTROL_AND_STATUS_CM_MASK << MMU_CONTROL_AND_STATUS_CM)
156627Sjchu 	    | (1ull << MMU_CONTROL_AND_STATUS_BE)
156727Sjchu 	    | (1ull << MMU_CONTROL_AND_STATUS_TE));
15680Sstevel@tonic-gate 
15690Sstevel@tonic-gate 	CSR_XS(csr_base, MMU_CONTROL_AND_STATUS, val);
15700Sstevel@tonic-gate 
15710Sstevel@tonic-gate 	/*
15720Sstevel@tonic-gate 	 * Read the register here to ensure that the previous writes to
15730Sstevel@tonic-gate 	 * the Fire MMU registers have been flushed.  (Technically, this
15740Sstevel@tonic-gate 	 * is not entirely necessary here as we will likely do later reads
15750Sstevel@tonic-gate 	 * during Fire initialization, but it is a small price to pay for
15760Sstevel@tonic-gate 	 * more modular code.)
15770Sstevel@tonic-gate 	 */
15780Sstevel@tonic-gate 	(void) CSR_XR(csr_base, MMU_CONTROL_AND_STATUS);
15790Sstevel@tonic-gate 
15800Sstevel@tonic-gate 	/*
158127Sjchu 	 * CSR_V TLU's UE interrupt regs (log, enable, status, clear)
158227Sjchu 	 * Plus header logs
15830Sstevel@tonic-gate 	 */
158427Sjchu 	DBG(DBG_MMU, NULL, "mmu_init - MMU_ERROR_LOG_ENABLE: 0x%llx\n",
158527Sjchu 	    CSR_XR(csr_base, MMU_ERROR_LOG_ENABLE));
158627Sjchu 
158727Sjchu 	DBG(DBG_MMU, NULL, "mmu_init - MMU_INTERRUPT_ENABLE: 0x%llx\n",
158827Sjchu 	    CSR_XR(csr_base, MMU_INTERRUPT_ENABLE));
158927Sjchu 
159027Sjchu 	DBG(DBG_MMU, NULL, "mmu_init - MMU_INTERRUPT_STATUS: 0x%llx\n",
159127Sjchu 	    CSR_XR(csr_base, MMU_INTERRUPT_STATUS));
159227Sjchu 
159327Sjchu 	DBG(DBG_MMU, NULL, "mmu_init - MMU_ERROR_STATUS_CLEAR: 0x%llx\n",
159427Sjchu 	    CSR_XR(csr_base, MMU_ERROR_STATUS_CLEAR));
15950Sstevel@tonic-gate }
15960Sstevel@tonic-gate 
15970Sstevel@tonic-gate /*
15980Sstevel@tonic-gate  * Generic IOMMU Servies
15990Sstevel@tonic-gate  */
16000Sstevel@tonic-gate 
16010Sstevel@tonic-gate /* ARGSUSED */
16020Sstevel@tonic-gate uint64_t
16030Sstevel@tonic-gate hvio_iommu_map(devhandle_t dev_hdl, pxu_t *pxu_p, tsbid_t tsbid,
16040Sstevel@tonic-gate     pages_t pages, io_attributes_t io_attributes,
16050Sstevel@tonic-gate     void *addr, size_t pfn_index, int flag)
16060Sstevel@tonic-gate {
16070Sstevel@tonic-gate 	tsbindex_t	tsb_index = PCI_TSBID_TO_TSBINDEX(tsbid);
16080Sstevel@tonic-gate 	uint64_t	attr = MMU_TTE_V;
16090Sstevel@tonic-gate 	int		i;
16100Sstevel@tonic-gate 
16110Sstevel@tonic-gate 	if (io_attributes & PCI_MAP_ATTR_WRITE)
16120Sstevel@tonic-gate 		attr |= MMU_TTE_W;
16130Sstevel@tonic-gate 
16140Sstevel@tonic-gate 	if (flag == MMU_MAP_MP) {
16150Sstevel@tonic-gate 		ddi_dma_impl_t  *mp = (ddi_dma_impl_t *)addr;
16160Sstevel@tonic-gate 
16170Sstevel@tonic-gate 		for (i = 0; i < pages; i++, pfn_index++, tsb_index++) {
16180Sstevel@tonic-gate 			px_iopfn_t	pfn = PX_GET_MP_PFN(mp, pfn_index);
16190Sstevel@tonic-gate 
16200Sstevel@tonic-gate 			pxu_p->tsb_vaddr[tsb_index] =
16210Sstevel@tonic-gate 			    MMU_PTOB(pfn) | attr;
16220Sstevel@tonic-gate 		}
16230Sstevel@tonic-gate 	} else {
16240Sstevel@tonic-gate 		caddr_t a = (caddr_t)addr;
16250Sstevel@tonic-gate 
16260Sstevel@tonic-gate 		for (i = 0; i < pages; i++, a += MMU_PAGE_SIZE, tsb_index++) {
16270Sstevel@tonic-gate 			px_iopfn_t pfn = hat_getpfnum(kas.a_hat, a);
16280Sstevel@tonic-gate 
16290Sstevel@tonic-gate 			pxu_p->tsb_vaddr[tsb_index] =
16300Sstevel@tonic-gate 			    MMU_PTOB(pfn) | attr;
16310Sstevel@tonic-gate 		}
16320Sstevel@tonic-gate 	}
16330Sstevel@tonic-gate 
16340Sstevel@tonic-gate 	return (H_EOK);
16350Sstevel@tonic-gate }
16360Sstevel@tonic-gate 
16370Sstevel@tonic-gate /* ARGSUSED */
16380Sstevel@tonic-gate uint64_t
16390Sstevel@tonic-gate hvio_iommu_demap(devhandle_t dev_hdl, pxu_t *pxu_p, tsbid_t tsbid,
16400Sstevel@tonic-gate     pages_t pages)
16410Sstevel@tonic-gate {
16420Sstevel@tonic-gate 	tsbindex_t	tsb_index = PCI_TSBID_TO_TSBINDEX(tsbid);
16430Sstevel@tonic-gate 	int		i;
16440Sstevel@tonic-gate 
16450Sstevel@tonic-gate 	for (i = 0; i < pages; i++, tsb_index++) {
16460Sstevel@tonic-gate 		pxu_p->tsb_vaddr[tsb_index] = MMU_INVALID_TTE;
16470Sstevel@tonic-gate 	}
16480Sstevel@tonic-gate 
16490Sstevel@tonic-gate 	return (H_EOK);
16500Sstevel@tonic-gate }
16510Sstevel@tonic-gate 
16520Sstevel@tonic-gate /* ARGSUSED */
16530Sstevel@tonic-gate uint64_t
16540Sstevel@tonic-gate hvio_iommu_getmap(devhandle_t dev_hdl, pxu_t *pxu_p, tsbid_t tsbid,
16550Sstevel@tonic-gate     io_attributes_t *attributes_p, r_addr_t *r_addr_p)
16560Sstevel@tonic-gate {
16570Sstevel@tonic-gate 	tsbindex_t	tsb_index = PCI_TSBID_TO_TSBINDEX(tsbid);
16580Sstevel@tonic-gate 	uint64_t	*tte_addr;
16590Sstevel@tonic-gate 	uint64_t	ret = H_EOK;
16600Sstevel@tonic-gate 
16610Sstevel@tonic-gate 	tte_addr = (uint64_t *)(pxu_p->tsb_vaddr) + tsb_index;
16620Sstevel@tonic-gate 
16630Sstevel@tonic-gate 	if (*tte_addr & MMU_TTE_V) {
16640Sstevel@tonic-gate 		*r_addr_p = MMU_TTETOPA(*tte_addr);
16650Sstevel@tonic-gate 		*attributes_p = (*tte_addr & MMU_TTE_W) ?
16660Sstevel@tonic-gate 		    PCI_MAP_ATTR_WRITE:PCI_MAP_ATTR_READ;
16670Sstevel@tonic-gate 	} else {
16680Sstevel@tonic-gate 		*r_addr_p = 0;
16690Sstevel@tonic-gate 		*attributes_p = 0;
16700Sstevel@tonic-gate 		ret = H_ENOMAP;
16710Sstevel@tonic-gate 	}
16720Sstevel@tonic-gate 
16730Sstevel@tonic-gate 	return (ret);
16740Sstevel@tonic-gate }
16750Sstevel@tonic-gate 
16760Sstevel@tonic-gate /* ARGSUSED */
16770Sstevel@tonic-gate uint64_t
16780Sstevel@tonic-gate hvio_iommu_getbypass(devhandle_t dev_hdl, r_addr_t ra,
16790Sstevel@tonic-gate     io_attributes_t io_attributes, io_addr_t *io_addr_p)
16800Sstevel@tonic-gate {
16810Sstevel@tonic-gate 	uint64_t	pfn = MMU_BTOP(ra);
16820Sstevel@tonic-gate 
16830Sstevel@tonic-gate 	*io_addr_p = MMU_BYPASS_BASE | ra |
168427Sjchu 	    (pf_is_memory(pfn) ? 0 : MMU_BYPASS_NONCACHE);
16850Sstevel@tonic-gate 
16860Sstevel@tonic-gate 	return (H_EOK);
16870Sstevel@tonic-gate }
16880Sstevel@tonic-gate 
16890Sstevel@tonic-gate /*
16900Sstevel@tonic-gate  * Generic IO Interrupt Servies
16910Sstevel@tonic-gate  */
16920Sstevel@tonic-gate 
16930Sstevel@tonic-gate /*
16940Sstevel@tonic-gate  * Converts a device specific interrupt number given by the
16950Sstevel@tonic-gate  * arguments devhandle and devino into a system specific ino.
16960Sstevel@tonic-gate  */
16970Sstevel@tonic-gate /* ARGSUSED */
16980Sstevel@tonic-gate uint64_t
16990Sstevel@tonic-gate hvio_intr_devino_to_sysino(devhandle_t dev_hdl, pxu_t *pxu_p, devino_t devino,
17000Sstevel@tonic-gate     sysino_t *sysino)
17010Sstevel@tonic-gate {
17020Sstevel@tonic-gate 	if (devino > INTERRUPT_MAPPING_ENTRIES) {
17030Sstevel@tonic-gate 		DBG(DBG_IB, NULL, "ino %x is invalid\n", devino);
17040Sstevel@tonic-gate 		return (H_ENOINTR);
17050Sstevel@tonic-gate 	}
17060Sstevel@tonic-gate 
17070Sstevel@tonic-gate 	*sysino = DEVINO_TO_SYSINO(pxu_p->portid, devino);
17080Sstevel@tonic-gate 
17090Sstevel@tonic-gate 	return (H_EOK);
17100Sstevel@tonic-gate }
17110Sstevel@tonic-gate 
17120Sstevel@tonic-gate /*
17130Sstevel@tonic-gate  * Returns state in intr_valid_state if the interrupt defined by sysino
17140Sstevel@tonic-gate  * is valid (enabled) or not-valid (disabled).
17150Sstevel@tonic-gate  */
17160Sstevel@tonic-gate uint64_t
17170Sstevel@tonic-gate hvio_intr_getvalid(devhandle_t dev_hdl, sysino_t sysino,
17180Sstevel@tonic-gate     intr_valid_state_t *intr_valid_state)
17190Sstevel@tonic-gate {
17200Sstevel@tonic-gate 	if (CSRA_BR((caddr_t)dev_hdl, INTERRUPT_MAPPING,
17210Sstevel@tonic-gate 	    SYSINO_TO_DEVINO(sysino), ENTRIES_V)) {
17220Sstevel@tonic-gate 		*intr_valid_state = INTR_VALID;
17230Sstevel@tonic-gate 	} else {
17240Sstevel@tonic-gate 		*intr_valid_state = INTR_NOTVALID;
17250Sstevel@tonic-gate 	}
17260Sstevel@tonic-gate 
17270Sstevel@tonic-gate 	return (H_EOK);
17280Sstevel@tonic-gate }
17290Sstevel@tonic-gate 
17300Sstevel@tonic-gate /*
17310Sstevel@tonic-gate  * Sets the 'valid' state of the interrupt defined by
17320Sstevel@tonic-gate  * the argument sysino to the state defined by the
17330Sstevel@tonic-gate  * argument intr_valid_state.
17340Sstevel@tonic-gate  */
17350Sstevel@tonic-gate uint64_t
17360Sstevel@tonic-gate hvio_intr_setvalid(devhandle_t dev_hdl, sysino_t sysino,
17370Sstevel@tonic-gate     intr_valid_state_t intr_valid_state)
17380Sstevel@tonic-gate {
17390Sstevel@tonic-gate 	switch (intr_valid_state) {
17400Sstevel@tonic-gate 	case INTR_VALID:
17410Sstevel@tonic-gate 		CSRA_BS((caddr_t)dev_hdl, INTERRUPT_MAPPING,
17420Sstevel@tonic-gate 		    SYSINO_TO_DEVINO(sysino), ENTRIES_V);
17430Sstevel@tonic-gate 		break;
17440Sstevel@tonic-gate 	case INTR_NOTVALID:
17450Sstevel@tonic-gate 		CSRA_BC((caddr_t)dev_hdl, INTERRUPT_MAPPING,
17460Sstevel@tonic-gate 		    SYSINO_TO_DEVINO(sysino), ENTRIES_V);
17470Sstevel@tonic-gate 		break;
17480Sstevel@tonic-gate 	default:
17490Sstevel@tonic-gate 		return (EINVAL);
17500Sstevel@tonic-gate 	}
17510Sstevel@tonic-gate 
17520Sstevel@tonic-gate 	return (H_EOK);
17530Sstevel@tonic-gate }
17540Sstevel@tonic-gate 
17550Sstevel@tonic-gate /*
17560Sstevel@tonic-gate  * Returns the current state of the interrupt given by the sysino
17570Sstevel@tonic-gate  * argument.
17580Sstevel@tonic-gate  */
17590Sstevel@tonic-gate uint64_t
17600Sstevel@tonic-gate hvio_intr_getstate(devhandle_t dev_hdl, sysino_t sysino,
17610Sstevel@tonic-gate     intr_state_t *intr_state)
17620Sstevel@tonic-gate {
17630Sstevel@tonic-gate 	intr_state_t state;
17640Sstevel@tonic-gate 
17650Sstevel@tonic-gate 	state = CSRA_FR((caddr_t)dev_hdl, INTERRUPT_CLEAR,
17660Sstevel@tonic-gate 	    SYSINO_TO_DEVINO(sysino), ENTRIES_INT_STATE);
17670Sstevel@tonic-gate 
17680Sstevel@tonic-gate 	switch (state) {
17690Sstevel@tonic-gate 	case INTERRUPT_IDLE_STATE:
17700Sstevel@tonic-gate 		*intr_state = INTR_IDLE_STATE;
17710Sstevel@tonic-gate 		break;
17720Sstevel@tonic-gate 	case INTERRUPT_RECEIVED_STATE:
17730Sstevel@tonic-gate 		*intr_state = INTR_RECEIVED_STATE;
17740Sstevel@tonic-gate 		break;
17750Sstevel@tonic-gate 	case INTERRUPT_PENDING_STATE:
17760Sstevel@tonic-gate 		*intr_state = INTR_DELIVERED_STATE;
17770Sstevel@tonic-gate 		break;
17780Sstevel@tonic-gate 	default:
17790Sstevel@tonic-gate 		return (EINVAL);
17800Sstevel@tonic-gate 	}
17810Sstevel@tonic-gate 
17820Sstevel@tonic-gate 	return (H_EOK);
17830Sstevel@tonic-gate 
17840Sstevel@tonic-gate }
17850Sstevel@tonic-gate 
17860Sstevel@tonic-gate /*
17870Sstevel@tonic-gate  * Sets the current state of the interrupt given by the sysino
17880Sstevel@tonic-gate  * argument to the value given in the argument intr_state.
17890Sstevel@tonic-gate  *
17900Sstevel@tonic-gate  * Note: Setting the state to INTR_IDLE clears any pending
17910Sstevel@tonic-gate  * interrupt for sysino.
17920Sstevel@tonic-gate  */
17930Sstevel@tonic-gate uint64_t
17940Sstevel@tonic-gate hvio_intr_setstate(devhandle_t dev_hdl, sysino_t sysino,
17950Sstevel@tonic-gate     intr_state_t intr_state)
17960Sstevel@tonic-gate {
17970Sstevel@tonic-gate 	intr_state_t state;
17980Sstevel@tonic-gate 
17990Sstevel@tonic-gate 	switch (intr_state) {
18000Sstevel@tonic-gate 	case INTR_IDLE_STATE:
18010Sstevel@tonic-gate 		state = INTERRUPT_IDLE_STATE;
18020Sstevel@tonic-gate 		break;
18030Sstevel@tonic-gate 	case INTR_DELIVERED_STATE:
18040Sstevel@tonic-gate 		state = INTERRUPT_PENDING_STATE;
18050Sstevel@tonic-gate 		break;
18060Sstevel@tonic-gate 	default:
18070Sstevel@tonic-gate 		return (EINVAL);
18080Sstevel@tonic-gate 	}
18090Sstevel@tonic-gate 
18100Sstevel@tonic-gate 	CSRA_FS((caddr_t)dev_hdl, INTERRUPT_CLEAR,
18110Sstevel@tonic-gate 	    SYSINO_TO_DEVINO(sysino), ENTRIES_INT_STATE, state);
18120Sstevel@tonic-gate 
18130Sstevel@tonic-gate 	return (H_EOK);
18140Sstevel@tonic-gate }
18150Sstevel@tonic-gate 
18160Sstevel@tonic-gate /*
18170Sstevel@tonic-gate  * Returns the cpuid that is the current target of the
18180Sstevel@tonic-gate  * interrupt given by the sysino argument.
18190Sstevel@tonic-gate  *
18200Sstevel@tonic-gate  * The cpuid value returned is undefined if the target
18210Sstevel@tonic-gate  * has not been set via intr_settarget.
18220Sstevel@tonic-gate  */
18230Sstevel@tonic-gate uint64_t
18240Sstevel@tonic-gate hvio_intr_gettarget(devhandle_t dev_hdl, sysino_t sysino, cpuid_t *cpuid)
18250Sstevel@tonic-gate {
18260Sstevel@tonic-gate 	*cpuid = CSRA_FR((caddr_t)dev_hdl, INTERRUPT_MAPPING,
18270Sstevel@tonic-gate 	    SYSINO_TO_DEVINO(sysino), ENTRIES_T_JPID);
18280Sstevel@tonic-gate 
18290Sstevel@tonic-gate 	return (H_EOK);
18300Sstevel@tonic-gate }
18310Sstevel@tonic-gate 
18320Sstevel@tonic-gate /*
18330Sstevel@tonic-gate  * Set the target cpu for the interrupt defined by the argument
18340Sstevel@tonic-gate  * sysino to the target cpu value defined by the argument cpuid.
18350Sstevel@tonic-gate  */
18360Sstevel@tonic-gate uint64_t
18370Sstevel@tonic-gate hvio_intr_settarget(devhandle_t dev_hdl, sysino_t sysino, cpuid_t cpuid)
18380Sstevel@tonic-gate {
18390Sstevel@tonic-gate 
18400Sstevel@tonic-gate 	uint64_t	val, intr_controller;
18410Sstevel@tonic-gate 	uint32_t	ino = SYSINO_TO_DEVINO(sysino);
18420Sstevel@tonic-gate 
18430Sstevel@tonic-gate 	/*
18440Sstevel@tonic-gate 	 * For now, we assign interrupt controller in a round
18450Sstevel@tonic-gate 	 * robin fashion.  Later, we may need to come up with
18460Sstevel@tonic-gate 	 * a more efficient assignment algorithm.
18470Sstevel@tonic-gate 	 */
18480Sstevel@tonic-gate 	intr_controller = 0x1ull << (cpuid % 4);
18490Sstevel@tonic-gate 
18500Sstevel@tonic-gate 	val = (((cpuid & INTERRUPT_MAPPING_ENTRIES_T_JPID_MASK) <<
18510Sstevel@tonic-gate 	    INTERRUPT_MAPPING_ENTRIES_T_JPID) |
18520Sstevel@tonic-gate 	    ((intr_controller & INTERRUPT_MAPPING_ENTRIES_INT_CNTRL_NUM_MASK)
18530Sstevel@tonic-gate 	    << INTERRUPT_MAPPING_ENTRIES_INT_CNTRL_NUM));
18540Sstevel@tonic-gate 
18550Sstevel@tonic-gate 	/* For EQ interrupts, set DATA MONDO bit */
18560Sstevel@tonic-gate 	if ((ino >= PX_DEFAULT_MSIQ_1ST_DEVINO) &&
18570Sstevel@tonic-gate 	    (ino < (PX_DEFAULT_MSIQ_1ST_DEVINO + PX_DEFAULT_MSIQ_CNT)))
18580Sstevel@tonic-gate 		val |= (0x1ull << INTERRUPT_MAPPING_ENTRIES_MDO_MODE);
18590Sstevel@tonic-gate 
18600Sstevel@tonic-gate 	CSRA_XS((caddr_t)dev_hdl, INTERRUPT_MAPPING, ino, val);
18610Sstevel@tonic-gate 
18620Sstevel@tonic-gate 	return (H_EOK);
18630Sstevel@tonic-gate }
18640Sstevel@tonic-gate 
18650Sstevel@tonic-gate /*
18660Sstevel@tonic-gate  * MSIQ Functions:
18670Sstevel@tonic-gate  */
18680Sstevel@tonic-gate uint64_t
18690Sstevel@tonic-gate hvio_msiq_init(devhandle_t dev_hdl, pxu_t *pxu_p)
18700Sstevel@tonic-gate {
18710Sstevel@tonic-gate 	CSRA_XS((caddr_t)dev_hdl, EVENT_QUEUE_BASE_ADDRESS, 0,
18720Sstevel@tonic-gate 	    (uint64_t)pxu_p->msiq_mapped_p);
18730Sstevel@tonic-gate 	DBG(DBG_IB, NULL,
18740Sstevel@tonic-gate 	    "hvio_msiq_init: EVENT_QUEUE_BASE_ADDRESS 0x%llx\n",
18750Sstevel@tonic-gate 	    CSR_XR((caddr_t)dev_hdl, EVENT_QUEUE_BASE_ADDRESS));
18760Sstevel@tonic-gate 
18770Sstevel@tonic-gate 	CSRA_XS((caddr_t)dev_hdl, INTERRUPT_MONDO_DATA_0, 0,
18780Sstevel@tonic-gate 	    (uint64_t)ID_TO_IGN(pxu_p->portid) << INO_BITS);
18790Sstevel@tonic-gate 	DBG(DBG_IB, NULL, "hvio_msiq_init: "
18800Sstevel@tonic-gate 	    "INTERRUPT_MONDO_DATA_0: 0x%llx\n",
18810Sstevel@tonic-gate 	    CSR_XR((caddr_t)dev_hdl, INTERRUPT_MONDO_DATA_0));
18820Sstevel@tonic-gate 
18830Sstevel@tonic-gate 	return (H_EOK);
18840Sstevel@tonic-gate }
18850Sstevel@tonic-gate 
18860Sstevel@tonic-gate uint64_t
18870Sstevel@tonic-gate hvio_msiq_getvalid(devhandle_t dev_hdl, msiqid_t msiq_id,
18880Sstevel@tonic-gate     pci_msiq_valid_state_t *msiq_valid_state)
18890Sstevel@tonic-gate {
18900Sstevel@tonic-gate 	uint32_t	eq_state;
18910Sstevel@tonic-gate 	uint64_t	ret = H_EOK;
18920Sstevel@tonic-gate 
18930Sstevel@tonic-gate 	eq_state = CSRA_FR((caddr_t)dev_hdl, EVENT_QUEUE_STATE,
18940Sstevel@tonic-gate 	    msiq_id, ENTRIES_STATE);
18950Sstevel@tonic-gate 
18960Sstevel@tonic-gate 	switch (eq_state) {
18970Sstevel@tonic-gate 	case EQ_IDLE_STATE:
18980Sstevel@tonic-gate 		*msiq_valid_state = PCI_MSIQ_INVALID;
18990Sstevel@tonic-gate 		break;
19000Sstevel@tonic-gate 	case EQ_ACTIVE_STATE:
19010Sstevel@tonic-gate 	case EQ_ERROR_STATE:
19020Sstevel@tonic-gate 		*msiq_valid_state = PCI_MSIQ_VALID;
19030Sstevel@tonic-gate 		break;
19040Sstevel@tonic-gate 	default:
19050Sstevel@tonic-gate 		ret = H_EIO;
19060Sstevel@tonic-gate 		break;
19070Sstevel@tonic-gate 	}
19080Sstevel@tonic-gate 
19090Sstevel@tonic-gate 	return (ret);
19100Sstevel@tonic-gate }
19110Sstevel@tonic-gate 
19120Sstevel@tonic-gate uint64_t
19130Sstevel@tonic-gate hvio_msiq_setvalid(devhandle_t dev_hdl, msiqid_t msiq_id,
19140Sstevel@tonic-gate     pci_msiq_valid_state_t msiq_valid_state)
19150Sstevel@tonic-gate {
19160Sstevel@tonic-gate 	uint64_t	ret = H_EOK;
19170Sstevel@tonic-gate 
19180Sstevel@tonic-gate 	switch (msiq_valid_state) {
19190Sstevel@tonic-gate 	case PCI_MSIQ_INVALID:
19200Sstevel@tonic-gate 		CSRA_BS((caddr_t)dev_hdl, EVENT_QUEUE_CONTROL_CLEAR,
19210Sstevel@tonic-gate 		    msiq_id, ENTRIES_DIS);
19220Sstevel@tonic-gate 		break;
19230Sstevel@tonic-gate 	case PCI_MSIQ_VALID:
19240Sstevel@tonic-gate 		CSRA_BS((caddr_t)dev_hdl, EVENT_QUEUE_CONTROL_SET,
19250Sstevel@tonic-gate 		    msiq_id, ENTRIES_EN);
19260Sstevel@tonic-gate 		break;
19270Sstevel@tonic-gate 	default:
19280Sstevel@tonic-gate 		ret = H_EINVAL;
19290Sstevel@tonic-gate 		break;
19300Sstevel@tonic-gate 	}
19310Sstevel@tonic-gate 
19320Sstevel@tonic-gate 	return (ret);
19330Sstevel@tonic-gate }
19340Sstevel@tonic-gate 
19350Sstevel@tonic-gate uint64_t
19360Sstevel@tonic-gate hvio_msiq_getstate(devhandle_t dev_hdl, msiqid_t msiq_id,
19370Sstevel@tonic-gate     pci_msiq_state_t *msiq_state)
19380Sstevel@tonic-gate {
19390Sstevel@tonic-gate 	uint32_t	eq_state;
19400Sstevel@tonic-gate 	uint64_t	ret = H_EOK;
19410Sstevel@tonic-gate 
19420Sstevel@tonic-gate 	eq_state = CSRA_FR((caddr_t)dev_hdl, EVENT_QUEUE_STATE,
19430Sstevel@tonic-gate 	    msiq_id, ENTRIES_STATE);
19440Sstevel@tonic-gate 
19450Sstevel@tonic-gate 	switch (eq_state) {
19460Sstevel@tonic-gate 	case EQ_IDLE_STATE:
19470Sstevel@tonic-gate 	case EQ_ACTIVE_STATE:
19480Sstevel@tonic-gate 		*msiq_state = PCI_MSIQ_STATE_IDLE;
19490Sstevel@tonic-gate 		break;
19500Sstevel@tonic-gate 	case EQ_ERROR_STATE:
19510Sstevel@tonic-gate 		*msiq_state = PCI_MSIQ_STATE_ERROR;
19520Sstevel@tonic-gate 		break;
19530Sstevel@tonic-gate 	default:
19540Sstevel@tonic-gate 		ret = H_EIO;
19550Sstevel@tonic-gate 	}
19560Sstevel@tonic-gate 
19570Sstevel@tonic-gate 	return (ret);
19580Sstevel@tonic-gate }
19590Sstevel@tonic-gate 
19600Sstevel@tonic-gate uint64_t
19610Sstevel@tonic-gate hvio_msiq_setstate(devhandle_t dev_hdl, msiqid_t msiq_id,
19620Sstevel@tonic-gate     pci_msiq_state_t msiq_state)
19630Sstevel@tonic-gate {
19640Sstevel@tonic-gate 	uint32_t	eq_state;
19650Sstevel@tonic-gate 	uint64_t	ret = H_EOK;
19660Sstevel@tonic-gate 
19670Sstevel@tonic-gate 	eq_state = CSRA_FR((caddr_t)dev_hdl, EVENT_QUEUE_STATE,
19680Sstevel@tonic-gate 	    msiq_id, ENTRIES_STATE);
19690Sstevel@tonic-gate 
19700Sstevel@tonic-gate 	switch (eq_state) {
19710Sstevel@tonic-gate 	case EQ_IDLE_STATE:
19720Sstevel@tonic-gate 		if (msiq_state == PCI_MSIQ_STATE_ERROR)
19730Sstevel@tonic-gate 			ret = H_EIO;
19740Sstevel@tonic-gate 		break;
19750Sstevel@tonic-gate 	case EQ_ACTIVE_STATE:
19760Sstevel@tonic-gate 		if (msiq_state == PCI_MSIQ_STATE_ERROR)
19770Sstevel@tonic-gate 			CSRA_BS((caddr_t)dev_hdl, EVENT_QUEUE_CONTROL_SET,
19780Sstevel@tonic-gate 			    msiq_id, ENTRIES_ENOVERR);
19790Sstevel@tonic-gate 		else
19800Sstevel@tonic-gate 			ret = H_EIO;
19810Sstevel@tonic-gate 		break;
19820Sstevel@tonic-gate 	case EQ_ERROR_STATE:
19830Sstevel@tonic-gate 		if (msiq_state == PCI_MSIQ_STATE_IDLE)
19840Sstevel@tonic-gate 			CSRA_BS((caddr_t)dev_hdl, EVENT_QUEUE_CONTROL_CLEAR,
19850Sstevel@tonic-gate 			    msiq_id, ENTRIES_E2I);
19860Sstevel@tonic-gate 		else
19870Sstevel@tonic-gate 			ret = H_EIO;
19880Sstevel@tonic-gate 		break;
19890Sstevel@tonic-gate 	default:
19900Sstevel@tonic-gate 		ret = H_EIO;
19910Sstevel@tonic-gate 	}
19920Sstevel@tonic-gate 
19930Sstevel@tonic-gate 	return (ret);
19940Sstevel@tonic-gate }
19950Sstevel@tonic-gate 
19960Sstevel@tonic-gate uint64_t
19970Sstevel@tonic-gate hvio_msiq_gethead(devhandle_t dev_hdl, msiqid_t msiq_id,
19980Sstevel@tonic-gate     msiqhead_t *msiq_head)
19990Sstevel@tonic-gate {
20000Sstevel@tonic-gate 	*msiq_head = CSRA_FR((caddr_t)dev_hdl, EVENT_QUEUE_HEAD,
20010Sstevel@tonic-gate 	    msiq_id, ENTRIES_HEAD);
20020Sstevel@tonic-gate 
20030Sstevel@tonic-gate 	return (H_EOK);
20040Sstevel@tonic-gate }
20050Sstevel@tonic-gate 
20060Sstevel@tonic-gate uint64_t
20070Sstevel@tonic-gate hvio_msiq_sethead(devhandle_t dev_hdl, msiqid_t msiq_id,
20080Sstevel@tonic-gate     msiqhead_t msiq_head)
20090Sstevel@tonic-gate {
20100Sstevel@tonic-gate 	CSRA_FS((caddr_t)dev_hdl, EVENT_QUEUE_HEAD, msiq_id,
20110Sstevel@tonic-gate 	    ENTRIES_HEAD, msiq_head);
20120Sstevel@tonic-gate 
20130Sstevel@tonic-gate 	return (H_EOK);
20140Sstevel@tonic-gate }
20150Sstevel@tonic-gate 
20160Sstevel@tonic-gate uint64_t
20170Sstevel@tonic-gate hvio_msiq_gettail(devhandle_t dev_hdl, msiqid_t msiq_id,
20180Sstevel@tonic-gate     msiqtail_t *msiq_tail)
20190Sstevel@tonic-gate {
20200Sstevel@tonic-gate 	*msiq_tail = CSRA_FR((caddr_t)dev_hdl, EVENT_QUEUE_TAIL,
20210Sstevel@tonic-gate 	    msiq_id, ENTRIES_TAIL);
20220Sstevel@tonic-gate 
20230Sstevel@tonic-gate 	return (H_EOK);
20240Sstevel@tonic-gate }
20250Sstevel@tonic-gate 
20260Sstevel@tonic-gate /*
20270Sstevel@tonic-gate  * MSI Functions:
20280Sstevel@tonic-gate  */
20290Sstevel@tonic-gate uint64_t
20300Sstevel@tonic-gate hvio_msi_init(devhandle_t dev_hdl, uint64_t addr32, uint64_t addr64)
20310Sstevel@tonic-gate {
20320Sstevel@tonic-gate 	/* PCI MEM 32 resources to perform 32 bit MSI transactions */
20330Sstevel@tonic-gate 	CSRA_FS((caddr_t)dev_hdl, MSI_32_BIT_ADDRESS, 0,
20340Sstevel@tonic-gate 	    ADDR, (uint64_t)addr32 >> MSI_32_BIT_ADDRESS_ADDR);
20350Sstevel@tonic-gate 	DBG(DBG_IB, NULL, "hvio_msiq_init: MSI_32_BIT_ADDRESS: 0x%llx\n",
20360Sstevel@tonic-gate 	    CSR_XR((caddr_t)dev_hdl, MSI_32_BIT_ADDRESS));
20370Sstevel@tonic-gate 
20380Sstevel@tonic-gate 	/* Reserve PCI MEM 64 resources to perform 64 bit MSI transactions */
20390Sstevel@tonic-gate 	CSRA_FS((caddr_t)dev_hdl, MSI_64_BIT_ADDRESS, 0,
20400Sstevel@tonic-gate 	    ADDR, (uint64_t)addr64 >> MSI_64_BIT_ADDRESS_ADDR);
20410Sstevel@tonic-gate 	DBG(DBG_IB, NULL, "hvio_msiq_init: MSI_64_BIT_ADDRESS: 0x%llx\n",
20420Sstevel@tonic-gate 	    CSR_XR((caddr_t)dev_hdl, MSI_64_BIT_ADDRESS));
20430Sstevel@tonic-gate 
20440Sstevel@tonic-gate 	return (H_EOK);
20450Sstevel@tonic-gate }
20460Sstevel@tonic-gate 
20470Sstevel@tonic-gate uint64_t
20480Sstevel@tonic-gate hvio_msi_getmsiq(devhandle_t dev_hdl, msinum_t msi_num,
20490Sstevel@tonic-gate     msiqid_t *msiq_id)
20500Sstevel@tonic-gate {
20510Sstevel@tonic-gate 	*msiq_id = CSRA_FR((caddr_t)dev_hdl, MSI_MAPPING,
20520Sstevel@tonic-gate 	    msi_num, ENTRIES_EQNUM);
20530Sstevel@tonic-gate 
20540Sstevel@tonic-gate 	return (H_EOK);
20550Sstevel@tonic-gate }
20560Sstevel@tonic-gate 
20570Sstevel@tonic-gate uint64_t
20580Sstevel@tonic-gate hvio_msi_setmsiq(devhandle_t dev_hdl, msinum_t msi_num,
20590Sstevel@tonic-gate     msiqid_t msiq_id)
20600Sstevel@tonic-gate {
20610Sstevel@tonic-gate 	CSRA_FS((caddr_t)dev_hdl, MSI_MAPPING, msi_num,
20620Sstevel@tonic-gate 	    ENTRIES_EQNUM, msiq_id);
20630Sstevel@tonic-gate 
20640Sstevel@tonic-gate 	return (H_EOK);
20650Sstevel@tonic-gate }
20660Sstevel@tonic-gate 
20670Sstevel@tonic-gate uint64_t
20680Sstevel@tonic-gate hvio_msi_getvalid(devhandle_t dev_hdl, msinum_t msi_num,
20690Sstevel@tonic-gate     pci_msi_valid_state_t *msi_valid_state)
20700Sstevel@tonic-gate {
20710Sstevel@tonic-gate 	*msi_valid_state = CSRA_BR((caddr_t)dev_hdl, MSI_MAPPING,
20720Sstevel@tonic-gate 	    msi_num, ENTRIES_V);
20730Sstevel@tonic-gate 
20740Sstevel@tonic-gate 	return (H_EOK);
20750Sstevel@tonic-gate }
20760Sstevel@tonic-gate 
20770Sstevel@tonic-gate uint64_t
20780Sstevel@tonic-gate hvio_msi_setvalid(devhandle_t dev_hdl, msinum_t msi_num,
20790Sstevel@tonic-gate     pci_msi_valid_state_t msi_valid_state)
20800Sstevel@tonic-gate {
20810Sstevel@tonic-gate 	uint64_t	ret = H_EOK;
20820Sstevel@tonic-gate 
20830Sstevel@tonic-gate 	switch (msi_valid_state) {
20840Sstevel@tonic-gate 	case PCI_MSI_VALID:
20850Sstevel@tonic-gate 		CSRA_BS((caddr_t)dev_hdl, MSI_MAPPING, msi_num,
20860Sstevel@tonic-gate 		    ENTRIES_V);
20870Sstevel@tonic-gate 		break;
20880Sstevel@tonic-gate 	case PCI_MSI_INVALID:
20890Sstevel@tonic-gate 		CSRA_BC((caddr_t)dev_hdl, MSI_MAPPING, msi_num,
20900Sstevel@tonic-gate 		    ENTRIES_V);
20910Sstevel@tonic-gate 		break;
20920Sstevel@tonic-gate 	default:
20930Sstevel@tonic-gate 		ret = H_EINVAL;
20940Sstevel@tonic-gate 	}
20950Sstevel@tonic-gate 
20960Sstevel@tonic-gate 	return (ret);
20970Sstevel@tonic-gate }
20980Sstevel@tonic-gate 
20990Sstevel@tonic-gate uint64_t
21000Sstevel@tonic-gate hvio_msi_getstate(devhandle_t dev_hdl, msinum_t msi_num,
21010Sstevel@tonic-gate     pci_msi_state_t *msi_state)
21020Sstevel@tonic-gate {
21030Sstevel@tonic-gate 	*msi_state = CSRA_BR((caddr_t)dev_hdl, MSI_MAPPING,
21040Sstevel@tonic-gate 	    msi_num, ENTRIES_EQWR_N);
21050Sstevel@tonic-gate 
21060Sstevel@tonic-gate 	return (H_EOK);
21070Sstevel@tonic-gate }
21080Sstevel@tonic-gate 
21090Sstevel@tonic-gate uint64_t
21100Sstevel@tonic-gate hvio_msi_setstate(devhandle_t dev_hdl, msinum_t msi_num,
21110Sstevel@tonic-gate     pci_msi_state_t msi_state)
21120Sstevel@tonic-gate {
21130Sstevel@tonic-gate 	uint64_t	ret = H_EOK;
21140Sstevel@tonic-gate 
21150Sstevel@tonic-gate 	switch (msi_state) {
21160Sstevel@tonic-gate 	case PCI_MSI_STATE_IDLE:
21170Sstevel@tonic-gate 		CSRA_BS((caddr_t)dev_hdl, MSI_CLEAR, msi_num,
21180Sstevel@tonic-gate 		    ENTRIES_EQWR_N);
21190Sstevel@tonic-gate 		break;
21200Sstevel@tonic-gate 	case PCI_MSI_STATE_DELIVERED:
21210Sstevel@tonic-gate 	default:
21220Sstevel@tonic-gate 		ret = H_EINVAL;
21230Sstevel@tonic-gate 		break;
21240Sstevel@tonic-gate 	}
21250Sstevel@tonic-gate 
21260Sstevel@tonic-gate 	return (ret);
21270Sstevel@tonic-gate }
21280Sstevel@tonic-gate 
21290Sstevel@tonic-gate /*
21300Sstevel@tonic-gate  * MSG Functions:
21310Sstevel@tonic-gate  */
21320Sstevel@tonic-gate uint64_t
21330Sstevel@tonic-gate hvio_msg_getmsiq(devhandle_t dev_hdl, pcie_msg_type_t msg_type,
21340Sstevel@tonic-gate     msiqid_t *msiq_id)
21350Sstevel@tonic-gate {
21360Sstevel@tonic-gate 	uint64_t	ret = H_EOK;
21370Sstevel@tonic-gate 
21380Sstevel@tonic-gate 	switch (msg_type) {
21390Sstevel@tonic-gate 	case PCIE_PME_MSG:
21400Sstevel@tonic-gate 		*msiq_id = CSR_FR((caddr_t)dev_hdl, PM_PME_MAPPING, EQNUM);
21410Sstevel@tonic-gate 		break;
21420Sstevel@tonic-gate 	case PCIE_PME_ACK_MSG:
21430Sstevel@tonic-gate 		*msiq_id = CSR_FR((caddr_t)dev_hdl, PME_TO_ACK_MAPPING,
21440Sstevel@tonic-gate 		    EQNUM);
21450Sstevel@tonic-gate 		break;
21460Sstevel@tonic-gate 	case PCIE_CORR_MSG:
21470Sstevel@tonic-gate 		*msiq_id = CSR_FR((caddr_t)dev_hdl, ERR_COR_MAPPING, EQNUM);
21480Sstevel@tonic-gate 		break;
21490Sstevel@tonic-gate 	case PCIE_NONFATAL_MSG:
21500Sstevel@tonic-gate 		*msiq_id = CSR_FR((caddr_t)dev_hdl, ERR_NONFATAL_MAPPING,
21510Sstevel@tonic-gate 		    EQNUM);
21520Sstevel@tonic-gate 		break;
21530Sstevel@tonic-gate 	case PCIE_FATAL_MSG:
21540Sstevel@tonic-gate 		*msiq_id = CSR_FR((caddr_t)dev_hdl, ERR_FATAL_MAPPING, EQNUM);
21550Sstevel@tonic-gate 		break;
21560Sstevel@tonic-gate 	default:
21570Sstevel@tonic-gate 		ret = H_EINVAL;
21580Sstevel@tonic-gate 		break;
21590Sstevel@tonic-gate 	}
21600Sstevel@tonic-gate 
21610Sstevel@tonic-gate 	return (ret);
21620Sstevel@tonic-gate }
21630Sstevel@tonic-gate 
21640Sstevel@tonic-gate uint64_t
21650Sstevel@tonic-gate hvio_msg_setmsiq(devhandle_t dev_hdl, pcie_msg_type_t msg_type,
21660Sstevel@tonic-gate     msiqid_t msiq_id)
21670Sstevel@tonic-gate {
21680Sstevel@tonic-gate 	uint64_t	ret = H_EOK;
21690Sstevel@tonic-gate 
21700Sstevel@tonic-gate 	switch (msg_type) {
21710Sstevel@tonic-gate 	case PCIE_PME_MSG:
21720Sstevel@tonic-gate 		CSR_FS((caddr_t)dev_hdl, PM_PME_MAPPING, EQNUM, msiq_id);
21730Sstevel@tonic-gate 		break;
21740Sstevel@tonic-gate 	case PCIE_PME_ACK_MSG:
21750Sstevel@tonic-gate 		CSR_FS((caddr_t)dev_hdl, PME_TO_ACK_MAPPING, EQNUM, msiq_id);
21760Sstevel@tonic-gate 		break;
21770Sstevel@tonic-gate 	case PCIE_CORR_MSG:
21780Sstevel@tonic-gate 		CSR_FS((caddr_t)dev_hdl, ERR_COR_MAPPING, EQNUM, msiq_id);
21790Sstevel@tonic-gate 		break;
21800Sstevel@tonic-gate 	case PCIE_NONFATAL_MSG:
21810Sstevel@tonic-gate 		CSR_FS((caddr_t)dev_hdl, ERR_NONFATAL_MAPPING, EQNUM, msiq_id);
21820Sstevel@tonic-gate 		break;
21830Sstevel@tonic-gate 	case PCIE_FATAL_MSG:
21840Sstevel@tonic-gate 		CSR_FS((caddr_t)dev_hdl, ERR_FATAL_MAPPING, EQNUM, msiq_id);
21850Sstevel@tonic-gate 		break;
21860Sstevel@tonic-gate 	default:
21870Sstevel@tonic-gate 		ret = H_EINVAL;
21880Sstevel@tonic-gate 		break;
21890Sstevel@tonic-gate 	}
21900Sstevel@tonic-gate 
21910Sstevel@tonic-gate 	return (ret);
21920Sstevel@tonic-gate }
21930Sstevel@tonic-gate 
21940Sstevel@tonic-gate uint64_t
21950Sstevel@tonic-gate hvio_msg_getvalid(devhandle_t dev_hdl, pcie_msg_type_t msg_type,
21960Sstevel@tonic-gate     pcie_msg_valid_state_t *msg_valid_state)
21970Sstevel@tonic-gate {
21980Sstevel@tonic-gate 	uint64_t	ret = H_EOK;
21990Sstevel@tonic-gate 
22000Sstevel@tonic-gate 	switch (msg_type) {
22010Sstevel@tonic-gate 	case PCIE_PME_MSG:
22020Sstevel@tonic-gate 		*msg_valid_state = CSR_BR((caddr_t)dev_hdl, PM_PME_MAPPING, V);
22030Sstevel@tonic-gate 		break;
22040Sstevel@tonic-gate 	case PCIE_PME_ACK_MSG:
22050Sstevel@tonic-gate 		*msg_valid_state = CSR_BR((caddr_t)dev_hdl,
22060Sstevel@tonic-gate 		    PME_TO_ACK_MAPPING, V);
22070Sstevel@tonic-gate 		break;
22080Sstevel@tonic-gate 	case PCIE_CORR_MSG:
22090Sstevel@tonic-gate 		*msg_valid_state = CSR_BR((caddr_t)dev_hdl, ERR_COR_MAPPING, V);
22100Sstevel@tonic-gate 		break;
22110Sstevel@tonic-gate 	case PCIE_NONFATAL_MSG:
22120Sstevel@tonic-gate 		*msg_valid_state = CSR_BR((caddr_t)dev_hdl,
22130Sstevel@tonic-gate 		    ERR_NONFATAL_MAPPING, V);
22140Sstevel@tonic-gate 		break;
22150Sstevel@tonic-gate 	case PCIE_FATAL_MSG:
22160Sstevel@tonic-gate 		*msg_valid_state = CSR_BR((caddr_t)dev_hdl, ERR_FATAL_MAPPING,
22170Sstevel@tonic-gate 		    V);
22180Sstevel@tonic-gate 		break;
22190Sstevel@tonic-gate 	default:
22200Sstevel@tonic-gate 		ret = H_EINVAL;
22210Sstevel@tonic-gate 		break;
22220Sstevel@tonic-gate 	}
22230Sstevel@tonic-gate 
22240Sstevel@tonic-gate 	return (ret);
22250Sstevel@tonic-gate }
22260Sstevel@tonic-gate 
22270Sstevel@tonic-gate uint64_t
22280Sstevel@tonic-gate hvio_msg_setvalid(devhandle_t dev_hdl, pcie_msg_type_t msg_type,
22290Sstevel@tonic-gate     pcie_msg_valid_state_t msg_valid_state)
22300Sstevel@tonic-gate {
22310Sstevel@tonic-gate 	uint64_t	ret = H_EOK;
22320Sstevel@tonic-gate 
22330Sstevel@tonic-gate 	switch (msg_valid_state) {
22340Sstevel@tonic-gate 	case PCIE_MSG_VALID:
22350Sstevel@tonic-gate 		switch (msg_type) {
22360Sstevel@tonic-gate 		case PCIE_PME_MSG:
22370Sstevel@tonic-gate 			CSR_BS((caddr_t)dev_hdl, PM_PME_MAPPING, V);
22380Sstevel@tonic-gate 			break;
22390Sstevel@tonic-gate 		case PCIE_PME_ACK_MSG:
22400Sstevel@tonic-gate 			CSR_BS((caddr_t)dev_hdl, PME_TO_ACK_MAPPING, V);
22410Sstevel@tonic-gate 			break;
22420Sstevel@tonic-gate 		case PCIE_CORR_MSG:
22430Sstevel@tonic-gate 			CSR_BS((caddr_t)dev_hdl, ERR_COR_MAPPING, V);
22440Sstevel@tonic-gate 			break;
22450Sstevel@tonic-gate 		case PCIE_NONFATAL_MSG:
22460Sstevel@tonic-gate 			CSR_BS((caddr_t)dev_hdl, ERR_NONFATAL_MAPPING, V);
22470Sstevel@tonic-gate 			break;
22480Sstevel@tonic-gate 		case PCIE_FATAL_MSG:
22490Sstevel@tonic-gate 			CSR_BS((caddr_t)dev_hdl, ERR_FATAL_MAPPING, V);
22500Sstevel@tonic-gate 			break;
22510Sstevel@tonic-gate 		default:
22520Sstevel@tonic-gate 			ret = H_EINVAL;
22530Sstevel@tonic-gate 			break;
22540Sstevel@tonic-gate 		}
22550Sstevel@tonic-gate 
22560Sstevel@tonic-gate 		break;
22570Sstevel@tonic-gate 	case PCIE_MSG_INVALID:
22580Sstevel@tonic-gate 		switch (msg_type) {
22590Sstevel@tonic-gate 		case PCIE_PME_MSG:
22600Sstevel@tonic-gate 			CSR_BC((caddr_t)dev_hdl, PM_PME_MAPPING, V);
22610Sstevel@tonic-gate 			break;
22620Sstevel@tonic-gate 		case PCIE_PME_ACK_MSG:
22630Sstevel@tonic-gate 			CSR_BC((caddr_t)dev_hdl, PME_TO_ACK_MAPPING, V);
22640Sstevel@tonic-gate 			break;
22650Sstevel@tonic-gate 		case PCIE_CORR_MSG:
22660Sstevel@tonic-gate 			CSR_BC((caddr_t)dev_hdl, ERR_COR_MAPPING, V);
22670Sstevel@tonic-gate 			break;
22680Sstevel@tonic-gate 		case PCIE_NONFATAL_MSG:
22690Sstevel@tonic-gate 			CSR_BC((caddr_t)dev_hdl, ERR_NONFATAL_MAPPING, V);
22700Sstevel@tonic-gate 			break;
22710Sstevel@tonic-gate 		case PCIE_FATAL_MSG:
22720Sstevel@tonic-gate 			CSR_BC((caddr_t)dev_hdl, ERR_FATAL_MAPPING, V);
22730Sstevel@tonic-gate 			break;
22740Sstevel@tonic-gate 		default:
22750Sstevel@tonic-gate 			ret = H_EINVAL;
22760Sstevel@tonic-gate 			break;
22770Sstevel@tonic-gate 		}
22780Sstevel@tonic-gate 		break;
22790Sstevel@tonic-gate 	default:
22800Sstevel@tonic-gate 		ret = H_EINVAL;
22810Sstevel@tonic-gate 	}
22820Sstevel@tonic-gate 
22830Sstevel@tonic-gate 	return (ret);
22840Sstevel@tonic-gate }
22850Sstevel@tonic-gate 
22860Sstevel@tonic-gate /*
22870Sstevel@tonic-gate  * Suspend/Resume Functions:
22880Sstevel@tonic-gate  *	(pec, mmu, ib)
22890Sstevel@tonic-gate  *	cb
22900Sstevel@tonic-gate  * Registers saved have all been touched in the XXX_init functions.
22910Sstevel@tonic-gate  */
22920Sstevel@tonic-gate uint64_t
22930Sstevel@tonic-gate hvio_suspend(devhandle_t dev_hdl, pxu_t *pxu_p)
22940Sstevel@tonic-gate {
22950Sstevel@tonic-gate 	uint64_t	*config_state;
22960Sstevel@tonic-gate 	int		total_size;
22970Sstevel@tonic-gate 	int		i;
22980Sstevel@tonic-gate 
22990Sstevel@tonic-gate 	if (msiq_suspend(dev_hdl, pxu_p) != H_EOK)
23000Sstevel@tonic-gate 		return (H_EIO);
23010Sstevel@tonic-gate 
23020Sstevel@tonic-gate 	total_size = PEC_SIZE + MMU_SIZE + IB_SIZE + IB_MAP_SIZE;
23030Sstevel@tonic-gate 	config_state = kmem_zalloc(total_size, KM_NOSLEEP);
23040Sstevel@tonic-gate 
23050Sstevel@tonic-gate 	if (config_state == NULL) {
23060Sstevel@tonic-gate 		return (H_EIO);
23070Sstevel@tonic-gate 	}
23080Sstevel@tonic-gate 
23090Sstevel@tonic-gate 	/*
23100Sstevel@tonic-gate 	 * Soft state for suspend/resume  from pxu_t
23110Sstevel@tonic-gate 	 * uint64_t	*pec_config_state;
23120Sstevel@tonic-gate 	 * uint64_t	*mmu_config_state;
23130Sstevel@tonic-gate 	 * uint64_t	*ib_intr_map;
23140Sstevel@tonic-gate 	 * uint64_t	*ib_config_state;
23150Sstevel@tonic-gate 	 * uint64_t	*xcb_config_state;
23160Sstevel@tonic-gate 	 */
23170Sstevel@tonic-gate 
23180Sstevel@tonic-gate 	/* Save the PEC configuration states */
23190Sstevel@tonic-gate 	pxu_p->pec_config_state = config_state;
23200Sstevel@tonic-gate 	for (i = 0; i < PEC_KEYS; i++) {
23210Sstevel@tonic-gate 		pxu_p->pec_config_state[i] =
23220Sstevel@tonic-gate 		    CSR_XR((caddr_t)dev_hdl, pec_config_state_regs[i]);
23230Sstevel@tonic-gate 	}
23240Sstevel@tonic-gate 
23250Sstevel@tonic-gate 	/* Save the MMU configuration states */
23260Sstevel@tonic-gate 	pxu_p->mmu_config_state = pxu_p->pec_config_state + PEC_KEYS;
23270Sstevel@tonic-gate 	for (i = 0; i < MMU_KEYS; i++) {
23280Sstevel@tonic-gate 		pxu_p->mmu_config_state[i] =
23290Sstevel@tonic-gate 		    CSR_XR((caddr_t)dev_hdl, mmu_config_state_regs[i]);
23300Sstevel@tonic-gate 	}
23310Sstevel@tonic-gate 
23320Sstevel@tonic-gate 	/* Save the interrupt mapping registers */
23330Sstevel@tonic-gate 	pxu_p->ib_intr_map = pxu_p->mmu_config_state + MMU_KEYS;
23340Sstevel@tonic-gate 	for (i = 0; i < INTERRUPT_MAPPING_ENTRIES; i++) {
23350Sstevel@tonic-gate 		pxu_p->ib_intr_map[i] =
23360Sstevel@tonic-gate 		    CSRA_XR((caddr_t)dev_hdl, INTERRUPT_MAPPING, i);
23370Sstevel@tonic-gate 	}
23380Sstevel@tonic-gate 
23390Sstevel@tonic-gate 	/* Save the IB configuration states */
23400Sstevel@tonic-gate 	pxu_p->ib_config_state = pxu_p->ib_intr_map + INTERRUPT_MAPPING_ENTRIES;
23410Sstevel@tonic-gate 	for (i = 0; i < IB_KEYS; i++) {
23420Sstevel@tonic-gate 		pxu_p->ib_config_state[i] =
23430Sstevel@tonic-gate 		    CSR_XR((caddr_t)dev_hdl, ib_config_state_regs[i]);
23440Sstevel@tonic-gate 	}
23450Sstevel@tonic-gate 
23460Sstevel@tonic-gate 	return (H_EOK);
23470Sstevel@tonic-gate }
23480Sstevel@tonic-gate 
23490Sstevel@tonic-gate void
23500Sstevel@tonic-gate hvio_resume(devhandle_t dev_hdl, devino_t devino, pxu_t *pxu_p)
23510Sstevel@tonic-gate {
23520Sstevel@tonic-gate 	int		total_size;
23530Sstevel@tonic-gate 	sysino_t	sysino;
23540Sstevel@tonic-gate 	int		i;
23550Sstevel@tonic-gate 
23560Sstevel@tonic-gate 	/* Make sure that suspend actually did occur */
23570Sstevel@tonic-gate 	if (!pxu_p->pec_config_state) {
23580Sstevel@tonic-gate 		return;
23590Sstevel@tonic-gate 	}
23600Sstevel@tonic-gate 
23610Sstevel@tonic-gate 	/* Restore IB configuration states */
23620Sstevel@tonic-gate 	for (i = 0; i < IB_KEYS; i++) {
23630Sstevel@tonic-gate 		CSR_XS((caddr_t)dev_hdl, ib_config_state_regs[i],
23640Sstevel@tonic-gate 		    pxu_p->ib_config_state[i]);
23650Sstevel@tonic-gate 	}
23660Sstevel@tonic-gate 
23670Sstevel@tonic-gate 	/*
23680Sstevel@tonic-gate 	 * Restore the interrupt mapping registers
23690Sstevel@tonic-gate 	 * And make sure the intrs are idle.
23700Sstevel@tonic-gate 	 */
23710Sstevel@tonic-gate 	for (i = 0; i < INTERRUPT_MAPPING_ENTRIES; i++) {
23720Sstevel@tonic-gate 		CSRA_FS((caddr_t)dev_hdl, INTERRUPT_CLEAR, i,
23730Sstevel@tonic-gate 		    ENTRIES_INT_STATE, INTERRUPT_IDLE_STATE);
23740Sstevel@tonic-gate 		CSRA_XS((caddr_t)dev_hdl, INTERRUPT_MAPPING, i,
23750Sstevel@tonic-gate 		    pxu_p->ib_intr_map[i]);
23760Sstevel@tonic-gate 	}
23770Sstevel@tonic-gate 
23780Sstevel@tonic-gate 	/* Restore MMU configuration states */
23790Sstevel@tonic-gate 	/* Clear the cache. */
23800Sstevel@tonic-gate 	CSR_XS((caddr_t)dev_hdl, MMU_TTE_CACHE_INVALIDATE, -1ull);
23810Sstevel@tonic-gate 
23820Sstevel@tonic-gate 	for (i = 0; i < MMU_KEYS; i++) {
23830Sstevel@tonic-gate 		CSR_XS((caddr_t)dev_hdl, mmu_config_state_regs[i],
23840Sstevel@tonic-gate 		    pxu_p->mmu_config_state[i]);
23850Sstevel@tonic-gate 	}
23860Sstevel@tonic-gate 
23870Sstevel@tonic-gate 	/* Restore PEC configuration states */
23880Sstevel@tonic-gate 	/* Make sure all reset bits are low until error is detected */
23890Sstevel@tonic-gate 	CSR_XS((caddr_t)dev_hdl, LPU_RESET, 0ull);
23900Sstevel@tonic-gate 
23910Sstevel@tonic-gate 	for (i = 0; i < PEC_KEYS; i++) {
23920Sstevel@tonic-gate 		CSR_XS((caddr_t)dev_hdl, pec_config_state_regs[i],
23930Sstevel@tonic-gate 		    pxu_p->pec_config_state[i]);
23940Sstevel@tonic-gate 	}
23950Sstevel@tonic-gate 
23960Sstevel@tonic-gate 	/* Enable PCI-E interrupt */
23970Sstevel@tonic-gate 	(void) hvio_intr_devino_to_sysino(dev_hdl, pxu_p, devino, &sysino);
23980Sstevel@tonic-gate 
23990Sstevel@tonic-gate 	(void) hvio_intr_setstate(dev_hdl, sysino, INTR_IDLE_STATE);
24000Sstevel@tonic-gate 
24010Sstevel@tonic-gate 	total_size = PEC_SIZE + MMU_SIZE + IB_SIZE + IB_MAP_SIZE;
24020Sstevel@tonic-gate 	kmem_free(pxu_p->pec_config_state, total_size);
24030Sstevel@tonic-gate 
24040Sstevel@tonic-gate 	pxu_p->pec_config_state = NULL;
24050Sstevel@tonic-gate 	pxu_p->mmu_config_state = NULL;
24060Sstevel@tonic-gate 	pxu_p->ib_config_state = NULL;
24070Sstevel@tonic-gate 	pxu_p->ib_intr_map = NULL;
24080Sstevel@tonic-gate 
24090Sstevel@tonic-gate 	msiq_resume(dev_hdl, pxu_p);
24100Sstevel@tonic-gate }
24110Sstevel@tonic-gate 
24120Sstevel@tonic-gate uint64_t
24130Sstevel@tonic-gate hvio_cb_suspend(devhandle_t dev_hdl, pxu_t *pxu_p)
24140Sstevel@tonic-gate {
24150Sstevel@tonic-gate 	uint64_t	*config_state;
24160Sstevel@tonic-gate 	int		i;
24170Sstevel@tonic-gate 
24180Sstevel@tonic-gate 	config_state = kmem_zalloc(CB_SIZE, KM_NOSLEEP);
24190Sstevel@tonic-gate 
24200Sstevel@tonic-gate 	if (config_state == NULL) {
24210Sstevel@tonic-gate 		return (H_EIO);
24220Sstevel@tonic-gate 	}
24230Sstevel@tonic-gate 
24240Sstevel@tonic-gate 	/* Save the configuration states */
24250Sstevel@tonic-gate 	pxu_p->xcb_config_state = config_state;
24260Sstevel@tonic-gate 	for (i = 0; i < CB_KEYS; i++) {
24270Sstevel@tonic-gate 		pxu_p->xcb_config_state[i] =
24280Sstevel@tonic-gate 		    CSR_XR((caddr_t)dev_hdl, cb_config_state_regs[i]);
24290Sstevel@tonic-gate 	}
24300Sstevel@tonic-gate 
24310Sstevel@tonic-gate 	return (H_EOK);
24320Sstevel@tonic-gate }
24330Sstevel@tonic-gate 
24340Sstevel@tonic-gate void
24350Sstevel@tonic-gate hvio_cb_resume(devhandle_t pci_dev_hdl, devhandle_t xbus_dev_hdl,
24360Sstevel@tonic-gate     devino_t devino, pxu_t *pxu_p)
24370Sstevel@tonic-gate {
24380Sstevel@tonic-gate 	sysino_t	sysino;
24390Sstevel@tonic-gate 	int		i;
24400Sstevel@tonic-gate 
24410Sstevel@tonic-gate 	/*
24420Sstevel@tonic-gate 	 * No reason to have any reset bits high until an error is
24430Sstevel@tonic-gate 	 * detected on the link.
24440Sstevel@tonic-gate 	 */
24450Sstevel@tonic-gate 	CSR_XS((caddr_t)xbus_dev_hdl, JBC_ERROR_STATUS_CLEAR, -1ull);
24460Sstevel@tonic-gate 
24470Sstevel@tonic-gate 	ASSERT(pxu_p->xcb_config_state);
24480Sstevel@tonic-gate 
24490Sstevel@tonic-gate 	/* Restore the configuration states */
24500Sstevel@tonic-gate 	for (i = 0; i < CB_KEYS; i++) {
24510Sstevel@tonic-gate 		CSR_XS((caddr_t)xbus_dev_hdl, cb_config_state_regs[i],
24520Sstevel@tonic-gate 		    pxu_p->xcb_config_state[i]);
24530Sstevel@tonic-gate 	}
24540Sstevel@tonic-gate 
24550Sstevel@tonic-gate 	/* Enable XBC interrupt */
24560Sstevel@tonic-gate 	(void) hvio_intr_devino_to_sysino(pci_dev_hdl, pxu_p, devino, &sysino);
24570Sstevel@tonic-gate 
24580Sstevel@tonic-gate 	(void) hvio_intr_setstate(pci_dev_hdl, sysino, INTR_IDLE_STATE);
24590Sstevel@tonic-gate 
24600Sstevel@tonic-gate 	kmem_free(pxu_p->xcb_config_state, CB_SIZE);
24610Sstevel@tonic-gate 
24620Sstevel@tonic-gate 	pxu_p->xcb_config_state = NULL;
24630Sstevel@tonic-gate }
24640Sstevel@tonic-gate 
24650Sstevel@tonic-gate static uint64_t
24660Sstevel@tonic-gate msiq_suspend(devhandle_t dev_hdl, pxu_t *pxu_p)
24670Sstevel@tonic-gate {
24680Sstevel@tonic-gate 	size_t	bufsz;
24690Sstevel@tonic-gate 	volatile uint64_t *cur_p;
24700Sstevel@tonic-gate 	int i;
24710Sstevel@tonic-gate 
24720Sstevel@tonic-gate 	bufsz = MSIQ_STATE_SIZE + MSIQ_MAPPING_SIZE + MSIQ_OTHER_SIZE;
24730Sstevel@tonic-gate 	if ((pxu_p->msiq_config_state = kmem_zalloc(bufsz, KM_NOSLEEP)) ==
24740Sstevel@tonic-gate 	    NULL)
24750Sstevel@tonic-gate 		return (H_EIO);
24760Sstevel@tonic-gate 
24770Sstevel@tonic-gate 	cur_p = pxu_p->msiq_config_state;
24780Sstevel@tonic-gate 
24790Sstevel@tonic-gate 	/* Save each EQ state */
24800Sstevel@tonic-gate 	for (i = 0; i < EVENT_QUEUE_STATE_ENTRIES; i++, cur_p++)
24810Sstevel@tonic-gate 		*cur_p = CSRA_XR((caddr_t)dev_hdl, EVENT_QUEUE_STATE, i);
24820Sstevel@tonic-gate 
24830Sstevel@tonic-gate 	/* Save MSI mapping registers */
24840Sstevel@tonic-gate 	for (i = 0; i < MSI_MAPPING_ENTRIES; i++, cur_p++)
24850Sstevel@tonic-gate 		*cur_p = CSRA_XR((caddr_t)dev_hdl, MSI_MAPPING, i);
24860Sstevel@tonic-gate 
24870Sstevel@tonic-gate 	/* Save all other MSIQ registers */
24880Sstevel@tonic-gate 	for (i = 0; i < MSIQ_OTHER_KEYS; i++, cur_p++)
24890Sstevel@tonic-gate 		*cur_p = CSR_XR((caddr_t)dev_hdl, msiq_config_other_regs[i]);
24900Sstevel@tonic-gate 	return (H_EOK);
24910Sstevel@tonic-gate }
24920Sstevel@tonic-gate 
24930Sstevel@tonic-gate static void
24940Sstevel@tonic-gate msiq_resume(devhandle_t dev_hdl, pxu_t *pxu_p)
24950Sstevel@tonic-gate {
24960Sstevel@tonic-gate 	size_t	bufsz;
24970Sstevel@tonic-gate 	uint64_t *cur_p;
24980Sstevel@tonic-gate 	int i;
24990Sstevel@tonic-gate 
25000Sstevel@tonic-gate 	bufsz = MSIQ_STATE_SIZE + MSIQ_MAPPING_SIZE + MSIQ_OTHER_SIZE;
25010Sstevel@tonic-gate 	cur_p = pxu_p->msiq_config_state;
25020Sstevel@tonic-gate 	/*
25030Sstevel@tonic-gate 	 * Initialize EQ base address register and
25040Sstevel@tonic-gate 	 * Interrupt Mondo Data 0 register.
25050Sstevel@tonic-gate 	 */
25060Sstevel@tonic-gate 	(void) hvio_msiq_init(dev_hdl, pxu_p);
25070Sstevel@tonic-gate 
25080Sstevel@tonic-gate 	/* Restore EQ states */
25090Sstevel@tonic-gate 	for (i = 0; i < EVENT_QUEUE_STATE_ENTRIES; i++, cur_p++) {
25100Sstevel@tonic-gate 		if (((*cur_p) & EVENT_QUEUE_STATE_ENTRIES_STATE_MASK) ==
25110Sstevel@tonic-gate 		    EQ_ACTIVE_STATE) {
25120Sstevel@tonic-gate 			CSRA_BS((caddr_t)dev_hdl, EVENT_QUEUE_CONTROL_SET,
25130Sstevel@tonic-gate 			    i, ENTRIES_EN);
25140Sstevel@tonic-gate 		}
25150Sstevel@tonic-gate 	}
25160Sstevel@tonic-gate 
25170Sstevel@tonic-gate 	/* Restore MSI mapping */
25180Sstevel@tonic-gate 	for (i = 0; i < MSI_MAPPING_ENTRIES; i++, cur_p++)
25190Sstevel@tonic-gate 		CSRA_XS((caddr_t)dev_hdl, MSI_MAPPING, i, *cur_p);
25200Sstevel@tonic-gate 
25210Sstevel@tonic-gate 	/*
25220Sstevel@tonic-gate 	 * Restore all other registers. MSI 32 bit address and
25230Sstevel@tonic-gate 	 * MSI 64 bit address are restored as part of this.
25240Sstevel@tonic-gate 	 */
25250Sstevel@tonic-gate 	for (i = 0; i < MSIQ_OTHER_KEYS; i++, cur_p++)
25260Sstevel@tonic-gate 		CSR_XS((caddr_t)dev_hdl, msiq_config_other_regs[i], *cur_p);
25270Sstevel@tonic-gate 
25280Sstevel@tonic-gate 	kmem_free(pxu_p->msiq_config_state, bufsz);
25290Sstevel@tonic-gate 	pxu_p->msiq_config_state = NULL;
25300Sstevel@tonic-gate }
25310Sstevel@tonic-gate 
25320Sstevel@tonic-gate /*
25330Sstevel@tonic-gate  * sends PME_Turn_Off message to put the link in L2/L3 ready state.
25340Sstevel@tonic-gate  * called by px_goto_l23ready.
25350Sstevel@tonic-gate  * returns DDI_SUCCESS or DDI_FAILURE
25360Sstevel@tonic-gate  */
25370Sstevel@tonic-gate int
25380Sstevel@tonic-gate px_send_pme_turnoff(caddr_t csr_base)
25390Sstevel@tonic-gate {
25400Sstevel@tonic-gate 	volatile uint64_t reg;
25410Sstevel@tonic-gate 
25420Sstevel@tonic-gate 	reg = CSR_XR(csr_base, TLU_PME_TURN_OFF_GENERATE);
25430Sstevel@tonic-gate 	/* If already pending, return failure */
25440Sstevel@tonic-gate 	if (reg & (1ull << TLU_PME_TURN_OFF_GENERATE_PTO)) {
2545118Sjchu 		DBG(DBG_PWR, NULL, "send_pme_turnoff: pending PTO bit "
2546118Sjchu 		    "tlu_pme_turn_off_generate = %x\n", reg);
25470Sstevel@tonic-gate 		return (DDI_FAILURE);
25480Sstevel@tonic-gate 	}
254927Sjchu 
25500Sstevel@tonic-gate 	/* write to PME_Turn_off reg to boradcast */
25510Sstevel@tonic-gate 	reg |= (1ull << TLU_PME_TURN_OFF_GENERATE_PTO);
25520Sstevel@tonic-gate 	CSR_XS(csr_base,  TLU_PME_TURN_OFF_GENERATE, reg);
2553118Sjchu 
25540Sstevel@tonic-gate 	return (DDI_SUCCESS);
25550Sstevel@tonic-gate }
2556118Sjchu 
2557118Sjchu /*
2558118Sjchu  * Checks for link being in L1idle state.
2559118Sjchu  * Returns
2560118Sjchu  * DDI_SUCCESS - if the link is in L1idle
2561118Sjchu  * DDI_FAILURE - if the link is not in L1idle
2562118Sjchu  */
2563118Sjchu int
2564118Sjchu px_link_wait4l1idle(caddr_t csr_base)
2565118Sjchu {
2566118Sjchu 	uint8_t ltssm_state;
2567118Sjchu 	int ntries = px_max_l1_tries;
2568118Sjchu 
2569118Sjchu 	while (ntries > 0) {
2570118Sjchu 		ltssm_state = CSR_FR(csr_base, LPU_LTSSM_STATUS1, LTSSM_STATE);
2571118Sjchu 		if (ltssm_state == LPU_LTSSM_L1_IDLE || (--ntries <= 0))
2572118Sjchu 			break;
2573118Sjchu 		delay(1);
2574118Sjchu 	}
2575118Sjchu 	DBG(DBG_PWR, NULL, "check_for_l1idle: ltssm_state %x\n", ltssm_state);
2576118Sjchu 	return ((ltssm_state == LPU_LTSSM_L1_IDLE) ? DDI_SUCCESS : DDI_FAILURE);
2577118Sjchu }
2578118Sjchu 
2579118Sjchu /*
2580118Sjchu  * Tranisition the link to L0, after it is down.
2581118Sjchu  */
2582118Sjchu int
2583118Sjchu px_link_retrain(caddr_t csr_base)
2584118Sjchu {
2585118Sjchu 	volatile uint64_t reg;
2586118Sjchu 
2587118Sjchu 	reg = CSR_XR(csr_base, TLU_CONTROL);
2588118Sjchu 	if (!(reg & (1ull << TLU_REMAIN_DETECT_QUIET))) {
2589118Sjchu 		DBG(DBG_PWR, NULL, "retrain_link: detect.quiet bit not set\n");
2590118Sjchu 		return (DDI_FAILURE);
2591118Sjchu 	}
2592118Sjchu 
2593118Sjchu 	/* Clear link down bit in TLU Other Event Clear Status Register. */
2594118Sjchu 	CSR_BS(csr_base, TLU_OTHER_EVENT_STATUS_CLEAR, LDN_P);
2595118Sjchu 
2596118Sjchu 	/* Clear Drain bit in TLU Status Register */
2597118Sjchu 	CSR_BS(csr_base, TLU_STATUS, DRAIN);
2598118Sjchu 
2599118Sjchu 	/* Clear Remain in Detect.Quiet bit in TLU Control Register */
2600118Sjchu 	reg = CSR_XR(csr_base, TLU_CONTROL);
2601118Sjchu 	reg &= ~(1ull << TLU_REMAIN_DETECT_QUIET);
2602118Sjchu 	CSR_XS(csr_base, TLU_CONTROL, reg);
2603118Sjchu 
2604118Sjchu 	return (DDI_SUCCESS);
2605118Sjchu }
2606118Sjchu 
2607118Sjchu void
2608118Sjchu px_enable_detect_quiet(caddr_t csr_base)
2609118Sjchu {
2610118Sjchu 	volatile uint64_t tlu_ctrl;
2611118Sjchu 
2612118Sjchu 	tlu_ctrl = CSR_XR(csr_base, TLU_CONTROL);
2613118Sjchu 	tlu_ctrl |= (1ull << TLU_REMAIN_DETECT_QUIET);
2614118Sjchu 	CSR_XS(csr_base, TLU_CONTROL, tlu_ctrl);
2615118Sjchu }
2616