xref: /onnv-gate/usr/src/uts/common/io/nxge/npi/npi_vir.c (revision 6929:a596171cbf16)
13859Sml29623 /*
23859Sml29623  * CDDL HEADER START
33859Sml29623  *
43859Sml29623  * The contents of this file are subject to the terms of the
53859Sml29623  * Common Development and Distribution License (the "License").
63859Sml29623  * You may not use this file except in compliance with the License.
73859Sml29623  *
83859Sml29623  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93859Sml29623  * or http://www.opensolaris.org/os/licensing.
103859Sml29623  * See the License for the specific language governing permissions
113859Sml29623  * and limitations under the License.
123859Sml29623  *
133859Sml29623  * When distributing Covered Code, include this CDDL HEADER in each
143859Sml29623  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153859Sml29623  * If applicable, add the following below this CDDL HEADER, with the
163859Sml29623  * fields enclosed by brackets "[]" replaced with your own identifying
173859Sml29623  * information: Portions Copyright [yyyy] [name of copyright owner]
183859Sml29623  *
193859Sml29623  * CDDL HEADER END
203859Sml29623  */
213859Sml29623 /*
226495Sspeer  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
233859Sml29623  * Use is subject to license terms.
243859Sml29623  */
253859Sml29623 
263859Sml29623 #pragma ident	"%Z%%M%	%I%	%E% SMI"
273859Sml29623 
283859Sml29623 #include <npi_vir.h>
293859Sml29623 
303859Sml29623 /* One register only */
313859Sml29623 uint64_t pio_offset[] = {
323859Sml29623 	DEV_FUNC_SR_REG
333859Sml29623 };
343859Sml29623 
353859Sml29623 const char *pio_name[] = {
363859Sml29623 	"DEV_FUNC_SR_REG",
373859Sml29623 };
383859Sml29623 
393859Sml29623 /* One register only */
403859Sml29623 uint64_t fzc_pio_offset[] = {
413859Sml29623 	MULTI_PART_CTL_REG,
423859Sml29623 	LDGITMRES_REG
433859Sml29623 };
443859Sml29623 
453859Sml29623 const char *fzc_pio_name[] = {
463859Sml29623 	"MULTI_PART_CTL_REG",
473859Sml29623 	"LDGITMRES_REG"
483859Sml29623 };
493859Sml29623 
503859Sml29623 /* 64 sets */
513859Sml29623 uint64_t fzc_pio_dma_bind_offset[] = {
523859Sml29623 	DMA_BIND_REG
533859Sml29623 };
543859Sml29623 
553859Sml29623 const char *fzc_pio_dma_bind_name[] = {
563859Sml29623 	"DMA_BIND_REG",
573859Sml29623 };
583859Sml29623 
593859Sml29623 /* 69 logical devices */
603859Sml29623 uint64_t fzc_pio_ldgnum_offset[] = {
613859Sml29623 	LDG_NUM_REG
623859Sml29623 };
633859Sml29623 
643859Sml29623 const char *fzc_pio_ldgnum_name[] = {
653859Sml29623 	"LDG_NUM_REG",
663859Sml29623 };
673859Sml29623 
683859Sml29623 /* PIO_LDSV, 64 sets by 8192 bytes */
693859Sml29623 uint64_t pio_ldsv_offset[] = {
703859Sml29623 	LDSV0_REG,
713859Sml29623 	LDSV1_REG,
723859Sml29623 	LDSV2_REG,
733859Sml29623 	LDGIMGN_REG
743859Sml29623 };
753859Sml29623 const char *pio_ldsv_name[] = {
763859Sml29623 	"LDSV0_REG",
773859Sml29623 	"LDSV1_REG",
783859Sml29623 	"LDSV2_REG",
793859Sml29623 	"LDGIMGN_REG"
803859Sml29623 };
813859Sml29623 
823859Sml29623 /* PIO_IMASK0: 64 by 8192 */
833859Sml29623 uint64_t pio_imask0_offset[] = {
843859Sml29623 	LD_IM0_REG,
853859Sml29623 };
863859Sml29623 
873859Sml29623 const char *pio_imask0_name[] = {
883859Sml29623 	"LD_IM0_REG",
893859Sml29623 };
903859Sml29623 
913859Sml29623 /* PIO_IMASK1: 5 by 8192 */
923859Sml29623 uint64_t pio_imask1_offset[] = {
933859Sml29623 	LD_IM1_REG
943859Sml29623 };
953859Sml29623 
963859Sml29623 const char *pio_imask1_name[] = {
973859Sml29623 	"LD_IM1_REG"
983859Sml29623 };
993859Sml29623 
1003859Sml29623 /* SID: 64 by 8 */
1013859Sml29623 uint64_t fzc_pio_sid_offset[] = {
1023859Sml29623 	SID_REG
1033859Sml29623 };
1043859Sml29623 
1053859Sml29623 const char *fzc_pio_sid_name[] = {
1063859Sml29623 	"SID_REG"
1073859Sml29623 };
1083859Sml29623 
1093859Sml29623 npi_status_t
npi_vir_dump_pio_fzc_regs_one(npi_handle_t handle)1103859Sml29623 npi_vir_dump_pio_fzc_regs_one(npi_handle_t handle)
1113859Sml29623 {
1123859Sml29623 	uint64_t value;
1133859Sml29623 	int num_regs, i;
1143859Sml29623 
1153859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
116*6929Smisaki 	    "\nPIO FZC Common Register Dump\n"));
1173859Sml29623 
1183859Sml29623 	num_regs = sizeof (pio_offset) / sizeof (uint64_t);
1193859Sml29623 	for (i = 0; i < num_regs; i++) {
1203859Sml29623 		value = 0;
1213859Sml29623 		NXGE_REG_RD64(handle, pio_offset[i], &value);
1223859Sml29623 		NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL, "0x%08llx "
123*6929Smisaki 		    "%s\t 0x%08llx \n",
124*6929Smisaki 		    pio_offset[i],
125*6929Smisaki 		    pio_name[i], value));
1263859Sml29623 	}
1273859Sml29623 
1283859Sml29623 	num_regs = sizeof (fzc_pio_offset) / sizeof (uint64_t);
1293859Sml29623 	for (i = 0; i < num_regs; i++) {
1303859Sml29623 		NXGE_REG_RD64(handle, fzc_pio_offset[i], &value);
1313859Sml29623 		NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL, "0x%08llx "
132*6929Smisaki 		    "%s\t 0x%08llx \n",
133*6929Smisaki 		    fzc_pio_offset[i],
134*6929Smisaki 		    fzc_pio_name[i], value));
1353859Sml29623 	}
1363859Sml29623 
1373859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
138*6929Smisaki 	    "\n PIO FZC Register Dump Done \n"));
1393859Sml29623 	return (NPI_SUCCESS);
1403859Sml29623 }
1413859Sml29623 
1423859Sml29623 npi_status_t
npi_vir_dump_ldgnum(npi_handle_t handle)1433859Sml29623 npi_vir_dump_ldgnum(npi_handle_t handle)
1443859Sml29623 {
1453859Sml29623 	uint64_t value = 0, offset = 0;
1463859Sml29623 	int num_regs, i, ldv;
1473859Sml29623 
1483859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
149*6929Smisaki 	    "\nFZC PIO LDG Number Register Dump\n"));
1503859Sml29623 
1513859Sml29623 	num_regs = sizeof (fzc_pio_ldgnum_offset) / sizeof (uint64_t);
1523859Sml29623 	for (ldv = 0; ldv < NXGE_INT_MAX_LDS; ldv++) {
1533859Sml29623 		for (i = 0; i < num_regs; i++) {
1543859Sml29623 			value = 0;
1553859Sml29623 			offset = fzc_pio_ldgnum_offset[i] + 8 * ldv;
1563859Sml29623 			NXGE_REG_RD64(handle, offset, &value);
1573859Sml29623 			NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
158*6929Smisaki 			    "Logical Device %d: 0x%08llx "
159*6929Smisaki 			    "%s\t %d\n",
160*6929Smisaki 			    ldv, offset,
161*6929Smisaki 			    fzc_pio_ldgnum_name[i], value));
1623859Sml29623 		}
1633859Sml29623 	}
1643859Sml29623 
1653859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
166*6929Smisaki 	    "\n FZC PIO LDG Register Dump Done \n"));
1673859Sml29623 
1683859Sml29623 	return (NPI_SUCCESS);
1693859Sml29623 }
1703859Sml29623 
1713859Sml29623 npi_status_t
npi_vir_dump_ldsv(npi_handle_t handle)1723859Sml29623 npi_vir_dump_ldsv(npi_handle_t handle)
1733859Sml29623 {
1743859Sml29623 	uint64_t value, offset;
1753859Sml29623 	int num_regs, i, ldg;
1763859Sml29623 
1773859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
178*6929Smisaki 	    "\nLD Device State Vector Register Dump\n"));
1793859Sml29623 
1803859Sml29623 	num_regs = sizeof (pio_ldsv_offset) / sizeof (uint64_t);
1813859Sml29623 	for (ldg = 0; ldg < NXGE_INT_MAX_LDGS; ldg++) {
1823859Sml29623 		for (i = 0; i < num_regs; i++) {
1833859Sml29623 			value = 0;
1843859Sml29623 			offset = pio_ldsv_offset[i] + 8192 * ldg;
1853859Sml29623 			NXGE_REG_RD64(handle, offset, &value);
1863859Sml29623 			NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
187*6929Smisaki 			    "LDG State: group %d: 0x%08llx "
188*6929Smisaki 			    "%s\t 0x%08llx \n",
189*6929Smisaki 			    ldg, offset,
190*6929Smisaki 			    pio_ldsv_name[i], value));
1913859Sml29623 		}
1923859Sml29623 	}
1933859Sml29623 
1943859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
195*6929Smisaki 	    "\n FZC PIO LDG Register Dump Done \n"));
1963859Sml29623 
1973859Sml29623 	return (NPI_SUCCESS);
1983859Sml29623 }
1993859Sml29623 
2003859Sml29623 npi_status_t
npi_vir_dump_imask0(npi_handle_t handle)2013859Sml29623 npi_vir_dump_imask0(npi_handle_t handle)
2023859Sml29623 {
2033859Sml29623 	uint64_t value, offset;
2043859Sml29623 	int num_regs, i, ldv;
2053859Sml29623 
2063859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
207*6929Smisaki 	    "\nLD Interrupt Mask Register Dump\n"));
2083859Sml29623 
2093859Sml29623 	num_regs = sizeof (pio_imask0_offset) / sizeof (uint64_t);
2103859Sml29623 	for (ldv = 0; ldv < 64; ldv++) {
2113859Sml29623 		for (i = 0; i < num_regs; i++) {
2123859Sml29623 			value = 0;
2133859Sml29623 			offset = pio_imask0_offset[i] + 8192 * ldv;
2143859Sml29623 			NXGE_REG_RD64(handle, offset,
215*6929Smisaki 			    &value);
2163859Sml29623 			NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
217*6929Smisaki 			    "LD Interrupt Mask %d: 0x%08llx "
218*6929Smisaki 			    "%s\t 0x%08llx \n",
219*6929Smisaki 			    ldv, offset,
220*6929Smisaki 			    pio_imask0_name[i], value));
2213859Sml29623 		}
2223859Sml29623 	}
2233859Sml29623 	num_regs = sizeof (pio_imask1_offset) / sizeof (uint64_t);
2243859Sml29623 	for (ldv = 64; ldv < 69; ldv++) {
2253859Sml29623 		for (i = 0; i < num_regs; i++) {
2263859Sml29623 			value = 0;
2273859Sml29623 			offset = pio_imask1_offset[i] + 8192 * (ldv - 64);
2283859Sml29623 			NXGE_REG_RD64(handle, offset,
229*6929Smisaki 			    &value);
2303859Sml29623 			NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
231*6929Smisaki 			    "LD Interrupt Mask %d: 0x%08llx "
232*6929Smisaki 			    "%s\t 0x%08llx \n",
233*6929Smisaki 			    ldv, offset,
234*6929Smisaki 			    pio_imask1_name[i], value));
2353859Sml29623 		}
2363859Sml29623 	}
2373859Sml29623 
2383859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
239*6929Smisaki 	    "\n FZC PIO Logical Device Group Register Dump Done \n"));
2403859Sml29623 
2413859Sml29623 	return (NPI_SUCCESS);
2423859Sml29623 }
2433859Sml29623 
2443859Sml29623 npi_status_t
npi_vir_dump_sid(npi_handle_t handle)2453859Sml29623 npi_vir_dump_sid(npi_handle_t handle)
2463859Sml29623 {
2473859Sml29623 	uint64_t value, offset;
2483859Sml29623 	int num_regs, i, ldg;
2493859Sml29623 
2503859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
251*6929Smisaki 	    "\nSystem Interrupt Data Register Dump\n"));
2523859Sml29623 
2533859Sml29623 	num_regs = sizeof (fzc_pio_sid_offset) / sizeof (uint64_t);
2543859Sml29623 	for (ldg = 0; ldg < NXGE_INT_MAX_LDGS; ldg++) {
2553859Sml29623 		for (i = 0; i < num_regs; i++) {
2563859Sml29623 			value = 0;
2573859Sml29623 			offset = fzc_pio_sid_offset[i] + 8 * ldg;
2583859Sml29623 			NXGE_REG_RD64(handle, offset,
259*6929Smisaki 			    &value);
2603859Sml29623 			NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
261*6929Smisaki 			    "SID for group %d: 0x%08llx "
262*6929Smisaki 			    "%s\t 0x%08llx \n",
263*6929Smisaki 			    ldg, offset,
264*6929Smisaki 			    fzc_pio_sid_name[i], value));
2653859Sml29623 		}
2663859Sml29623 	}
2673859Sml29623 
2683859Sml29623 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
269*6929Smisaki 	    "\n FZC PIO SID Register Dump Done \n"));
2703859Sml29623 
2713859Sml29623 	return (NPI_SUCCESS);
2723859Sml29623 }
2733859Sml29623 
2743859Sml29623 /*
2753859Sml29623  * npi_dev_func_sr_init():
2763859Sml29623  *	This function is called to initialize the device function
2773859Sml29623  *	shared register (set the software implementation lock
2783859Sml29623  *	state to FREE).
2793859Sml29623  * Parameters:
2803859Sml29623  *	handle		- NPI handle
2813859Sml29623  * Return:
2823859Sml29623  *	NPI_SUCCESS	- If initialization is complete successfully.
2833859Sml29623  *			  (set sr bits to free).
2843859Sml29623  *	Error:
2853859Sml29623  *	NPI_FAILURE
2863859Sml29623  *		VIR_TAS_BUSY
2873859Sml29623  */
2883859Sml29623 
2893859Sml29623 npi_status_t
npi_dev_func_sr_init(npi_handle_t handle)2903859Sml29623 npi_dev_func_sr_init(npi_handle_t handle)
2913859Sml29623 {
2923859Sml29623 	dev_func_sr_t		sr;
2933859Sml29623 	int			status = NPI_SUCCESS;
2943859Sml29623 
2953859Sml29623 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
2963859Sml29623 	if (!sr.bits.ldw.tas) {
2973859Sml29623 		/*
2983859Sml29623 		 * After read, this bit is set to 1 by hardware.
2993859Sml29623 		 * We own it if tas bit read as 0.
3003859Sml29623 		 * Set the lock state to free if it is in reset state.
3013859Sml29623 		 */
3023859Sml29623 		if (!sr.bits.ldw.sr) {
3033859Sml29623 			/* reset state */
3043859Sml29623 			sr.bits.ldw.sr |= NPI_DEV_SR_LOCK_ST_FREE;
3053859Sml29623 			NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
3063859Sml29623 			sr.bits.ldw.tas = 0;
3073859Sml29623 			NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
3083859Sml29623 		}
3093859Sml29623 
3104185Sspeer 		NPI_DEBUG_MSG((handle.function, NPI_VIR_CTL,
311*6929Smisaki 		    " npi_dev_func_sr_init"
312*6929Smisaki 		    " sr <0x%x>",
313*6929Smisaki 		    sr.bits.ldw.sr));
3143859Sml29623 	} else {
3153859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
316*6929Smisaki 		    " npi_dev_func_sr_init"
317*6929Smisaki 		    " tas busy <0x%x>",
318*6929Smisaki 		    sr.bits.ldw));
3193859Sml29623 		status = NPI_VIR_TAS_BUSY(sr.bits.ldw.funcid);
3203859Sml29623 	}
3213859Sml29623 
3223859Sml29623 	return (status);
3233859Sml29623 }
3243859Sml29623 
3253859Sml29623 /*
3263859Sml29623  * npi_dev_func_sr_lock_enter():
3273859Sml29623  *	This function is called to lock the function shared register
3283859Sml29623  *	by setting the lock state to busy.
3293859Sml29623  * Parameters:
3303859Sml29623  *	handle		- NPI handle
3313859Sml29623  * Return:
3323859Sml29623  *	NPI_SUCCESS	- If the function id can own the lock.
3333859Sml29623  *
3343859Sml29623  *	Error:
3353859Sml29623  *	NPI_FAILURE
3363859Sml29623  *		VIR_SR_RESET
3373859Sml29623  *		VIR_SR_BUSY
3383859Sml29623  *		VIR_SR_INVALID
3393859Sml29623  *		VIR_TAS_BUSY
3403859Sml29623  */
3413859Sml29623 
3423859Sml29623 npi_status_t
npi_dev_func_sr_lock_enter(npi_handle_t handle)3433859Sml29623 npi_dev_func_sr_lock_enter(npi_handle_t handle)
3443859Sml29623 {
3453859Sml29623 	dev_func_sr_t		sr;
3463859Sml29623 	int			status = NPI_SUCCESS;
3473859Sml29623 	uint32_t		state;
3483859Sml29623 
3493859Sml29623 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
3503859Sml29623 	if (!sr.bits.ldw.tas) {
3513859Sml29623 		/*
3523859Sml29623 		 * tas bit will be set to 1 by hardware.
3533859Sml29623 		 * reset tas bit when we unlock the sr.
3543859Sml29623 		 */
3553859Sml29623 		state = sr.bits.ldw.sr & NPI_DEV_SR_LOCK_ST_MASK;
3563859Sml29623 		switch (state) {
3573859Sml29623 		case NPI_DEV_SR_LOCK_ST_FREE:
3583859Sml29623 			/*
3593859Sml29623 			 * set it to busy and our function id.
3603859Sml29623 			 */
3613859Sml29623 			sr.bits.ldw.sr |= (NPI_DEV_SR_LOCK_ST_BUSY |
362*6929Smisaki 			    (sr.bits.ldw.funcid <<
363*6929Smisaki 			    NPI_DEV_SR_LOCK_FID_SHIFT));
3643859Sml29623 			NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
3653859Sml29623 			break;
3663859Sml29623 
3673859Sml29623 		case NPI_DEV_SR_LOCK_ST_RESET:
3683859Sml29623 			NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
369*6929Smisaki 			    " npi_dev_func_sr_lock_enter"
370*6929Smisaki 			    " reset state <0x%x>",
371*6929Smisaki 			    sr.bits.ldw.sr));
3723859Sml29623 			status = NPI_VIR_SR_RESET(sr.bits.ldw.funcid);
3733859Sml29623 			break;
3743859Sml29623 
3753859Sml29623 		case NPI_DEV_SR_LOCK_ST_BUSY:
3763859Sml29623 			NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
377*6929Smisaki 			    " npi_dev_func_sr_lock_enter"
378*6929Smisaki 			    " busy <0x%x>",
379*6929Smisaki 			    sr.bits.ldw.sr));
3803859Sml29623 			status = NPI_VIR_SR_BUSY(sr.bits.ldw.funcid);
3813859Sml29623 			break;
3823859Sml29623 
3833859Sml29623 		default:
3843859Sml29623 			NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
385*6929Smisaki 			    " npi_dev_func_sr_lock_enter",
386*6929Smisaki 			    " invalid state",
387*6929Smisaki 			    sr.bits.ldw.sr));
3883859Sml29623 			status = NPI_VIR_SR_INVALID(sr.bits.ldw.funcid);
3893859Sml29623 			break;
3903859Sml29623 		}
3913859Sml29623 	} else {
3923859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
393*6929Smisaki 		    " npi_dev_func_sr_lock_enter",
394*6929Smisaki 		    " tas busy", sr.bits.ldw));
3953859Sml29623 		status = NPI_VIR_TAS_BUSY(sr.bits.ldw.funcid);
3963859Sml29623 	}
3973859Sml29623 
3983859Sml29623 	return (status);
3993859Sml29623 }
4003859Sml29623 
4013859Sml29623 /*
4023859Sml29623  * npi_dev_func_sr_lock_free():
4033859Sml29623  *	This function is called to free the function shared register
4043859Sml29623  *	by setting the lock state to free.
4053859Sml29623  * Parameters:
4063859Sml29623  *	handle		- NPI handle
4073859Sml29623  * Return:
4083859Sml29623  *	NPI_SUCCESS	- If the function id can free the lock.
4093859Sml29623  *
4103859Sml29623  *	Error:
4113859Sml29623  *	NPI_FAILURE
4123859Sml29623  *		VIR_SR_NOTOWNER
4133859Sml29623  *		VIR_TAS_NOTREAD
4143859Sml29623  */
4153859Sml29623 
4163859Sml29623 npi_status_t
npi_dev_func_sr_lock_free(npi_handle_t handle)4173859Sml29623 npi_dev_func_sr_lock_free(npi_handle_t handle)
4183859Sml29623 {
4193859Sml29623 	dev_func_sr_t		sr;
4203859Sml29623 	int			status = NPI_SUCCESS;
4213859Sml29623 
4223859Sml29623 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
4233859Sml29623 	if (sr.bits.ldw.tas) {
4243859Sml29623 		if (sr.bits.ldw.funcid == NPI_GET_LOCK_OWNER(sr.bits.ldw.sr)) {
4253859Sml29623 			sr.bits.ldw.sr &= NPI_DEV_SR_IMPL_ST_MASK;
4263859Sml29623 			sr.bits.ldw.sr |= NPI_DEV_SR_LOCK_ST_FREE;
4273859Sml29623 			sr.bits.ldw.tas = 0;
4283859Sml29623 			NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
4293859Sml29623 		} else {
4303859Sml29623 			NPI_DEBUG_MSG((handle.function, NPI_VIR_CTL,
431*6929Smisaki 			    " npi_dev_func_sr_lock_free"
432*6929Smisaki 			    " not owner <0x%x>",
433*6929Smisaki 			    sr.bits.ldw.sr));
4343859Sml29623 			status = NPI_VIR_SR_NOTOWNER(sr.bits.ldw.funcid);
4353859Sml29623 		}
4363859Sml29623 	} else {
4373859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
438*6929Smisaki 		    " npi_dev_func_sr_lock_free",
439*6929Smisaki 		    " invalid tas state <0x%x>",
440*6929Smisaki 		    sr.bits.ldw.tas));
4413859Sml29623 		status = NPI_VIR_TAS_NOTREAD(sr.bits.ldw.funcid);
4423859Sml29623 	}
4433859Sml29623 
4443859Sml29623 	return (status);
4453859Sml29623 }
4463859Sml29623 
4473859Sml29623 /*
4483859Sml29623  * npi_dev_func_sr_funcid_get():
4493859Sml29623  *	This function is called to get the caller's function ID.
4503859Sml29623  *	(based on address bits [25:26] on read access.
4513859Sml29623  *	(After read, the TAS bit is always set to 1. Software needs
4523859Sml29623  *	to write 0 to clear.) This function will write 0 to clear
4533859Sml29623  *	the TAS bit if we own it.
4543859Sml29623  * Parameters:
4553859Sml29623  *	handle		- NPI handle
4563859Sml29623  *	funcid_p	- pointer to store the function id.
4573859Sml29623  * Return:
4583859Sml29623  *	NPI_SUCCESS	- If get function id is complete successfully.
4593859Sml29623  *
4603859Sml29623  *	Error:
4613859Sml29623  */
4623859Sml29623 
4633859Sml29623 npi_status_t
npi_dev_func_sr_funcid_get(npi_handle_t handle,uint8_t * funcid_p)4643859Sml29623 npi_dev_func_sr_funcid_get(npi_handle_t handle, uint8_t *funcid_p)
4653859Sml29623 {
4663859Sml29623 	dev_func_sr_t		sr;
4673859Sml29623 
4683859Sml29623 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
4693859Sml29623 	*funcid_p = NXGE_VAL(DEV_FUNC_SR_FUNCID, sr.value);
4703859Sml29623 	if (!sr.bits.ldw.tas) {
4713859Sml29623 		/*
4723859Sml29623 		 * After read, this bit is set to 1 by hardware.
4733859Sml29623 		 * We own it if tas bit read as 0.
4743859Sml29623 		 */
4753859Sml29623 		sr.bits.ldw.tas = 0;
4763859Sml29623 		NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
4773859Sml29623 	}
4783859Sml29623 
4793859Sml29623 	return (NPI_SUCCESS);
4803859Sml29623 }
4813859Sml29623 
4823859Sml29623 /*
4833859Sml29623  * npi_dev_func_sr_sr_get():
4843859Sml29623  *	This function is called to get the shared register value.
4853859Sml29623  *	(After read, the TAS bit is always set to 1. Software needs
4863859Sml29623  *	to write 0 to clear if we own it.)
4873859Sml29623  *
4883859Sml29623  * Parameters:
4893859Sml29623  *	handle		- NPI handle
4903859Sml29623  *	sr_p		- pointer to store the shared value of this register.
4913859Sml29623  *
4923859Sml29623  * Return:
4933859Sml29623  *	NPI_SUCCESS		- If shared value get is complete successfully.
4943859Sml29623  *
4953859Sml29623  *	Error:
4963859Sml29623  */
4973859Sml29623 npi_status_t
npi_dev_func_sr_sr_raw_get(npi_handle_t handle,uint16_t * sr_p)4983859Sml29623 npi_dev_func_sr_sr_raw_get(npi_handle_t handle, uint16_t *sr_p)
4993859Sml29623 {
5003859Sml29623 	dev_func_sr_t		sr;
5013859Sml29623 
5023859Sml29623 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
5033859Sml29623 	*sr_p = NXGE_VAL(DEV_FUNC_SR_FUNCID, sr.value);
5043859Sml29623 	if (!sr.bits.ldw.tas) {
5053859Sml29623 		/*
5063859Sml29623 		 * After read, this bit is set to 1 by hardware.
5073859Sml29623 		 * We own it if tas bit read as 0.
5083859Sml29623 		 */
5093859Sml29623 		sr.bits.ldw.tas = 0;
5103859Sml29623 		NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
5113859Sml29623 	}
5123859Sml29623 
5133859Sml29623 	return (NPI_SUCCESS);
5143859Sml29623 }
5153859Sml29623 
5163859Sml29623 /*
5173859Sml29623  * npi_dev_func_sr_sr_get():
5183859Sml29623  *	This function is called to get the shared register value.
5193859Sml29623  *	(After read, the TAS bit is always set to 1. Software needs
5203859Sml29623  *	to write 0 to clear if we own it.)
5213859Sml29623  *
5223859Sml29623  * Parameters:
5233859Sml29623  *	handle	- NPI handle
5243859Sml29623  *	sr_p	- pointer to store the shared value of this register.
5253859Sml29623  *		. this will get only non-lock, non-function id portion
5263859Sml29623  *              . of the register
5273859Sml29623  *
5283859Sml29623  *
5293859Sml29623  * Return:
5303859Sml29623  *	NPI_SUCCESS		- If shared value get is complete successfully.
5313859Sml29623  *
5323859Sml29623  *	Error:
5333859Sml29623  */
5343859Sml29623 
5353859Sml29623 npi_status_t
npi_dev_func_sr_sr_get(npi_handle_t handle,uint16_t * sr_p)5363859Sml29623 npi_dev_func_sr_sr_get(npi_handle_t handle, uint16_t *sr_p)
5373859Sml29623 {
5383859Sml29623 	dev_func_sr_t		sr;
5393859Sml29623 	uint16_t sr_impl = 0;
5403859Sml29623 
5413859Sml29623 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
5423859Sml29623 	sr_impl = NXGE_VAL(DEV_FUNC_SR_FUNCID, sr.value);
5433859Sml29623 	*sr_p =  (sr_impl << NPI_DEV_SR_IMPL_ST_SHIFT);
5443859Sml29623 	if (!sr.bits.ldw.tas) {
5453859Sml29623 		/*
5463859Sml29623 		 * After read, this bit is set to 1 by hardware.
5473859Sml29623 		 * We own it if tas bit read as 0.
5483859Sml29623 		 */
5493859Sml29623 		sr.bits.ldw.tas = 0;
5503859Sml29623 		NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
5513859Sml29623 	}
5523859Sml29623 
5533859Sml29623 	return (NPI_SUCCESS);
5543859Sml29623 }
5553859Sml29623 
5563859Sml29623 /*
5573859Sml29623  * npi_dev_func_sr_sr_get_set_clear():
5583859Sml29623  *	This function is called to set the shared register value.
5593859Sml29623  *	(Shared register must be read first. If tas bit is 0, then
5603859Sml29623  *	it implies that the software can proceed to set). After
5613859Sml29623  *	setting, tas bit will be cleared.
5623859Sml29623  * Parameters:
5633859Sml29623  *	handle		- NPI handle
5643859Sml29623  *	impl_sr		- shared value to set (only the 8 bit
5653859Sml29623  *			  implementation specific state info).
5663859Sml29623  *
5673859Sml29623  * Return:
5683859Sml29623  *	NPI_SUCCESS		- If shared value is set successfully.
5693859Sml29623  *
5703859Sml29623  *	Error:
5713859Sml29623  *	NPI_FAILURE
5723859Sml29623  *		VIR_TAS_BUSY
5733859Sml29623  */
5743859Sml29623 
5753859Sml29623 npi_status_t
npi_dev_func_sr_sr_get_set_clear(npi_handle_t handle,uint16_t impl_sr)5763859Sml29623 npi_dev_func_sr_sr_get_set_clear(npi_handle_t handle, uint16_t impl_sr)
5773859Sml29623 {
5783859Sml29623 	dev_func_sr_t		sr;
5793859Sml29623 	int			status;
5803859Sml29623 
5813859Sml29623 	status = npi_dev_func_sr_lock_enter(handle);
5823859Sml29623 	if (status != NPI_SUCCESS) {
5833859Sml29623 		NPI_DEBUG_MSG((handle.function, NPI_VIR_CTL,
584*6929Smisaki 		    " npi_dev_func_sr_src_get_set_clear"
585*6929Smisaki 		    " unable to acquire lock:"
586*6929Smisaki 		    " status <0x%x>", status));
5873859Sml29623 		return (status);
5883859Sml29623 	}
5893859Sml29623 
5903859Sml29623 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
5913859Sml29623 	sr.bits.ldw.sr |= (impl_sr << NPI_DEV_SR_IMPL_ST_SHIFT);
5923859Sml29623 	NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
5933859Sml29623 
5943859Sml29623 	return (npi_dev_func_sr_lock_free(handle));
5953859Sml29623 }
5963859Sml29623 
5973859Sml29623 /*
5983859Sml29623  * npi_dev_func_sr_sr_set_only():
5993859Sml29623  *	This function is called to only set the shared register value.
6003859Sml29623  * Parameters:
6013859Sml29623  *	handle		- NPI handle
6023859Sml29623  *	impl_sr		- shared value to set.
6033859Sml29623  *
6043859Sml29623  * Return:
6053859Sml29623  *	NPI_SUCCESS		- If shared value is set successfully.
6063859Sml29623  *
6073859Sml29623  *	Error:
6083859Sml29623  *	NPI_FAILURE
6093859Sml29623  *		VIR_TAS_BUSY
6103859Sml29623  */
6113859Sml29623 
6123859Sml29623 npi_status_t
npi_dev_func_sr_sr_set_only(npi_handle_t handle,uint16_t impl_sr)6133859Sml29623 npi_dev_func_sr_sr_set_only(npi_handle_t handle, uint16_t impl_sr)
6143859Sml29623 {
6153859Sml29623 	int		status = NPI_SUCCESS;
6163859Sml29623 	dev_func_sr_t	sr;
6173859Sml29623 
6183859Sml29623 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
6193859Sml29623 	/* must be the owner */
6203859Sml29623 	if (sr.bits.ldw.funcid == NPI_GET_LOCK_OWNER(sr.bits.ldw.sr)) {
6213859Sml29623 		sr.bits.ldw.sr |= (impl_sr << NPI_DEV_SR_IMPL_ST_SHIFT);
6223859Sml29623 		NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
6233859Sml29623 	} else {
6243859Sml29623 		NPI_DEBUG_MSG((handle.function, NPI_VIR_CTL,
625*6929Smisaki 		    " npi_dev_func_sr_sr_set_only"
626*6929Smisaki 		    " not owner <0x%x>",
627*6929Smisaki 		    sr.bits.ldw.sr));
6283859Sml29623 		status = NPI_VIR_SR_NOTOWNER(sr.bits.ldw.funcid);
6293859Sml29623 	}
6303859Sml29623 
6313859Sml29623 	return (status);
6323859Sml29623 }
6333859Sml29623 
6343859Sml29623 /*
6353859Sml29623  * npi_dev_func_sr_busy():
6363859Sml29623  *	This function is called to see if we can own the device.
6373859Sml29623  *	It will not reset the tas bit.
6383859Sml29623  * Parameters:
6393859Sml29623  *	handle		- NPI handle
6403859Sml29623  *	busy_p		- pointer to store busy flag.
6413859Sml29623  *				(B_TRUE: device is in use, B_FALSE: free).
6423859Sml29623  * Return:
6433859Sml29623  *	NPI_SUCCESS		- If tas bit is read successfully.
6443859Sml29623  *	Error:
6453859Sml29623  */
6463859Sml29623 
6473859Sml29623 npi_status_t
npi_dev_func_sr_busy(npi_handle_t handle,boolean_t * busy_p)6483859Sml29623 npi_dev_func_sr_busy(npi_handle_t handle, boolean_t *busy_p)
6493859Sml29623 {
6503859Sml29623 	dev_func_sr_t	sr;
6513859Sml29623 
6523859Sml29623 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
6533859Sml29623 	if (!sr.bits.ldw.tas) {
6543859Sml29623 		sr.bits.ldw.tas = 0;
6553859Sml29623 		NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
6563859Sml29623 		*busy_p = B_FALSE;
6573859Sml29623 	} else {
6583859Sml29623 		/* Other function already owns it */
6593859Sml29623 		*busy_p = B_TRUE;
6603859Sml29623 	}
6613859Sml29623 
6623859Sml29623 	return (NPI_SUCCESS);
6633859Sml29623 }
6643859Sml29623 
6653859Sml29623 /*
6663859Sml29623  * npi_dev_func_sr_tas_get():
6673859Sml29623  *	This function is called to get the tas bit
6683859Sml29623  *	(after read, this bit is always set to 1, software write 0
6693859Sml29623  *	 to clear it).
6703859Sml29623  *
6713859Sml29623  * Parameters:
6723859Sml29623  *	handle		- NPI handle
6733859Sml29623  *	tas_p		- pointer to store the tas value
6743859Sml29623  *
6753859Sml29623  * Return:
6763859Sml29623  *	NPI_SUCCESS		- If tas value get is complete successfully.
6773859Sml29623  *	Error:
6783859Sml29623  */
6793859Sml29623 
6803859Sml29623 npi_status_t
npi_dev_func_sr_tas_get(npi_handle_t handle,uint8_t * tas_p)6813859Sml29623 npi_dev_func_sr_tas_get(npi_handle_t handle, uint8_t *tas_p)
6823859Sml29623 {
6833859Sml29623 	dev_func_sr_t		sr;
6843859Sml29623 
6853859Sml29623 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
6863859Sml29623 	*tas_p = sr.bits.ldw.tas;
6873859Sml29623 	if (!sr.bits.ldw.tas) {
6883859Sml29623 		sr.bits.ldw.tas = 0;
6893859Sml29623 		NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
6903859Sml29623 
6913859Sml29623 	}
6923859Sml29623 
6933859Sml29623 	return (NPI_SUCCESS);
6943859Sml29623 }
6953859Sml29623 
6963859Sml29623 /*
6973859Sml29623  * npi_fzc_mpc_set():
6983859Sml29623  *	This function is called to enable the write access
6993859Sml29623  *	to FZC region to function zero.
7003859Sml29623  * Parameters:
7013859Sml29623  *	handle		- NPI handle
7023859Sml29623  * Return:
7033859Sml29623  *	NPI_SUCCESS	-
7043859Sml29623  *	Error:
7053859Sml29623  */
7063859Sml29623 
7073859Sml29623 npi_status_t
npi_fzc_mpc_set(npi_handle_t handle,boolean_t mpc)7083859Sml29623 npi_fzc_mpc_set(npi_handle_t handle, boolean_t mpc)
7093859Sml29623 {
7103859Sml29623 	multi_part_ctl_t	mp;
7113859Sml29623 
7123859Sml29623 	mp.value = 0;
7133859Sml29623 	if (mpc) {
7143859Sml29623 		mp.bits.ldw.mpc = 1;
7153859Sml29623 	}
7163859Sml29623 	NXGE_REG_WR64(handle, MULTI_PART_CTL_REG, mp.value);
7173859Sml29623 
7183859Sml29623 	return (NPI_SUCCESS);
7193859Sml29623 }
7203859Sml29623 
7213859Sml29623 /*
7223859Sml29623  * npi_fzc_mpc_get():
7233859Sml29623  *	This function is called to get the access mode.
7243859Sml29623  * Parameters:
7253859Sml29623  *	handle		- NPI handle
7263859Sml29623  * Return:
7273859Sml29623  *	NPI_SUCCESS	-
7283859Sml29623  *
7293859Sml29623  */
7303859Sml29623 
7313859Sml29623 npi_status_t
npi_fzc_mpc_get(npi_handle_t handle,boolean_t * mpc_p)7323859Sml29623 npi_fzc_mpc_get(npi_handle_t handle, boolean_t *mpc_p)
7333859Sml29623 {
7343859Sml29623 	multi_part_ctl_t	mpc;
7353859Sml29623 
7363859Sml29623 	mpc.value = 0;
7373859Sml29623 	NXGE_REG_RD64(handle, MULTI_PART_CTL_REG, &mpc.value);
7383859Sml29623 	*mpc_p = mpc.bits.ldw.mpc;
7393859Sml29623 
7403859Sml29623 	return (NPI_SUCCESS);
7413859Sml29623 }
7423859Sml29623 
7433859Sml29623 /*
7443859Sml29623  * npi_fzc_dma_bind_set():
7453859Sml29623  *	This function is called to set DMA binding register.
7463859Sml29623  * Parameters:
7473859Sml29623  *	handle		- NPI handle
7483859Sml29623  *	dma_bind	- NPI defined data structure that
7493859Sml29623  *			  contains the tx/rx channel binding info.
7503859Sml29623  *			  to set.
7513859Sml29623  * Return:
7523859Sml29623  *	NPI_SUCCESS	-
7533859Sml29623  *	Error:
7543859Sml29623  *	NPI_FAILURE
7553859Sml29623  *
7563859Sml29623  */
7573859Sml29623 
7583859Sml29623 npi_status_t
npi_fzc_dma_bind_set(npi_handle_t handle,fzc_dma_bind_t dma_bind)7593859Sml29623 npi_fzc_dma_bind_set(npi_handle_t handle, fzc_dma_bind_t dma_bind)
7603859Sml29623 {
7613859Sml29623 	dma_bind_t	bind;
7623859Sml29623 	int		status;
7633859Sml29623 	uint8_t		fn, region, id, tn, rn;
7643859Sml29623 
7653859Sml29623 	fn = dma_bind.function_id;
7663859Sml29623 	region = dma_bind.sub_vir_region;
7673859Sml29623 	id = dma_bind.vir_index;
7683859Sml29623 	tn = dma_bind.tx_channel;
7693859Sml29623 	rn = dma_bind.rx_channel;
7703859Sml29623 
7713859Sml29623 	DMA_BIND_VADDR_VALIDATE(fn, region, id, status);
7723859Sml29623 	if (status) {
7733859Sml29623 		return (status);
7743859Sml29623 	}
7753859Sml29623 
7763859Sml29623 	if (dma_bind.tx_bind) {
7773859Sml29623 		DMA_BIND_TX_VALIDATE(tn, status);
7783859Sml29623 		if (status) {
7793859Sml29623 			return (status);
7803859Sml29623 		}
7813859Sml29623 	}
7823859Sml29623 
7833859Sml29623 	if (dma_bind.rx_bind) {
7843859Sml29623 		DMA_BIND_RX_VALIDATE(rn, status);
7853859Sml29623 		if (status) {
7863859Sml29623 			return (status);
7873859Sml29623 		}
7883859Sml29623 	}
7893859Sml29623 
7903859Sml29623 	bind.value = 0;
7913859Sml29623 	if (dma_bind.tx_bind) {
7923859Sml29623 		bind.bits.ldw.tx_bind = 1;
7933859Sml29623 		bind.bits.ldw.tx = tn;
7943859Sml29623 	}
7953859Sml29623 	if (dma_bind.rx_bind) {
7963859Sml29623 		bind.bits.ldw.rx_bind = 1;
7973859Sml29623 		bind.bits.ldw.rx = rn;
7983859Sml29623 	}
7993859Sml29623 
8003859Sml29623 	NXGE_REG_WR64(handle, DMA_BIND_REG +
8016495Sspeer 	    DMA_BIND_REG_OFFSET(fn, region, id), bind.value);
8026495Sspeer 
8036495Sspeer 	return (status);
8046495Sspeer }
8056495Sspeer 
8066495Sspeer npi_status_t
npi_fzc_dma_bind_get(npi_handle_t handle,fzc_dma_bind_t dma_bind,uint64_t * pValue)8076495Sspeer npi_fzc_dma_bind_get(
8086495Sspeer 	npi_handle_t handle,
8096495Sspeer 	fzc_dma_bind_t dma_bind,
8106495Sspeer 	uint64_t *pValue)
8116495Sspeer {
8126495Sspeer 	uint8_t		function, region, slot;
8136495Sspeer 	int		offset;
8146495Sspeer 	int		status;
8156495Sspeer 
8166495Sspeer 	function = dma_bind.function_id;
8176495Sspeer 	region = dma_bind.sub_vir_region;
8186495Sspeer 	slot = dma_bind.vir_index;
8196495Sspeer 
8206495Sspeer 	DMA_BIND_VADDR_VALIDATE(function, region, slot, status);
8216495Sspeer 	if (status) {
8226495Sspeer 		return (status);
8236495Sspeer 	}
8246495Sspeer 
8256495Sspeer 	offset = DMA_BIND_REG_OFFSET(function, region, slot);
8266495Sspeer 	NXGE_REG_RD64(handle, DMA_BIND_REG + offset, pValue);
8273859Sml29623 
8283859Sml29623 	return (status);
8293859Sml29623 }
8303859Sml29623 
8313859Sml29623 /*
8323859Sml29623  * npi_fzc_ldg_num_set():
8333859Sml29623  *	This function is called to set up a logical group number that
8343859Sml29623  *	a logical device belongs to.
8353859Sml29623  * Parameters:
8363859Sml29623  *	handle		- NPI handle
8373859Sml29623  *	ld		- logical device number (0 - 68)
8383859Sml29623  *	ldg		- logical device group number (0 - 63)
8393859Sml29623  * Return:
8403859Sml29623  *	NPI_SUCCESS	-
8413859Sml29623  *	Error:
8423859Sml29623  *	NPI_FAILURE
8433859Sml29623  *
8443859Sml29623  */
8453859Sml29623 
8463859Sml29623 npi_status_t
npi_fzc_ldg_num_set(npi_handle_t handle,uint8_t ld,uint8_t ldg)8473859Sml29623 npi_fzc_ldg_num_set(npi_handle_t handle, uint8_t ld, uint8_t ldg)
8483859Sml29623 {
8493859Sml29623 	ldg_num_t	gnum;
8503859Sml29623 
8513859Sml29623 	ASSERT(LD_VALID(ld));
8523859Sml29623 	if (!LD_VALID(ld)) {
8533859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
854*6929Smisaki 		    " npi_fzc_ldg_num_set"
855*6929Smisaki 		    "ld <0x%x>", ld));
8563859Sml29623 		return (NPI_FAILURE | NPI_VIR_LD_INVALID(ld));
8573859Sml29623 	}
8583859Sml29623 
8593859Sml29623 	ASSERT(LDG_VALID(ldg));
8603859Sml29623 	if (!LDG_VALID(ldg)) {
8613859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
862*6929Smisaki 		    " npi_fzc_ldg_num_set"
863*6929Smisaki 		    " ldg <0x%x>", ldg));
8643859Sml29623 		return (NPI_FAILURE | NPI_VIR_LDG_INVALID(ld));
8653859Sml29623 	}
8663859Sml29623 
8673859Sml29623 	gnum.value = 0;
8683859Sml29623 	gnum.bits.ldw.num = ldg;
8693859Sml29623 
8703859Sml29623 	NXGE_REG_WR64(handle, LDG_NUM_REG + LD_NUM_OFFSET(ld),
871*6929Smisaki 	    gnum.value);
8723859Sml29623 
8733859Sml29623 	return (NPI_SUCCESS);
8743859Sml29623 }
8753859Sml29623 
8763859Sml29623 /*
8773859Sml29623  * npi_fzc_ldg_num_get():
8783859Sml29623  *	This function is called to get the logical device group that
8793859Sml29623  *	a logical device belongs to.
8803859Sml29623  * Parameters:
8813859Sml29623  *	handle		- NPI handle
8823859Sml29623  *	ld		- logical device number (0 - 68)
8833859Sml29623  *	*ldg_p		- pointer to store its group number.
8843859Sml29623  * Return:
8853859Sml29623  *	NPI_SUCCESS	-
8863859Sml29623  *	Error:
8873859Sml29623  *	NPI_FAILURE
8883859Sml29623  */
8893859Sml29623 
8903859Sml29623 npi_status_t
npi_fzc_ldg_num_get(npi_handle_t handle,uint8_t ld,uint8_t * ldg_p)8913859Sml29623 npi_fzc_ldg_num_get(npi_handle_t handle, uint8_t ld, uint8_t *ldg_p)
8923859Sml29623 {
8933859Sml29623 	uint64_t val;
8943859Sml29623 
8953859Sml29623 	ASSERT(LD_VALID(ld));
8963859Sml29623 	if (!LD_VALID(ld)) {
8973859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
898*6929Smisaki 		    " npi_fzc_ldg_num_get"
899*6929Smisaki 		    " Invalid Input:",
900*6929Smisaki 		    " ld <0x%x>", ld));
9013859Sml29623 		return (NPI_FAILURE | NPI_VIR_LD_INVALID(ld));
9023859Sml29623 	}
9033859Sml29623 
9043859Sml29623 	NXGE_REG_RD64(handle, LDG_NUM_REG + LD_NUM_OFFSET(ld), &val);
9053859Sml29623 
9063859Sml29623 	*ldg_p = (uint8_t)(val & LDG_NUM_NUM_MASK);
9073859Sml29623 
9083859Sml29623 	return (NPI_SUCCESS);
9093859Sml29623 }
9103859Sml29623 
9113859Sml29623 /*
9123859Sml29623  * npi_ldsv_ldfs_get():
9133859Sml29623  *	This function is called to get device state vectors.
9143859Sml29623  * Parameters:
9153859Sml29623  *	handle		- NPI handle
9163859Sml29623  *	ldg		- logical device group (0 - 63)
9173859Sml29623  *	*ldf_p		- pointer to store ldf0 and ldf1 flag bits.
9183859Sml29623  * Return:
9193859Sml29623  *	NPI_SUCCESS	-
9203859Sml29623  *	Error:
9213859Sml29623  *	NPI_FAILURE
9223859Sml29623  */
9233859Sml29623 
9243859Sml29623 npi_status_t
npi_ldsv_ldfs_get(npi_handle_t handle,uint8_t ldg,uint64_t * vector0_p,uint64_t * vector1_p,uint64_t * vector2_p)9253859Sml29623 npi_ldsv_ldfs_get(npi_handle_t handle, uint8_t ldg, uint64_t *vector0_p,
9263859Sml29623 	uint64_t *vector1_p, uint64_t *vector2_p)
9273859Sml29623 {
9283859Sml29623 	int	status;
9293859Sml29623 
9303859Sml29623 	if ((status = npi_ldsv_get(handle, ldg, VECTOR0, vector0_p))) {
9313859Sml29623 		return (status);
9323859Sml29623 	}
9333859Sml29623 	if ((status = npi_ldsv_get(handle, ldg, VECTOR1, vector1_p))) {
9343859Sml29623 		return (status);
9353859Sml29623 	}
9363859Sml29623 	if ((status = npi_ldsv_get(handle, ldg, VECTOR2, vector2_p))) {
9373859Sml29623 		return (status);
9383859Sml29623 	}
9393859Sml29623 
9403859Sml29623 	return (NPI_SUCCESS);
9413859Sml29623 }
9423859Sml29623 
9433859Sml29623 /*
9443859Sml29623  * npi_ldsv_get():
9453859Sml29623  *	This function is called to get device state vectors.
9463859Sml29623  * Parameters:
9473859Sml29623  *	handle		- NPI handle
9483859Sml29623  *	ldg		- logical device group (0 - 63)
9493859Sml29623  *	ldf_type	- either LDF0 (0) or LDF1 (1)
9503859Sml29623  *	vector		- vector type (0, 1 or 2)
9513859Sml29623  *	*ldf_p		- pointer to store its flag bits.
9523859Sml29623  * Return:
9533859Sml29623  *	NPI_SUCCESS	-
9543859Sml29623  *	Error:
9553859Sml29623  *	NPI_FAILURE
9563859Sml29623  */
9573859Sml29623 
9583859Sml29623 npi_status_t
npi_ldsv_get(npi_handle_t handle,uint8_t ldg,ldsv_type_t vector,uint64_t * ldf_p)9593859Sml29623 npi_ldsv_get(npi_handle_t handle, uint8_t ldg, ldsv_type_t vector,
9603859Sml29623 	uint64_t *ldf_p)
9613859Sml29623 {
9623859Sml29623 	uint64_t		offset;
9633859Sml29623 
9643859Sml29623 	ASSERT(LDG_VALID(ldg));
9653859Sml29623 	if (!LDG_VALID(ldg)) {
9663859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
967*6929Smisaki 		    " npi_ldsv_get"
968*6929Smisaki 		    " Invalid Input "
969*6929Smisaki 		    " ldg <0x%x>", ldg));
9703859Sml29623 		return (NPI_FAILURE | NPI_VIR_LDG_INVALID(ldg));
9713859Sml29623 	}
9723859Sml29623 
9733859Sml29623 	switch (vector) {
9743859Sml29623 	case VECTOR0:
9753859Sml29623 		offset = LDSV0_REG + LDSV_OFFSET(ldg);
9763859Sml29623 		break;
9773859Sml29623 
9783859Sml29623 	case VECTOR1:
9793859Sml29623 		offset = LDSV1_REG + LDSV_OFFSET(ldg);
9803859Sml29623 		break;
9813859Sml29623 
9823859Sml29623 	case VECTOR2:
9833859Sml29623 		offset = LDSV2_REG + LDSV_OFFSET(ldg);
9843859Sml29623 		break;
9853859Sml29623 
9863859Sml29623 	default:
9873859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
988*6929Smisaki 		    " npi_ldsv_get"
989*6929Smisaki 		    " Invalid Input: "
990*6929Smisaki 		    " ldsv type <0x%x>", vector));
9913859Sml29623 		return (NPI_FAILURE | NPI_VIR_LDSV_INVALID(vector));
9923859Sml29623 	}
9933859Sml29623 
9943859Sml29623 	NXGE_REG_RD64(handle, offset, ldf_p);
9953859Sml29623 
9963859Sml29623 	return (NPI_SUCCESS);
9973859Sml29623 }
9983859Sml29623 
9993859Sml29623 /*
10003859Sml29623  * npi_ldsv_ld_get():
10013859Sml29623  *	This function is called to get the flag bit value of a device.
10023859Sml29623  * Parameters:
10033859Sml29623  *	handle		- NPI handle
10043859Sml29623  *	ldg		- logical device group (0 - 63)
10053859Sml29623  *	ld		- logical device (0 - 68)
10063859Sml29623  *	ldf_type	- either LDF0 (0) or LDF1 (1)
10073859Sml29623  *	vector		- vector type (0, 1 or 2)
10083859Sml29623  *	*ldf_p		- pointer to store its flag bits.
10093859Sml29623  * Return:
10103859Sml29623  *	NPI_SUCCESS	-
10113859Sml29623  *	Error:
10123859Sml29623  *	NPI_FAILURE
10133859Sml29623  */
10143859Sml29623 
10153859Sml29623 npi_status_t
npi_ldsv_ld_get(npi_handle_t handle,uint8_t ldg,uint8_t ld,ldsv_type_t vector,ldf_type_t ldf_type,boolean_t * flag_p)10163859Sml29623 npi_ldsv_ld_get(npi_handle_t handle, uint8_t ldg, uint8_t ld,
10173859Sml29623 	ldsv_type_t vector, ldf_type_t ldf_type, boolean_t *flag_p)
10183859Sml29623 {
10193859Sml29623 	uint64_t		sv;
10203859Sml29623 	uint64_t		offset;
10213859Sml29623 
10223859Sml29623 	ASSERT(LDG_VALID(ldg));
10233859Sml29623 	if (!LDG_VALID(ldg)) {
10243859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1025*6929Smisaki 		    " npi_ldsv_ld_get"
1026*6929Smisaki 		    " Invalid Input: "
1027*6929Smisaki 		    " ldg <0x%x>", ldg));
10283859Sml29623 		return (NPI_FAILURE | NPI_VIR_LDG_INVALID(ldg));
10293859Sml29623 	}
10303859Sml29623 	ASSERT((LD_VALID(ld)) &&	\
1031*6929Smisaki 	    ((vector != VECTOR2) || (ld >= NXGE_MAC_LD_START)));
10323859Sml29623 	if (!LD_VALID(ld)) {
10333859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1034*6929Smisaki 		    " npi_ldsv_ld_get Invalid Input: "
1035*6929Smisaki 		    " ld <9x%x>", ld));
10363859Sml29623 		return (NPI_FAILURE | NPI_VIR_LD_INVALID(ld));
10373859Sml29623 	} else if (vector == VECTOR2 && ld < NXGE_MAC_LD_START) {
10383859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1039*6929Smisaki 		    " npi_ldsv_ld_get Invalid Input:"
1040*6929Smisaki 		    " ld-vector2 <0x%x>", ld));
10413859Sml29623 		return (NPI_FAILURE | NPI_VIR_LD_INVALID(ld));
10423859Sml29623 	}
10433859Sml29623 
10443859Sml29623 	switch (vector) {
10453859Sml29623 	case VECTOR0:
10463859Sml29623 		offset = LDSV0_REG + LDSV_OFFSET(ldg);
10473859Sml29623 		break;
10483859Sml29623 
10493859Sml29623 	case VECTOR1:
10503859Sml29623 		offset = LDSV1_REG + LDSV_OFFSET(ldg);
10513859Sml29623 		break;
10523859Sml29623 
10533859Sml29623 	case VECTOR2:
10543859Sml29623 		offset = LDSV2_REG + LDSV_OFFSET(ldg);
10553859Sml29623 
10563859Sml29623 	default:
10573859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL, "npi_ldsv_get"
1058*6929Smisaki 		    "ldsv", vector));
10593859Sml29623 		return (NPI_FAILURE | NPI_VIR_LDSV_INVALID(vector));
10603859Sml29623 	}
10613859Sml29623 
10623859Sml29623 	NXGE_REG_RD64(handle, offset, &sv);
10633859Sml29623 	if (vector != VECTOR2) {
10643859Sml29623 		*flag_p = ((sv >> ld) & LDSV_MASK_ALL);
10653859Sml29623 	} else {
10663859Sml29623 		if (ldf_type) {
10673859Sml29623 			*flag_p = (((sv >> LDSV2_LDF1_SHIFT) >>
1068*6929Smisaki 			    (ld - NXGE_MAC_LD_START)) & LDSV_MASK_ALL);
10693859Sml29623 		} else {
10703859Sml29623 			*flag_p = (((sv >> LDSV2_LDF0_SHIFT) >>
1071*6929Smisaki 			    (ld - NXGE_MAC_LD_START)) & LDSV_MASK_ALL);
10723859Sml29623 		}
10733859Sml29623 	}
10743859Sml29623 
10753859Sml29623 	return (NPI_SUCCESS);
10763859Sml29623 }
10773859Sml29623 
10783859Sml29623 /*
10793859Sml29623  * npi_ldsv_ld_ldf0_get():
10803859Sml29623  *	This function is called to get the ldf0 bit value of a device.
10813859Sml29623  * Parameters:
10823859Sml29623  *	handle		- NPI handle
10833859Sml29623  *	ldg		- logical device group (0 - 63)
10843859Sml29623  *	ld		- logical device (0 - 68)
10853859Sml29623  *	*ldf_p		- pointer to store its flag bits.
10863859Sml29623  * Return:
10873859Sml29623  *	NPI_SUCCESS	-
10883859Sml29623  *	Error:
10893859Sml29623  *	NPI_FAILURE
10903859Sml29623  */
10913859Sml29623 
10923859Sml29623 npi_status_t
npi_ldsv_ld_ldf0_get(npi_handle_t handle,uint8_t ldg,uint8_t ld,boolean_t * flag_p)10933859Sml29623 npi_ldsv_ld_ldf0_get(npi_handle_t handle, uint8_t ldg, uint8_t ld,
10943859Sml29623 	boolean_t *flag_p)
10953859Sml29623 {
10963859Sml29623 	ldsv_type_t vector;
10973859Sml29623 
10983859Sml29623 	if (ld >= NXGE_MAC_LD_START) {
10993859Sml29623 		vector = VECTOR2;
11003859Sml29623 	}
11013859Sml29623 
11023859Sml29623 	return (npi_ldsv_ld_get(handle, ldg, ld, vector, LDF0, flag_p));
11033859Sml29623 }
11043859Sml29623 
11053859Sml29623 /*
11063859Sml29623  * npi_ldsv_ld_ldf1_get():
11073859Sml29623  *	This function is called to get the ldf1 bit value of a device.
11083859Sml29623  * Parameters:
11093859Sml29623  *	handle		- NPI handle
11103859Sml29623  *	ldg		- logical device group (0 - 63)
11113859Sml29623  *	ld		- logical device (0 - 68)
11123859Sml29623  *	*ldf_p		- pointer to store its flag bits.
11133859Sml29623  * Return:
11143859Sml29623  *	NPI_SUCCESS	-
11153859Sml29623  *	Error:
11163859Sml29623  *	NPI_FAILURE
11173859Sml29623  */
11183859Sml29623 
11193859Sml29623 npi_status_t
npi_ldsv_ld_ldf1_get(npi_handle_t handle,uint8_t ldg,uint8_t ld,boolean_t * flag_p)11203859Sml29623 npi_ldsv_ld_ldf1_get(npi_handle_t handle, uint8_t ldg, uint8_t ld,
11213859Sml29623 		boolean_t *flag_p)
11223859Sml29623 {
11233859Sml29623 	ldsv_type_t vector;
11243859Sml29623 
11253859Sml29623 	if (ld >= NXGE_MAC_LD_START) {
11263859Sml29623 		vector = VECTOR2;
11273859Sml29623 	}
11283859Sml29623 
11293859Sml29623 	return (npi_ldsv_ld_get(handle, ldg, ld, vector, LDF1, flag_p));
11303859Sml29623 }
11313859Sml29623 
11323859Sml29623 /*
11333859Sml29623  * npi_intr_mask_set():
11343859Sml29623  *	This function is called to select the mask bits for both ldf0 and ldf1.
11353859Sml29623  * Parameters:
11363859Sml29623  *	handle		- NPI handle
11373859Sml29623  *	ld		- logical device (0 - 68)
11383859Sml29623  *	ldf_mask	- mask value to set (both ldf0 and ldf1).
11393859Sml29623  * Return:
11403859Sml29623  *	NPI_SUCCESS	-
11413859Sml29623  *	Error:
11423859Sml29623  *	NPI_FAILURE
11433859Sml29623  */
11443859Sml29623 
11453859Sml29623 npi_status_t
npi_intr_mask_set(npi_handle_t handle,uint8_t ld,uint8_t ldf_mask)11463859Sml29623 npi_intr_mask_set(npi_handle_t handle, uint8_t ld, uint8_t ldf_mask)
11473859Sml29623 {
11483859Sml29623 	uint64_t		offset;
11493859Sml29623 
11503859Sml29623 	ASSERT(LD_VALID(ld));
11513859Sml29623 	if (!LD_VALID(ld)) {
11523859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1153*6929Smisaki 		    " npi_intr_mask_set ld", ld));
11543859Sml29623 		return (NPI_FAILURE | NPI_VIR_LD_INVALID(ld));
11553859Sml29623 	}
11563859Sml29623 
11573859Sml29623 	ldf_mask &= LD_IM0_MASK;
11583859Sml29623 	offset = LDSV_OFFSET_MASK(ld);
11593859Sml29623 
11603859Sml29623 	NPI_DEBUG_MSG((handle.function, NPI_VIR_CTL,
1161*6929Smisaki 	    "npi_intr_mask_set: ld %d "
1162*6929Smisaki 	    " offset 0x%0llx "
1163*6929Smisaki 	    " mask 0x%x",
1164*6929Smisaki 	    ld, offset, ldf_mask));
11653859Sml29623 
11663859Sml29623 	NXGE_REG_WR64(handle, offset, (uint64_t)ldf_mask);
11673859Sml29623 
11683859Sml29623 	return (NPI_SUCCESS);
11693859Sml29623 }
11703859Sml29623 
11713859Sml29623 /*
11723859Sml29623  * npi_intr_mask_get():
11733859Sml29623  *	This function is called to get the mask bits.
11743859Sml29623  * Parameters:
11753859Sml29623  *	handle		- NPI handle
11763859Sml29623  *	ld		- logical device (0 - 68)
11773859Sml29623  *	ldf_mask	- pointer to store mask bits info.
11783859Sml29623  * Return:
11793859Sml29623  *	NPI_SUCCESS	-
11803859Sml29623  *	Error:
11813859Sml29623  *	NPI_FAILURE
11823859Sml29623  */
11833859Sml29623 npi_status_t
npi_intr_mask_get(npi_handle_t handle,uint8_t ld,uint8_t * ldf_mask_p)11843859Sml29623 npi_intr_mask_get(npi_handle_t handle, uint8_t ld, uint8_t *ldf_mask_p)
11853859Sml29623 {
11863859Sml29623 	uint64_t		offset;
11873859Sml29623 	uint64_t		val;
11883859Sml29623 
11893859Sml29623 	ASSERT(LD_VALID(ld));
11903859Sml29623 	if (!LD_VALID(ld)) {
11913859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1192*6929Smisaki 		    " npi_intr_mask_get ld", ld));
11933859Sml29623 		return (NPI_FAILURE | NPI_VIR_LD_INVALID(ld));
11943859Sml29623 	}
11953859Sml29623 
11963859Sml29623 	offset = LDSV_OFFSET_MASK(ld);
11973859Sml29623 
11983859Sml29623 	NXGE_REG_RD64(handle, offset, &val);
11993859Sml29623 
12003859Sml29623 	*ldf_mask_p = (uint8_t)(val & LD_IM_MASK);
12013859Sml29623 
12023859Sml29623 	return (NPI_SUCCESS);
12033859Sml29623 }
12043859Sml29623 
12053859Sml29623 /*
12063859Sml29623  * npi_intr_ldg_mgmt_set():
12073859Sml29623  *	This function is called to set interrupt timer and arm bit.
12083859Sml29623  * Parameters:
12093859Sml29623  *	handle		- NPI handle
12103859Sml29623  *	ldg		- logical device group (0 - 63)
12113859Sml29623  *	arm		- B_TRUE (arm) B_FALSE (disable)
12123859Sml29623  * Return:
12133859Sml29623  *	NPI_SUCCESS	-
12143859Sml29623  *	Error:
12153859Sml29623  *	NPI_FAILURE
12163859Sml29623  */
12173859Sml29623 
12183859Sml29623 npi_status_t
npi_intr_ldg_mgmt_set(npi_handle_t handle,uint8_t ldg,boolean_t arm,uint8_t timer)12193859Sml29623 npi_intr_ldg_mgmt_set(npi_handle_t handle, uint8_t ldg, boolean_t arm,
12203859Sml29623 			uint8_t timer)
12213859Sml29623 {
12223859Sml29623 	ldgimgm_t		mgm;
12233859Sml29623 	uint64_t		val;
12243859Sml29623 
12253859Sml29623 	ASSERT((LDG_VALID(ldg)) && (LD_INTTIMER_VALID(timer)));
12263859Sml29623 	if (!LDG_VALID(ldg)) {
12273859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1228*6929Smisaki 		    " npi_intr_ldg_mgmt_set"
1229*6929Smisaki 		    " Invalid Input: "
1230*6929Smisaki 		    " ldg <0x%x>", ldg));
12313859Sml29623 		return (NPI_FAILURE | NPI_VIR_LDG_INVALID(ldg));
12323859Sml29623 	}
12333859Sml29623 	if (!LD_INTTIMER_VALID(timer)) {
12343859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1235*6929Smisaki 		    " npi_intr_ldg_mgmt_set Invalid Input"
1236*6929Smisaki 		    " timer <0x%x>", timer));
12373859Sml29623 		return (NPI_FAILURE | NPI_VIR_INTM_TM_INVALID(ldg));
12383859Sml29623 	}
12393859Sml29623 
12403859Sml29623 	if (arm) {
12413859Sml29623 		mgm.bits.ldw.arm = 1;
12423859Sml29623 	} else {
12433859Sml29623 		NXGE_REG_RD64(handle, LDGIMGN_REG + LDSV_OFFSET(ldg), &val);
12443859Sml29623 		mgm.value = val & LDGIMGM_ARM_MASK;
12453859Sml29623 	}
12463859Sml29623 
12473859Sml29623 	mgm.bits.ldw.timer = timer;
12483859Sml29623 	NXGE_REG_WR64(handle, LDGIMGN_REG + LDSV_OFFSET(ldg),
1249*6929Smisaki 	    mgm.value);
12503859Sml29623 
12513859Sml29623 	NPI_DEBUG_MSG((handle.function, NPI_VIR_CTL,
1252*6929Smisaki 	    " npi_intr_ldg_mgmt_set: ldg %d"
1253*6929Smisaki 	    " reg offset 0x%x",
1254*6929Smisaki 	    ldg, LDGIMGN_REG + LDSV_OFFSET(ldg)));
12553859Sml29623 
12563859Sml29623 	return (NPI_SUCCESS);
12573859Sml29623 }
12583859Sml29623 
12593859Sml29623 /*
12603859Sml29623  * npi_intr_ldg_mgmt_timer_get():
12613859Sml29623  *	This function is called to get the timer counter
12623859Sml29623  * Parameters:
12633859Sml29623  *	handle		- NPI handle
12643859Sml29623  *	ldg		- logical device group (0 - 63)
12653859Sml29623  *	timer_p		- pointer to store the timer counter.
12663859Sml29623  * Return:
12673859Sml29623  *	NPI_SUCCESS	-
12683859Sml29623  *	Error:
12693859Sml29623  *	NPI_FAILURE
12703859Sml29623  */
12713859Sml29623 
12723859Sml29623 npi_status_t
npi_intr_ldg_mgmt_timer_get(npi_handle_t handle,uint8_t ldg,uint8_t * timer_p)12733859Sml29623 npi_intr_ldg_mgmt_timer_get(npi_handle_t handle, uint8_t ldg, uint8_t *timer_p)
12743859Sml29623 {
12753859Sml29623 	uint64_t val;
12763859Sml29623 
12773859Sml29623 	ASSERT(LDG_VALID(ldg));
12783859Sml29623 	if (!LDG_VALID(ldg)) {
12793859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1280*6929Smisaki 		    " npi_intr_ldg_mgmt_timer_get"
1281*6929Smisaki 		    " Invalid Input: ldg <0x%x>", ldg));
12823859Sml29623 		return (NPI_FAILURE | NPI_VIR_LDG_INVALID(ldg));
12833859Sml29623 	}
12843859Sml29623 
12853859Sml29623 	NXGE_REG_RD64(handle, LDGIMGN_REG + LDSV_OFFSET(ldg), &val);
12863859Sml29623 
12873859Sml29623 	*timer_p = (uint8_t)(val & LDGIMGM_TIMER_MASK);
12883859Sml29623 
12893859Sml29623 	NPI_DEBUG_MSG((handle.function, NPI_VIR_CTL,
1290*6929Smisaki 	    " npi_intr_ldg_mgmt_timer_get: ldg %d"
1291*6929Smisaki 	    " reg offset 0x%x",
1292*6929Smisaki 	    ldg, LDGIMGN_REG + LDSV_OFFSET(ldg)));
12933859Sml29623 
12943859Sml29623 	return (NPI_SUCCESS);
12953859Sml29623 }
12963859Sml29623 
12973859Sml29623 /*
12983859Sml29623  * npi_intr_ldg_mgmt_arm():
12993859Sml29623  *	This function is called to arm the group.
13003859Sml29623  * Parameters:
13013859Sml29623  *	handle		- NPI handle
13023859Sml29623  *	ldg		- logical device group (0 - 63)
13033859Sml29623  * Return:
13043859Sml29623  *	NPI_SUCCESS	-
13053859Sml29623  *	Error:
13063859Sml29623  *	NPI_FAILURE
13073859Sml29623  */
13083859Sml29623 
13093859Sml29623 npi_status_t
npi_intr_ldg_mgmt_arm(npi_handle_t handle,uint8_t ldg)13103859Sml29623 npi_intr_ldg_mgmt_arm(npi_handle_t handle, uint8_t ldg)
13113859Sml29623 {
13123859Sml29623 	ldgimgm_t		mgm;
13133859Sml29623 
13143859Sml29623 	ASSERT(LDG_VALID(ldg));
13153859Sml29623 	if (!LDG_VALID(ldg)) {
13163859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1317*6929Smisaki 		    " npi_intr_ldg_mgmt_arm"
1318*6929Smisaki 		    " Invalid Input: ldg <0x%x>",
1319*6929Smisaki 		    ldg));
13203859Sml29623 		return (NPI_FAILURE | NPI_VIR_LDG_INVALID(ldg));
13213859Sml29623 	}
13223859Sml29623 
13233859Sml29623 	NXGE_REG_RD64(handle, (LDGIMGN_REG + LDSV_OFFSET(ldg)), &mgm.value);
13243859Sml29623 	mgm.bits.ldw.arm = 1;
13253859Sml29623 
13263859Sml29623 	NXGE_REG_WR64(handle, LDGIMGN_REG + LDSV_OFFSET(ldg),
1327*6929Smisaki 	    mgm.value);
13283859Sml29623 	NPI_DEBUG_MSG((handle.function, NPI_VIR_CTL,
1329*6929Smisaki 	    " npi_intr_ldg_mgmt_arm: ldg %d"
1330*6929Smisaki 	    " reg offset 0x%x",
1331*6929Smisaki 	    ldg, LDGIMGN_REG + LDSV_OFFSET(ldg)));
13323859Sml29623 
13333859Sml29623 	return (NPI_SUCCESS);
13343859Sml29623 }
13353859Sml29623 
13363859Sml29623 /*
13373859Sml29623  * npi_fzc_ldg_timer_res_set():
13383859Sml29623  *	This function is called to set the timer resolution.
13393859Sml29623  * Parameters:
13403859Sml29623  *	handle		- NPI handle
13413859Sml29623  *	res		- timer resolution (# of system clocks)
13423859Sml29623  * Return:
13433859Sml29623  *	NPI_SUCCESS	-
13443859Sml29623  *	Error:
13453859Sml29623  *	NPI_FAILURE
13463859Sml29623  */
13473859Sml29623 
13483859Sml29623 npi_status_t
npi_fzc_ldg_timer_res_set(npi_handle_t handle,uint32_t res)13493859Sml29623 npi_fzc_ldg_timer_res_set(npi_handle_t handle, uint32_t res)
13503859Sml29623 {
13513859Sml29623 	ASSERT(res <= LDGTITMRES_RES_MASK);
13523859Sml29623 	if (res > LDGTITMRES_RES_MASK) {
13533859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1354*6929Smisaki 		    " npi_fzc_ldg_timer_res_set"
1355*6929Smisaki 		    " Invalid Input: res <0x%x>",
1356*6929Smisaki 		    res));
13573859Sml29623 		return (NPI_FAILURE | NPI_VIR_TM_RES_INVALID);
13583859Sml29623 	}
13593859Sml29623 
13603859Sml29623 	NXGE_REG_WR64(handle, LDGITMRES_REG, (res & LDGTITMRES_RES_MASK));
13613859Sml29623 
13623859Sml29623 	return (NPI_SUCCESS);
13633859Sml29623 }
13643859Sml29623 
13653859Sml29623 /*
13663859Sml29623  * npi_fzc_ldg_timer_res_get():
13673859Sml29623  *	This function is called to get the timer resolution.
13683859Sml29623  * Parameters:
13693859Sml29623  *	handle		- NPI handle
13703859Sml29623  *	res_p		- pointer to store the timer resolution.
13713859Sml29623  * Return:
13723859Sml29623  *	NPI_SUCCESS	-
13733859Sml29623  *	Error:
13743859Sml29623  *	NPI_FAILURE
13753859Sml29623  */
13763859Sml29623 
13773859Sml29623 npi_status_t
npi_fzc_ldg_timer_res_get(npi_handle_t handle,uint8_t * res_p)13783859Sml29623 npi_fzc_ldg_timer_res_get(npi_handle_t handle, uint8_t *res_p)
13793859Sml29623 {
13803859Sml29623 	uint64_t val;
13813859Sml29623 
13823859Sml29623 	NXGE_REG_RD64(handle, LDGITMRES_REG, &val);
13833859Sml29623 
13843859Sml29623 	*res_p = (uint8_t)(val & LDGIMGM_TIMER_MASK);
13853859Sml29623 
13863859Sml29623 	return (NPI_SUCCESS);
13873859Sml29623 }
13883859Sml29623 
13893859Sml29623 /*
13903859Sml29623  * npi_fzc_sid_set():
13913859Sml29623  *	This function is called to set the system interrupt data.
13923859Sml29623  * Parameters:
13933859Sml29623  *	handle		- NPI handle
13943859Sml29623  *	ldg		- logical group (0 - 63)
13953859Sml29623  *	sid		- NPI defined data to set
13963859Sml29623  * Return:
13973859Sml29623  *	NPI_SUCCESS	-
13983859Sml29623  *	Error:
13993859Sml29623  *	NPI_FAILURE
14003859Sml29623  */
14013859Sml29623 
14023859Sml29623 npi_status_t
npi_fzc_sid_set(npi_handle_t handle,fzc_sid_t sid)14033859Sml29623 npi_fzc_sid_set(npi_handle_t handle, fzc_sid_t sid)
14043859Sml29623 {
14053859Sml29623 	sid_t		sd;
14063859Sml29623 
14073859Sml29623 	ASSERT(LDG_VALID(sid.ldg));
14083859Sml29623 	if (!LDG_VALID(sid.ldg)) {
14093859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1410*6929Smisaki 		    " npi_fzc_sid_set"
1411*6929Smisaki 		    " Invalid Input: ldg <0x%x>",
1412*6929Smisaki 		    sid.ldg));
14133859Sml29623 		return (NPI_FAILURE | NPI_VIR_LDG_INVALID(sid.ldg));
14143859Sml29623 	}
14153859Sml29623 	if (!sid.niu) {
14163859Sml29623 		ASSERT(FUNC_VALID(sid.func));
14173859Sml29623 		if (!FUNC_VALID(sid.func)) {
14183859Sml29623 			NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1419*6929Smisaki 			    " npi_fzc_sid_set"
1420*6929Smisaki 			    " Invalid Input: func <0x%x>",
1421*6929Smisaki 			    sid.func));
14223859Sml29623 			NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1423*6929Smisaki 			    "invalid FUNC: npi_fzc_sid_set(%d)", sid.func));
14243859Sml29623 			return (NPI_FAILURE | NPI_VIR_FUNC_INVALID(sid.func));
14253859Sml29623 		}
14263859Sml29623 
14273859Sml29623 		ASSERT(SID_VECTOR_VALID(sid.vector));
14283859Sml29623 		if (!SID_VECTOR_VALID(sid.vector)) {
14293859Sml29623 			NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1430*6929Smisaki 			    " npi_fzc_sid_set"
1431*6929Smisaki 			    " Invalid Input: vector <0x%x>",
1432*6929Smisaki 			    sid.vector));
14333859Sml29623 			NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1434*6929Smisaki 			    " invalid VECTOR: npi_fzc_sid_set(%d)",
1435*6929Smisaki 			    sid.vector));
14363859Sml29623 			return (NPI_FAILURE |
1437*6929Smisaki 			    NPI_VIR_SID_VEC_INVALID(sid.vector));
14383859Sml29623 		}
14393859Sml29623 	}
14403859Sml29623 	sd.value = 0;
14413859Sml29623 	if (!sid.niu) {
14423859Sml29623 		sd.bits.ldw.data = ((sid.func << SID_DATA_FUNCNUM_SHIFT) |
1443*6929Smisaki 		    (sid.vector & SID_DATA_INTNUM_MASK));
14443859Sml29623 	}
14453859Sml29623 
14464185Sspeer 	NPI_DEBUG_MSG((handle.function, NPI_VIR_CTL,
14473859Sml29623 	    " npi_fzc_sid_set: group %d 0x%llx", sid.ldg, sd.value));
14483859Sml29623 
14493859Sml29623 	NXGE_REG_WR64(handle,  SID_REG + LDG_SID_OFFSET(sid.ldg), sd.value);
14503859Sml29623 
14513859Sml29623 	return (NPI_SUCCESS);
14523859Sml29623 }
14533859Sml29623 
14543859Sml29623 /*
14553859Sml29623  * npi_fzc_sid_get():
14563859Sml29623  *	This function is called to get the system interrupt data.
14573859Sml29623  * Parameters:
14583859Sml29623  *	handle		- NPI handle
14593859Sml29623  *	ldg		- logical group (0 - 63)
14603859Sml29623  *	sid_p		- NPI defined data to get
14613859Sml29623  * Return:
14623859Sml29623  *	NPI_SUCCESS	-
14633859Sml29623  *	Error:
14643859Sml29623  *	NPI_FAILURE
14653859Sml29623  */
14663859Sml29623 
14673859Sml29623 npi_status_t
npi_fzc_sid_get(npi_handle_t handle,p_fzc_sid_t sid_p)14683859Sml29623 npi_fzc_sid_get(npi_handle_t handle, p_fzc_sid_t sid_p)
14693859Sml29623 {
14703859Sml29623 	sid_t		sd;
14713859Sml29623 
14723859Sml29623 	ASSERT(LDG_VALID(sid_p->ldg));
14733859Sml29623 	if (!LDG_VALID(sid_p->ldg)) {
14743859Sml29623 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1475*6929Smisaki 		    " npi_fzc_sid_get"
1476*6929Smisaki 		    " Invalid Input: ldg <0x%x>",
1477*6929Smisaki 		    sid_p->ldg));
14783859Sml29623 		return (NPI_FAILURE | NPI_VIR_LDG_INVALID(sid_p->ldg));
14793859Sml29623 	}
14803859Sml29623 	NXGE_REG_RD64(handle, (SID_REG + LDG_SID_OFFSET(sid_p->ldg)),
1481*6929Smisaki 	    &sd.value);
14823859Sml29623 	if (!sid_p->niu) {
14833859Sml29623 		sid_p->func = ((sd.bits.ldw.data & SID_DATA_FUNCNUM_MASK) >>
1484*6929Smisaki 		    SID_DATA_FUNCNUM_SHIFT);
14853859Sml29623 		sid_p->vector = ((sd.bits.ldw.data & SID_DATA_INTNUM_MASK) >>
1486*6929Smisaki 		    SID_DATA_INTNUM_SHIFT);
14873859Sml29623 	} else {
14883859Sml29623 		sid_p->vector = (sd.value & SID_DATA_MASK);
14893859Sml29623 	}
14903859Sml29623 
14913859Sml29623 	return (NPI_SUCCESS);
14923859Sml29623 }
14933859Sml29623 
14943859Sml29623 /*
14953859Sml29623  * npi_fzc_sys_err_mask_set():
14963859Sml29623  *	This function is called to mask/unmask the device error mask bits.
14973859Sml29623  *
14983859Sml29623  * Parameters:
14993859Sml29623  *	handle		- NPI handle
15003859Sml29623  *	mask		- set bit mapped mask
15013859Sml29623  * Return:
15023859Sml29623  *	NPI_SUCCESS	-
15033859Sml29623  *	Error:
15043859Sml29623  *	NPI_FAILURE
15053859Sml29623  */
15063859Sml29623 
15073859Sml29623 npi_status_t
npi_fzc_sys_err_mask_set(npi_handle_t handle,uint64_t mask)15083859Sml29623 npi_fzc_sys_err_mask_set(npi_handle_t handle, uint64_t mask)
15093859Sml29623 {
15103859Sml29623 	NXGE_REG_WR64(handle,  SYS_ERR_MASK_REG, mask);
15113859Sml29623 	return (NPI_SUCCESS);
15123859Sml29623 }
15133859Sml29623 
15143859Sml29623 /*
15153859Sml29623  * npi_fzc_sys_err_stat_get():
15163859Sml29623  *	This function is called to get the system error stats.
15173859Sml29623  *
15183859Sml29623  * Parameters:
15193859Sml29623  *	handle		- NPI handle
15203859Sml29623  *	err_stat	- sys_err_stat structure to hold stats.
15213859Sml29623  * Return:
15223859Sml29623  *	NPI_SUCCESS	-
15233859Sml29623  *	Error:
15243859Sml29623  *	NPI_FAILURE
15253859Sml29623  */
15263859Sml29623 
15273859Sml29623 npi_status_t
npi_fzc_sys_err_stat_get(npi_handle_t handle,p_sys_err_stat_t statp)15283859Sml29623 npi_fzc_sys_err_stat_get(npi_handle_t handle, p_sys_err_stat_t statp)
15293859Sml29623 {
15303859Sml29623 	NXGE_REG_RD64(handle,  SYS_ERR_STAT_REG, &statp->value);
15313859Sml29623 	return (NPI_SUCCESS);
15323859Sml29623 }
15333859Sml29623 
15343859Sml29623 npi_status_t
npi_fzc_rst_ctl_get(npi_handle_t handle,p_rst_ctl_t rstp)15353859Sml29623 npi_fzc_rst_ctl_get(npi_handle_t handle, p_rst_ctl_t rstp)
15363859Sml29623 {
15373859Sml29623 	NXGE_REG_RD64(handle, RST_CTL_REG, &rstp->value);
15383859Sml29623 
15393859Sml29623 	return (NPI_SUCCESS);
15403859Sml29623 }
15413859Sml29623 
15423859Sml29623 /*
15433859Sml29623  * npi_fzc_mpc_get():
15443859Sml29623  *	This function is called to get the access mode.
15453859Sml29623  * Parameters:
15463859Sml29623  *	handle		- NPI handle
15473859Sml29623  * Return:
15483859Sml29623  *	NPI_SUCCESS	-
15493859Sml29623  *
15503859Sml29623  */
15513859Sml29623 
15523859Sml29623 npi_status_t
npi_fzc_rst_ctl_reset_mac(npi_handle_t handle,uint8_t port)15533859Sml29623 npi_fzc_rst_ctl_reset_mac(npi_handle_t handle, uint8_t port)
15543859Sml29623 {
15553859Sml29623 	rst_ctl_t 		rst;
15563859Sml29623 
15573859Sml29623 	rst.value = 0;
15583859Sml29623 	NXGE_REG_RD64(handle, RST_CTL_REG, &rst.value);
15593859Sml29623 	rst.value |= (1 << (RST_CTL_MAC_RST0_SHIFT + port));
15603859Sml29623 	NXGE_REG_WR64(handle, RST_CTL_REG, rst.value);
15613859Sml29623 
15623859Sml29623 	return (NPI_SUCCESS);
15633859Sml29623 }
1564