xref: /illumos-gate/usr/src/uts/common/io/nxge/npi/npi_vir.c (revision 56d930ae)
144961713Sgirish /*
244961713Sgirish  * CDDL HEADER START
344961713Sgirish  *
444961713Sgirish  * The contents of this file are subject to the terms of the
544961713Sgirish  * Common Development and Distribution License (the "License").
644961713Sgirish  * You may not use this file except in compliance with the License.
744961713Sgirish  *
844961713Sgirish  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
944961713Sgirish  * or http://www.opensolaris.org/os/licensing.
1044961713Sgirish  * See the License for the specific language governing permissions
1144961713Sgirish  * and limitations under the License.
1244961713Sgirish  *
1344961713Sgirish  * When distributing Covered Code, include this CDDL HEADER in each
1444961713Sgirish  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1544961713Sgirish  * If applicable, add the following below this CDDL HEADER, with the
1644961713Sgirish  * fields enclosed by brackets "[]" replaced with your own identifying
1744961713Sgirish  * information: Portions Copyright [yyyy] [name of copyright owner]
1844961713Sgirish  *
1944961713Sgirish  * CDDL HEADER END
2044961713Sgirish  */
2144961713Sgirish /*
22a3c5bd6dSspeer  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
2344961713Sgirish  * Use is subject to license terms.
2444961713Sgirish  */
2544961713Sgirish 
2644961713Sgirish #pragma ident	"%Z%%M%	%I%	%E% SMI"
2744961713Sgirish 
28a3c5bd6dSspeer #include <npi_vir.h>
2944961713Sgirish 
3044961713Sgirish /* One register only */
3144961713Sgirish uint64_t pio_offset[] = {
3244961713Sgirish 	DEV_FUNC_SR_REG
3344961713Sgirish };
3444961713Sgirish 
3544961713Sgirish const char *pio_name[] = {
3644961713Sgirish 	"DEV_FUNC_SR_REG",
3744961713Sgirish };
3844961713Sgirish 
3944961713Sgirish /* One register only */
4044961713Sgirish uint64_t fzc_pio_offset[] = {
4144961713Sgirish 	MULTI_PART_CTL_REG,
4244961713Sgirish 	LDGITMRES_REG
4344961713Sgirish };
4444961713Sgirish 
4544961713Sgirish const char *fzc_pio_name[] = {
4644961713Sgirish 	"MULTI_PART_CTL_REG",
4744961713Sgirish 	"LDGITMRES_REG"
4844961713Sgirish };
4944961713Sgirish 
5044961713Sgirish /* 64 sets */
5144961713Sgirish uint64_t fzc_pio_dma_bind_offset[] = {
5244961713Sgirish 	DMA_BIND_REG
5344961713Sgirish };
5444961713Sgirish 
5544961713Sgirish const char *fzc_pio_dma_bind_name[] = {
5644961713Sgirish 	"DMA_BIND_REG",
5744961713Sgirish };
5844961713Sgirish 
5944961713Sgirish /* 69 logical devices */
6044961713Sgirish uint64_t fzc_pio_ldgnum_offset[] = {
6144961713Sgirish 	LDG_NUM_REG
6244961713Sgirish };
6344961713Sgirish 
6444961713Sgirish const char *fzc_pio_ldgnum_name[] = {
6544961713Sgirish 	"LDG_NUM_REG",
6644961713Sgirish };
6744961713Sgirish 
6844961713Sgirish /* PIO_LDSV, 64 sets by 8192 bytes */
6944961713Sgirish uint64_t pio_ldsv_offset[] = {
7044961713Sgirish 	LDSV0_REG,
7144961713Sgirish 	LDSV1_REG,
7244961713Sgirish 	LDSV2_REG,
7344961713Sgirish 	LDGIMGN_REG
7444961713Sgirish };
7544961713Sgirish const char *pio_ldsv_name[] = {
7644961713Sgirish 	"LDSV0_REG",
7744961713Sgirish 	"LDSV1_REG",
7844961713Sgirish 	"LDSV2_REG",
7944961713Sgirish 	"LDGIMGN_REG"
8044961713Sgirish };
8144961713Sgirish 
8244961713Sgirish /* PIO_IMASK0: 64 by 8192 */
8344961713Sgirish uint64_t pio_imask0_offset[] = {
8444961713Sgirish 	LD_IM0_REG,
8544961713Sgirish };
8644961713Sgirish 
8744961713Sgirish const char *pio_imask0_name[] = {
8844961713Sgirish 	"LD_IM0_REG",
8944961713Sgirish };
9044961713Sgirish 
9144961713Sgirish /* PIO_IMASK1: 5 by 8192 */
9244961713Sgirish uint64_t pio_imask1_offset[] = {
9344961713Sgirish 	LD_IM1_REG
9444961713Sgirish };
9544961713Sgirish 
9644961713Sgirish const char *pio_imask1_name[] = {
9744961713Sgirish 	"LD_IM1_REG"
9844961713Sgirish };
9944961713Sgirish 
10044961713Sgirish /* SID: 64 by 8 */
10144961713Sgirish uint64_t fzc_pio_sid_offset[] = {
10244961713Sgirish 	SID_REG
10344961713Sgirish };
10444961713Sgirish 
10544961713Sgirish const char *fzc_pio_sid_name[] = {
10644961713Sgirish 	"SID_REG"
10744961713Sgirish };
10844961713Sgirish 
10944961713Sgirish npi_status_t
11044961713Sgirish npi_vir_dump_pio_fzc_regs_one(npi_handle_t handle)
11144961713Sgirish {
11244961713Sgirish 	uint64_t value;
11344961713Sgirish 	int num_regs, i;
11444961713Sgirish 
11544961713Sgirish 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
11644961713Sgirish 		"\nPIO FZC Common Register Dump\n"));
11744961713Sgirish 
11844961713Sgirish 	num_regs = sizeof (pio_offset) / sizeof (uint64_t);
11944961713Sgirish 	for (i = 0; i < num_regs; i++) {
12044961713Sgirish 		value = 0;
12144961713Sgirish 		NXGE_REG_RD64(handle, pio_offset[i], &value);
12244961713Sgirish 		NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL, "0x%08llx "
12344961713Sgirish 			"%s\t 0x%08llx \n",
12444961713Sgirish 			pio_offset[i],
12544961713Sgirish 			pio_name[i], value));
12644961713Sgirish 	}
12744961713Sgirish 
12844961713Sgirish 	num_regs = sizeof (fzc_pio_offset) / sizeof (uint64_t);
12944961713Sgirish 	for (i = 0; i < num_regs; i++) {
13044961713Sgirish 		NXGE_REG_RD64(handle, fzc_pio_offset[i], &value);
13144961713Sgirish 		NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL, "0x%08llx "
13244961713Sgirish 			"%s\t 0x%08llx \n",
13344961713Sgirish 			fzc_pio_offset[i],
13444961713Sgirish 			fzc_pio_name[i], value));
13544961713Sgirish 	}
13644961713Sgirish 
13744961713Sgirish 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
13844961713Sgirish 		"\n PIO FZC Register Dump Done \n"));
13944961713Sgirish 	return (NPI_SUCCESS);
14044961713Sgirish }
14144961713Sgirish 
14244961713Sgirish npi_status_t
14344961713Sgirish npi_vir_dump_ldgnum(npi_handle_t handle)
14444961713Sgirish {
14544961713Sgirish 	uint64_t value = 0, offset = 0;
14644961713Sgirish 	int num_regs, i, ldv;
14744961713Sgirish 
14844961713Sgirish 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
14944961713Sgirish 		"\nFZC PIO LDG Number Register Dump\n"));
15044961713Sgirish 
15144961713Sgirish 	num_regs = sizeof (fzc_pio_ldgnum_offset) / sizeof (uint64_t);
15244961713Sgirish 	for (ldv = 0; ldv < NXGE_INT_MAX_LDS; ldv++) {
15344961713Sgirish 		for (i = 0; i < num_regs; i++) {
15444961713Sgirish 			value = 0;
15544961713Sgirish 			offset = fzc_pio_ldgnum_offset[i] + 8 * ldv;
15644961713Sgirish 			NXGE_REG_RD64(handle, offset, &value);
15744961713Sgirish 			NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
15844961713Sgirish 				"Logical Device %d: 0x%08llx "
15944961713Sgirish 				"%s\t 0x%08llx \n",
16044961713Sgirish 				ldv, offset,
16144961713Sgirish 				fzc_pio_ldgnum_name[i], value));
16244961713Sgirish 		}
16344961713Sgirish 	}
16444961713Sgirish 
16544961713Sgirish 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
16644961713Sgirish 		"\n FZC PIO LDG Register Dump Done \n"));
16744961713Sgirish 
16844961713Sgirish 	return (NPI_SUCCESS);
16944961713Sgirish }
17044961713Sgirish 
17144961713Sgirish npi_status_t
17244961713Sgirish npi_vir_dump_ldsv(npi_handle_t handle)
17344961713Sgirish {
17444961713Sgirish 	uint64_t value, offset;
17544961713Sgirish 	int num_regs, i, ldg;
17644961713Sgirish 
17744961713Sgirish 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
17844961713Sgirish 		"\nLD Device State Vector Register Dump\n"));
17944961713Sgirish 
18044961713Sgirish 	num_regs = sizeof (pio_ldsv_offset) / sizeof (uint64_t);
18144961713Sgirish 	for (ldg = 0; ldg < NXGE_INT_MAX_LDGS; ldg++) {
18244961713Sgirish 		for (i = 0; i < num_regs; i++) {
18344961713Sgirish 			value = 0;
18444961713Sgirish 			offset = pio_ldsv_offset[i] + 8192 * ldg;
18544961713Sgirish 			NXGE_REG_RD64(handle, offset, &value);
18644961713Sgirish 			NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
18744961713Sgirish 				    "LDG State: group %d: 0x%08llx "
18844961713Sgirish 				    "%s\t 0x%08llx \n",
18944961713Sgirish 				ldg, offset,
19044961713Sgirish 				pio_ldsv_name[i], value));
19144961713Sgirish 		}
19244961713Sgirish 	}
19344961713Sgirish 
19444961713Sgirish 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
19544961713Sgirish 		"\n FZC PIO LDG Register Dump Done \n"));
19644961713Sgirish 
19744961713Sgirish 	return (NPI_SUCCESS);
19844961713Sgirish }
19944961713Sgirish 
20044961713Sgirish npi_status_t
20144961713Sgirish npi_vir_dump_imask0(npi_handle_t handle)
20244961713Sgirish {
20344961713Sgirish 	uint64_t value, offset;
20444961713Sgirish 	int num_regs, i, ldv;
20544961713Sgirish 
20644961713Sgirish 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
20744961713Sgirish 		"\nLD Interrupt Mask Register Dump\n"));
20844961713Sgirish 
20944961713Sgirish 	num_regs = sizeof (pio_imask0_offset) / sizeof (uint64_t);
21044961713Sgirish 	for (ldv = 0; ldv < 64; ldv++) {
21144961713Sgirish 		for (i = 0; i < num_regs; i++) {
21244961713Sgirish 			value = 0;
21344961713Sgirish 			offset = pio_imask0_offset[i] + 8192 * ldv;
21444961713Sgirish 			NXGE_REG_RD64(handle, offset,
21544961713Sgirish 				&value);
21644961713Sgirish 			NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
21744961713Sgirish 				"LD Interrupt Mask %d: 0x%08llx "
21844961713Sgirish 				"%s\t 0x%08llx \n",
21944961713Sgirish 				ldv, offset,
22044961713Sgirish 				pio_imask0_name[i], value));
22144961713Sgirish 		}
22244961713Sgirish 	}
22344961713Sgirish 	num_regs = sizeof (pio_imask1_offset) / sizeof (uint64_t);
22444961713Sgirish 	for (ldv = 64; ldv < 69; ldv++) {
22544961713Sgirish 		for (i = 0; i < num_regs; i++) {
22644961713Sgirish 			value = 0;
22744961713Sgirish 			offset = pio_imask1_offset[i] + 8192 * (ldv - 64);
22844961713Sgirish 			NXGE_REG_RD64(handle, offset,
22944961713Sgirish 				&value);
23044961713Sgirish 			NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
23144961713Sgirish 				"LD Interrupt Mask %d: 0x%08llx "
23244961713Sgirish 				"%s\t 0x%08llx \n",
23344961713Sgirish 				ldv, offset,
23444961713Sgirish 				pio_imask1_name[i], value));
23544961713Sgirish 		}
23644961713Sgirish 	}
23744961713Sgirish 
23844961713Sgirish 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
23944961713Sgirish 		"\n FZC PIO Logical Device Group Register Dump Done \n"));
24044961713Sgirish 
24144961713Sgirish 	return (NPI_SUCCESS);
24244961713Sgirish }
24344961713Sgirish 
24444961713Sgirish npi_status_t
24544961713Sgirish npi_vir_dump_sid(npi_handle_t handle)
24644961713Sgirish {
24744961713Sgirish 	uint64_t value, offset;
24844961713Sgirish 	int num_regs, i, ldg;
24944961713Sgirish 
25044961713Sgirish 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
25144961713Sgirish 		"\nSystem Interrupt Data Register Dump\n"));
25244961713Sgirish 
25344961713Sgirish 	num_regs = sizeof (fzc_pio_sid_offset) / sizeof (uint64_t);
25444961713Sgirish 	for (ldg = 0; ldg < NXGE_INT_MAX_LDGS; ldg++) {
25544961713Sgirish 		for (i = 0; i < num_regs; i++) {
25644961713Sgirish 			value = 0;
25744961713Sgirish 			offset = fzc_pio_sid_offset[i] + 8 * ldg;
25844961713Sgirish 			NXGE_REG_RD64(handle, offset,
25944961713Sgirish 				&value);
26044961713Sgirish 			NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
26144961713Sgirish 				"SID for group %d: 0x%08llx "
26244961713Sgirish 				"%s\t 0x%08llx \n",
26344961713Sgirish 				ldg, offset,
26444961713Sgirish 				fzc_pio_sid_name[i], value));
26544961713Sgirish 		}
26644961713Sgirish 	}
26744961713Sgirish 
26844961713Sgirish 	NPI_REG_DUMP_MSG((handle.function, NPI_REG_CTL,
26944961713Sgirish 		"\n FZC PIO SID Register Dump Done \n"));
27044961713Sgirish 
27144961713Sgirish 	return (NPI_SUCCESS);
27244961713Sgirish }
27344961713Sgirish 
27444961713Sgirish /*
27544961713Sgirish  * npi_dev_func_sr_init():
27644961713Sgirish  *	This function is called to initialize the device function
27744961713Sgirish  *	shared register (set the software implementation lock
27844961713Sgirish  *	state to FREE).
27944961713Sgirish  * Parameters:
28044961713Sgirish  *	handle		- NPI handle
28144961713Sgirish  * Return:
28244961713Sgirish  *	NPI_SUCCESS	- If initialization is complete successfully.
28344961713Sgirish  *			  (set sr bits to free).
28444961713Sgirish  *	Error:
28544961713Sgirish  *	NPI_FAILURE
28644961713Sgirish  *		VIR_TAS_BUSY
28744961713Sgirish  */
288a3c5bd6dSspeer 
28944961713Sgirish npi_status_t
29044961713Sgirish npi_dev_func_sr_init(npi_handle_t handle)
29144961713Sgirish {
29244961713Sgirish 	dev_func_sr_t		sr;
29344961713Sgirish 	int			status = NPI_SUCCESS;
29444961713Sgirish 
29544961713Sgirish 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
29644961713Sgirish 	if (!sr.bits.ldw.tas) {
29744961713Sgirish 		/*
29844961713Sgirish 		 * After read, this bit is set to 1 by hardware.
29944961713Sgirish 		 * We own it if tas bit read as 0.
30044961713Sgirish 		 * Set the lock state to free if it is in reset state.
30144961713Sgirish 		 */
30244961713Sgirish 		if (!sr.bits.ldw.sr) {
30344961713Sgirish 			/* reset state */
30444961713Sgirish 			sr.bits.ldw.sr |= NPI_DEV_SR_LOCK_ST_FREE;
30544961713Sgirish 			NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
30644961713Sgirish 			sr.bits.ldw.tas = 0;
30744961713Sgirish 			NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
30844961713Sgirish 		}
30944961713Sgirish 
310*56d930aeSspeer 		NPI_DEBUG_MSG((handle.function, NPI_VIR_CTL,
31144961713Sgirish 			" npi_dev_func_sr_init"
31244961713Sgirish 			" sr <0x%x>",
31344961713Sgirish 			sr.bits.ldw.sr));
31444961713Sgirish 	} else {
31544961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
31644961713Sgirish 				    " npi_dev_func_sr_init"
31744961713Sgirish 				    " tas busy <0x%x>",
31844961713Sgirish 				    sr.bits.ldw));
31944961713Sgirish 		status = NPI_VIR_TAS_BUSY(sr.bits.ldw.funcid);
32044961713Sgirish 	}
32144961713Sgirish 
32244961713Sgirish 	return (status);
32344961713Sgirish }
32444961713Sgirish 
32544961713Sgirish /*
32644961713Sgirish  * npi_dev_func_sr_lock_enter():
32744961713Sgirish  *	This function is called to lock the function shared register
32844961713Sgirish  *	by setting the lock state to busy.
32944961713Sgirish  * Parameters:
33044961713Sgirish  *	handle		- NPI handle
33144961713Sgirish  * Return:
33244961713Sgirish  *	NPI_SUCCESS	- If the function id can own the lock.
33344961713Sgirish  *
33444961713Sgirish  *	Error:
33544961713Sgirish  *	NPI_FAILURE
33644961713Sgirish  *		VIR_SR_RESET
33744961713Sgirish  *		VIR_SR_BUSY
33844961713Sgirish  *		VIR_SR_INVALID
33944961713Sgirish  *		VIR_TAS_BUSY
34044961713Sgirish  */
341a3c5bd6dSspeer 
34244961713Sgirish npi_status_t
34344961713Sgirish npi_dev_func_sr_lock_enter(npi_handle_t handle)
34444961713Sgirish {
34544961713Sgirish 	dev_func_sr_t		sr;
34644961713Sgirish 	int			status = NPI_SUCCESS;
34744961713Sgirish 	uint32_t		state;
34844961713Sgirish 
34944961713Sgirish 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
35044961713Sgirish 	if (!sr.bits.ldw.tas) {
35144961713Sgirish 		/*
35244961713Sgirish 		 * tas bit will be set to 1 by hardware.
35344961713Sgirish 		 * reset tas bit when we unlock the sr.
35444961713Sgirish 		 */
35544961713Sgirish 		state = sr.bits.ldw.sr & NPI_DEV_SR_LOCK_ST_MASK;
35644961713Sgirish 		switch (state) {
35744961713Sgirish 		case NPI_DEV_SR_LOCK_ST_FREE:
35844961713Sgirish 			/*
35944961713Sgirish 			 * set it to busy and our function id.
36044961713Sgirish 			 */
36144961713Sgirish 			sr.bits.ldw.sr |= (NPI_DEV_SR_LOCK_ST_BUSY |
36244961713Sgirish 						(sr.bits.ldw.funcid <<
36344961713Sgirish 						NPI_DEV_SR_LOCK_FID_SHIFT));
36444961713Sgirish 			NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
36544961713Sgirish 			break;
36644961713Sgirish 
36744961713Sgirish 		case NPI_DEV_SR_LOCK_ST_RESET:
36844961713Sgirish 			NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
36944961713Sgirish 					    " npi_dev_func_sr_lock_enter"
37044961713Sgirish 					    " reset state <0x%x>",
37144961713Sgirish 					    sr.bits.ldw.sr));
37244961713Sgirish 			status = NPI_VIR_SR_RESET(sr.bits.ldw.funcid);
37344961713Sgirish 			break;
37444961713Sgirish 
37544961713Sgirish 		case NPI_DEV_SR_LOCK_ST_BUSY:
37644961713Sgirish 			NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
37744961713Sgirish 					    " npi_dev_func_sr_lock_enter"
37844961713Sgirish 					    " busy <0x%x>",
37944961713Sgirish 					    sr.bits.ldw.sr));
38044961713Sgirish 			status = NPI_VIR_SR_BUSY(sr.bits.ldw.funcid);
38144961713Sgirish 			break;
38244961713Sgirish 
38344961713Sgirish 		default:
38444961713Sgirish 			NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
38544961713Sgirish 					    " npi_dev_func_sr_lock_enter",
38644961713Sgirish 					    " invalid state",
38744961713Sgirish 					    sr.bits.ldw.sr));
38844961713Sgirish 			status = NPI_VIR_SR_INVALID(sr.bits.ldw.funcid);
38944961713Sgirish 			break;
39044961713Sgirish 		}
39144961713Sgirish 	} else {
39244961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
39344961713Sgirish 				    " npi_dev_func_sr_lock_enter",
39444961713Sgirish 				    " tas busy", sr.bits.ldw));
39544961713Sgirish 		status = NPI_VIR_TAS_BUSY(sr.bits.ldw.funcid);
39644961713Sgirish 	}
39744961713Sgirish 
39844961713Sgirish 	return (status);
39944961713Sgirish }
40044961713Sgirish 
40144961713Sgirish /*
40244961713Sgirish  * npi_dev_func_sr_lock_free():
40344961713Sgirish  *	This function is called to free the function shared register
40444961713Sgirish  *	by setting the lock state to free.
40544961713Sgirish  * Parameters:
40644961713Sgirish  *	handle		- NPI handle
40744961713Sgirish  * Return:
40844961713Sgirish  *	NPI_SUCCESS	- If the function id can free the lock.
40944961713Sgirish  *
41044961713Sgirish  *	Error:
41144961713Sgirish  *	NPI_FAILURE
41244961713Sgirish  *		VIR_SR_NOTOWNER
41344961713Sgirish  *		VIR_TAS_NOTREAD
41444961713Sgirish  */
415a3c5bd6dSspeer 
41644961713Sgirish npi_status_t
41744961713Sgirish npi_dev_func_sr_lock_free(npi_handle_t handle)
41844961713Sgirish {
41944961713Sgirish 	dev_func_sr_t		sr;
42044961713Sgirish 	int			status = NPI_SUCCESS;
42144961713Sgirish 
42244961713Sgirish 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
42344961713Sgirish 	if (sr.bits.ldw.tas) {
42444961713Sgirish 		if (sr.bits.ldw.funcid == NPI_GET_LOCK_OWNER(sr.bits.ldw.sr)) {
42544961713Sgirish 			sr.bits.ldw.sr &= NPI_DEV_SR_IMPL_ST_MASK;
42644961713Sgirish 			sr.bits.ldw.sr |= NPI_DEV_SR_LOCK_ST_FREE;
42744961713Sgirish 			sr.bits.ldw.tas = 0;
42844961713Sgirish 			NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
42944961713Sgirish 		} else {
43044961713Sgirish 			NPI_DEBUG_MSG((handle.function, NPI_VIR_CTL,
43144961713Sgirish 					    " npi_dev_func_sr_lock_free"
43244961713Sgirish 					    " not owner <0x%x>",
43344961713Sgirish 					    sr.bits.ldw.sr));
43444961713Sgirish 			status = NPI_VIR_SR_NOTOWNER(sr.bits.ldw.funcid);
43544961713Sgirish 		}
43644961713Sgirish 	} else {
43744961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
43844961713Sgirish 				    " npi_dev_func_sr_lock_free",
43944961713Sgirish 				    " invalid tas state <0x%x>",
44044961713Sgirish 				    sr.bits.ldw.tas));
44144961713Sgirish 		status = NPI_VIR_TAS_NOTREAD(sr.bits.ldw.funcid);
44244961713Sgirish 	}
44344961713Sgirish 
44444961713Sgirish 	return (status);
44544961713Sgirish }
44644961713Sgirish 
44744961713Sgirish /*
44844961713Sgirish  * npi_dev_func_sr_funcid_get():
44944961713Sgirish  *	This function is called to get the caller's function ID.
45044961713Sgirish  *	(based on address bits [25:26] on read access.
45144961713Sgirish  *	(After read, the TAS bit is always set to 1. Software needs
45244961713Sgirish  *	to write 0 to clear.) This function will write 0 to clear
45344961713Sgirish  *	the TAS bit if we own it.
45444961713Sgirish  * Parameters:
45544961713Sgirish  *	handle		- NPI handle
45644961713Sgirish  *	funcid_p	- pointer to store the function id.
45744961713Sgirish  * Return:
45844961713Sgirish  *	NPI_SUCCESS	- If get function id is complete successfully.
45944961713Sgirish  *
46044961713Sgirish  *	Error:
46144961713Sgirish  */
462a3c5bd6dSspeer 
46344961713Sgirish npi_status_t
46444961713Sgirish npi_dev_func_sr_funcid_get(npi_handle_t handle, uint8_t *funcid_p)
46544961713Sgirish {
46644961713Sgirish 	dev_func_sr_t		sr;
46744961713Sgirish 
46844961713Sgirish 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
46944961713Sgirish 	*funcid_p = NXGE_VAL(DEV_FUNC_SR_FUNCID, sr.value);
47044961713Sgirish 	if (!sr.bits.ldw.tas) {
47144961713Sgirish 		/*
47244961713Sgirish 		 * After read, this bit is set to 1 by hardware.
47344961713Sgirish 		 * We own it if tas bit read as 0.
47444961713Sgirish 		 */
47544961713Sgirish 		sr.bits.ldw.tas = 0;
47644961713Sgirish 		NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
47744961713Sgirish 	}
47844961713Sgirish 
47944961713Sgirish 	return (NPI_SUCCESS);
48044961713Sgirish }
48144961713Sgirish 
48244961713Sgirish /*
48344961713Sgirish  * npi_dev_func_sr_sr_get():
48444961713Sgirish  *	This function is called to get the shared register value.
48544961713Sgirish  *	(After read, the TAS bit is always set to 1. Software needs
48644961713Sgirish  *	to write 0 to clear if we own it.)
48744961713Sgirish  *
48844961713Sgirish  * Parameters:
48944961713Sgirish  *	handle		- NPI handle
49044961713Sgirish  *	sr_p		- pointer to store the shared value of this register.
49144961713Sgirish  *
49244961713Sgirish  * Return:
49344961713Sgirish  *	NPI_SUCCESS		- If shared value get is complete successfully.
49444961713Sgirish  *
49544961713Sgirish  *	Error:
49644961713Sgirish  */
49744961713Sgirish npi_status_t
49844961713Sgirish npi_dev_func_sr_sr_raw_get(npi_handle_t handle, uint16_t *sr_p)
49944961713Sgirish {
50044961713Sgirish 	dev_func_sr_t		sr;
50144961713Sgirish 
50244961713Sgirish 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
50344961713Sgirish 	*sr_p = NXGE_VAL(DEV_FUNC_SR_FUNCID, sr.value);
50444961713Sgirish 	if (!sr.bits.ldw.tas) {
50544961713Sgirish 		/*
50644961713Sgirish 		 * After read, this bit is set to 1 by hardware.
50744961713Sgirish 		 * We own it if tas bit read as 0.
50844961713Sgirish 		 */
50944961713Sgirish 		sr.bits.ldw.tas = 0;
51044961713Sgirish 		NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
51144961713Sgirish 	}
51244961713Sgirish 
51344961713Sgirish 	return (NPI_SUCCESS);
51444961713Sgirish }
51544961713Sgirish 
51644961713Sgirish /*
51744961713Sgirish  * npi_dev_func_sr_sr_get():
51844961713Sgirish  *	This function is called to get the shared register value.
51944961713Sgirish  *	(After read, the TAS bit is always set to 1. Software needs
52044961713Sgirish  *	to write 0 to clear if we own it.)
52144961713Sgirish  *
52244961713Sgirish  * Parameters:
52344961713Sgirish  *	handle	- NPI handle
52444961713Sgirish  *	sr_p	- pointer to store the shared value of this register.
52544961713Sgirish  *		. this will get only non-lock, non-function id portion
52644961713Sgirish  *              . of the register
52744961713Sgirish  *
52844961713Sgirish  *
52944961713Sgirish  * Return:
53044961713Sgirish  *	NPI_SUCCESS		- If shared value get is complete successfully.
53144961713Sgirish  *
53244961713Sgirish  *	Error:
53344961713Sgirish  */
53444961713Sgirish 
53544961713Sgirish npi_status_t
53644961713Sgirish npi_dev_func_sr_sr_get(npi_handle_t handle, uint16_t *sr_p)
53744961713Sgirish {
53844961713Sgirish 	dev_func_sr_t		sr;
53944961713Sgirish 	uint16_t sr_impl = 0;
54044961713Sgirish 
54144961713Sgirish 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
54244961713Sgirish 	sr_impl = NXGE_VAL(DEV_FUNC_SR_FUNCID, sr.value);
54344961713Sgirish 	*sr_p =  (sr_impl << NPI_DEV_SR_IMPL_ST_SHIFT);
54444961713Sgirish 	if (!sr.bits.ldw.tas) {
54544961713Sgirish 		/*
54644961713Sgirish 		 * After read, this bit is set to 1 by hardware.
54744961713Sgirish 		 * We own it if tas bit read as 0.
54844961713Sgirish 		 */
54944961713Sgirish 		sr.bits.ldw.tas = 0;
55044961713Sgirish 		NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
55144961713Sgirish 	}
55244961713Sgirish 
55344961713Sgirish 	return (NPI_SUCCESS);
55444961713Sgirish }
55544961713Sgirish 
55644961713Sgirish /*
55744961713Sgirish  * npi_dev_func_sr_sr_get_set_clear():
55844961713Sgirish  *	This function is called to set the shared register value.
55944961713Sgirish  *	(Shared register must be read first. If tas bit is 0, then
56044961713Sgirish  *	it implies that the software can proceed to set). After
56144961713Sgirish  *	setting, tas bit will be cleared.
56244961713Sgirish  * Parameters:
56344961713Sgirish  *	handle		- NPI handle
56444961713Sgirish  *	impl_sr		- shared value to set (only the 8 bit
56544961713Sgirish  *			  implementation specific state info).
56644961713Sgirish  *
56744961713Sgirish  * Return:
56844961713Sgirish  *	NPI_SUCCESS		- If shared value is set successfully.
56944961713Sgirish  *
57044961713Sgirish  *	Error:
57144961713Sgirish  *	NPI_FAILURE
57244961713Sgirish  *		VIR_TAS_BUSY
57344961713Sgirish  */
574a3c5bd6dSspeer 
57544961713Sgirish npi_status_t
57644961713Sgirish npi_dev_func_sr_sr_get_set_clear(npi_handle_t handle, uint16_t impl_sr)
57744961713Sgirish {
57844961713Sgirish 	dev_func_sr_t		sr;
57944961713Sgirish 	int			status;
58044961713Sgirish 
58144961713Sgirish 	status = npi_dev_func_sr_lock_enter(handle);
58244961713Sgirish 	if (status != NPI_SUCCESS) {
58344961713Sgirish 		NPI_DEBUG_MSG((handle.function, NPI_VIR_CTL,
58444961713Sgirish 				    " npi_dev_func_sr_src_get_set_clear"
58544961713Sgirish 				    " unable to acquire lock:"
58644961713Sgirish 				    " status <0x%x>", status));
58744961713Sgirish 		return (status);
58844961713Sgirish 	}
58944961713Sgirish 
59044961713Sgirish 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
59144961713Sgirish 	sr.bits.ldw.sr |= (impl_sr << NPI_DEV_SR_IMPL_ST_SHIFT);
59244961713Sgirish 	NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
59344961713Sgirish 
59444961713Sgirish 	return (npi_dev_func_sr_lock_free(handle));
59544961713Sgirish }
59644961713Sgirish 
59744961713Sgirish /*
59844961713Sgirish  * npi_dev_func_sr_sr_set_only():
59944961713Sgirish  *	This function is called to only set the shared register value.
60044961713Sgirish  * Parameters:
60144961713Sgirish  *	handle		- NPI handle
60244961713Sgirish  *	impl_sr		- shared value to set.
60344961713Sgirish  *
60444961713Sgirish  * Return:
60544961713Sgirish  *	NPI_SUCCESS		- If shared value is set successfully.
60644961713Sgirish  *
60744961713Sgirish  *	Error:
60844961713Sgirish  *	NPI_FAILURE
60944961713Sgirish  *		VIR_TAS_BUSY
61044961713Sgirish  */
611a3c5bd6dSspeer 
61244961713Sgirish npi_status_t
61344961713Sgirish npi_dev_func_sr_sr_set_only(npi_handle_t handle, uint16_t impl_sr)
61444961713Sgirish {
61544961713Sgirish 	int		status = NPI_SUCCESS;
61644961713Sgirish 	dev_func_sr_t	sr;
61744961713Sgirish 
61844961713Sgirish 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
61944961713Sgirish 	/* must be the owner */
62044961713Sgirish 	if (sr.bits.ldw.funcid == NPI_GET_LOCK_OWNER(sr.bits.ldw.sr)) {
62144961713Sgirish 		sr.bits.ldw.sr |= (impl_sr << NPI_DEV_SR_IMPL_ST_SHIFT);
62244961713Sgirish 		NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
62344961713Sgirish 	} else {
62444961713Sgirish 		NPI_DEBUG_MSG((handle.function, NPI_VIR_CTL,
62544961713Sgirish 				    " npi_dev_func_sr_sr_set_only"
62644961713Sgirish 				    " not owner <0x%x>",
62744961713Sgirish 				    sr.bits.ldw.sr));
62844961713Sgirish 		status = NPI_VIR_SR_NOTOWNER(sr.bits.ldw.funcid);
62944961713Sgirish 	}
63044961713Sgirish 
63144961713Sgirish 	return (status);
63244961713Sgirish }
63344961713Sgirish 
63444961713Sgirish /*
63544961713Sgirish  * npi_dev_func_sr_busy():
63644961713Sgirish  *	This function is called to see if we can own the device.
63744961713Sgirish  *	It will not reset the tas bit.
63844961713Sgirish  * Parameters:
63944961713Sgirish  *	handle		- NPI handle
64044961713Sgirish  *	busy_p		- pointer to store busy flag.
64144961713Sgirish  *				(B_TRUE: device is in use, B_FALSE: free).
64244961713Sgirish  * Return:
64344961713Sgirish  *	NPI_SUCCESS		- If tas bit is read successfully.
64444961713Sgirish  *	Error:
64544961713Sgirish  */
646a3c5bd6dSspeer 
64744961713Sgirish npi_status_t
64844961713Sgirish npi_dev_func_sr_busy(npi_handle_t handle, boolean_t *busy_p)
64944961713Sgirish {
65044961713Sgirish 	dev_func_sr_t	sr;
65144961713Sgirish 
65244961713Sgirish 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
65344961713Sgirish 	if (!sr.bits.ldw.tas) {
65444961713Sgirish 		sr.bits.ldw.tas = 0;
65544961713Sgirish 		NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
65644961713Sgirish 		*busy_p = B_FALSE;
65744961713Sgirish 	} else {
65844961713Sgirish 		/* Other function already owns it */
65944961713Sgirish 		*busy_p = B_TRUE;
66044961713Sgirish 	}
66144961713Sgirish 
66244961713Sgirish 	return (NPI_SUCCESS);
66344961713Sgirish }
66444961713Sgirish 
66544961713Sgirish /*
66644961713Sgirish  * npi_dev_func_sr_tas_get():
66744961713Sgirish  *	This function is called to get the tas bit
66844961713Sgirish  *	(after read, this bit is always set to 1, software write 0
66944961713Sgirish  *	 to clear it).
67044961713Sgirish  *
67144961713Sgirish  * Parameters:
67244961713Sgirish  *	handle		- NPI handle
67344961713Sgirish  *	tas_p		- pointer to store the tas value
67444961713Sgirish  *
67544961713Sgirish  * Return:
67644961713Sgirish  *	NPI_SUCCESS		- If tas value get is complete successfully.
67744961713Sgirish  *	Error:
67844961713Sgirish  */
679a3c5bd6dSspeer 
68044961713Sgirish npi_status_t
68144961713Sgirish npi_dev_func_sr_tas_get(npi_handle_t handle, uint8_t *tas_p)
68244961713Sgirish {
68344961713Sgirish 	dev_func_sr_t		sr;
68444961713Sgirish 
68544961713Sgirish 	NXGE_REG_RD64(handle, DEV_FUNC_SR_REG, &sr.value);
68644961713Sgirish 	*tas_p = sr.bits.ldw.tas;
68744961713Sgirish 	if (!sr.bits.ldw.tas) {
68844961713Sgirish 		sr.bits.ldw.tas = 0;
68944961713Sgirish 		NXGE_REG_WR64(handle, DEV_FUNC_SR_REG, sr.value);
69044961713Sgirish 
69144961713Sgirish 	}
69244961713Sgirish 
69344961713Sgirish 	return (NPI_SUCCESS);
69444961713Sgirish }
69544961713Sgirish 
69644961713Sgirish /*
69744961713Sgirish  * npi_fzc_mpc_set():
69844961713Sgirish  *	This function is called to enable the write access
69944961713Sgirish  *	to FZC region to function zero.
70044961713Sgirish  * Parameters:
70144961713Sgirish  *	handle		- NPI handle
70244961713Sgirish  * Return:
70344961713Sgirish  *	NPI_SUCCESS	-
70444961713Sgirish  *	Error:
70544961713Sgirish  */
706a3c5bd6dSspeer 
70744961713Sgirish npi_status_t
70844961713Sgirish npi_fzc_mpc_set(npi_handle_t handle, boolean_t mpc)
70944961713Sgirish {
71044961713Sgirish 	multi_part_ctl_t	mp;
71144961713Sgirish 
71244961713Sgirish 	mp.value = 0;
71344961713Sgirish 	if (mpc) {
71444961713Sgirish 		mp.bits.ldw.mpc = 1;
71544961713Sgirish 	}
71644961713Sgirish 	NXGE_REG_WR64(handle, MULTI_PART_CTL_REG, mp.value);
71744961713Sgirish 
71844961713Sgirish 	return (NPI_SUCCESS);
71944961713Sgirish }
72044961713Sgirish 
72144961713Sgirish /*
72244961713Sgirish  * npi_fzc_mpc_get():
72344961713Sgirish  *	This function is called to get the access mode.
72444961713Sgirish  * Parameters:
72544961713Sgirish  *	handle		- NPI handle
72644961713Sgirish  * Return:
72744961713Sgirish  *	NPI_SUCCESS	-
72844961713Sgirish  *
72944961713Sgirish  */
730a3c5bd6dSspeer 
73144961713Sgirish npi_status_t
73244961713Sgirish npi_fzc_mpc_get(npi_handle_t handle, boolean_t *mpc_p)
73344961713Sgirish {
73444961713Sgirish 	multi_part_ctl_t	mpc;
73544961713Sgirish 
73644961713Sgirish 	mpc.value = 0;
73744961713Sgirish 	NXGE_REG_RD64(handle, MULTI_PART_CTL_REG, &mpc.value);
73844961713Sgirish 	*mpc_p = mpc.bits.ldw.mpc;
73944961713Sgirish 
74044961713Sgirish 	return (NPI_SUCCESS);
74144961713Sgirish }
74244961713Sgirish 
74344961713Sgirish /*
74444961713Sgirish  * npi_fzc_dma_bind_set():
74544961713Sgirish  *	This function is called to set DMA binding register.
74644961713Sgirish  * Parameters:
74744961713Sgirish  *	handle		- NPI handle
74844961713Sgirish  *	dma_bind	- NPI defined data structure that
74944961713Sgirish  *			  contains the tx/rx channel binding info.
75044961713Sgirish  *			  to set.
75144961713Sgirish  * Return:
75244961713Sgirish  *	NPI_SUCCESS	-
75344961713Sgirish  *	Error:
75444961713Sgirish  *	NPI_FAILURE
75544961713Sgirish  *
75644961713Sgirish  */
757a3c5bd6dSspeer 
75844961713Sgirish npi_status_t
75944961713Sgirish npi_fzc_dma_bind_set(npi_handle_t handle, fzc_dma_bind_t dma_bind)
76044961713Sgirish {
76144961713Sgirish 	dma_bind_t	bind;
76244961713Sgirish 	int		status;
76344961713Sgirish 	uint8_t		fn, region, id, tn, rn;
76444961713Sgirish 
76544961713Sgirish 	fn = dma_bind.function_id;
76644961713Sgirish 	region = dma_bind.sub_vir_region;
76744961713Sgirish 	id = dma_bind.vir_index;
76844961713Sgirish 	tn = dma_bind.tx_channel;
76944961713Sgirish 	rn = dma_bind.rx_channel;
77044961713Sgirish 
77144961713Sgirish 	DMA_BIND_VADDR_VALIDATE(fn, region, id, status);
77244961713Sgirish 	if (status) {
77344961713Sgirish 		return (status);
77444961713Sgirish 	}
77544961713Sgirish 
77644961713Sgirish 	if (dma_bind.tx_bind) {
77744961713Sgirish 		DMA_BIND_TX_VALIDATE(tn, status);
77844961713Sgirish 		if (status) {
77944961713Sgirish 			return (status);
78044961713Sgirish 		}
78144961713Sgirish 	}
78244961713Sgirish 
78344961713Sgirish 	if (dma_bind.rx_bind) {
78444961713Sgirish 		DMA_BIND_RX_VALIDATE(rn, status);
78544961713Sgirish 		if (status) {
78644961713Sgirish 			return (status);
78744961713Sgirish 		}
78844961713Sgirish 	}
78944961713Sgirish 
79044961713Sgirish 	bind.value = 0;
79144961713Sgirish 	if (dma_bind.tx_bind) {
79244961713Sgirish 		bind.bits.ldw.tx_bind = 1;
79344961713Sgirish 		bind.bits.ldw.tx = tn;
79444961713Sgirish 	}
79544961713Sgirish 	if (dma_bind.rx_bind) {
79644961713Sgirish 		bind.bits.ldw.rx_bind = 1;
79744961713Sgirish 		bind.bits.ldw.rx = rn;
79844961713Sgirish 	}
79944961713Sgirish 
80044961713Sgirish 	NXGE_REG_WR64(handle, DMA_BIND_REG +
80144961713Sgirish 		DMA_BIND_REG_OFFSET(fn, rn, id), bind.value);
80244961713Sgirish 
80344961713Sgirish 	return (status);
80444961713Sgirish }
80544961713Sgirish 
80644961713Sgirish /*
80744961713Sgirish  * npi_fzc_ldg_num_set():
80844961713Sgirish  *	This function is called to set up a logical group number that
80944961713Sgirish  *	a logical device belongs to.
81044961713Sgirish  * Parameters:
81144961713Sgirish  *	handle		- NPI handle
81244961713Sgirish  *	ld		- logical device number (0 - 68)
81344961713Sgirish  *	ldg		- logical device group number (0 - 63)
81444961713Sgirish  * Return:
81544961713Sgirish  *	NPI_SUCCESS	-
81644961713Sgirish  *	Error:
81744961713Sgirish  *	NPI_FAILURE
81844961713Sgirish  *
81944961713Sgirish  */
820a3c5bd6dSspeer 
82144961713Sgirish npi_status_t
82244961713Sgirish npi_fzc_ldg_num_set(npi_handle_t handle, uint8_t ld, uint8_t ldg)
82344961713Sgirish {
82444961713Sgirish 	ldg_num_t	gnum;
82544961713Sgirish 
826a3c5bd6dSspeer 	ASSERT(LD_VALID(ld));
82744961713Sgirish 	if (!LD_VALID(ld)) {
82844961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
82944961713Sgirish 				    " npi_fzc_ldg_num_set"
83044961713Sgirish 				    "ld <0x%x>", ld));
83144961713Sgirish 		return (NPI_FAILURE | NPI_VIR_LD_INVALID(ld));
83244961713Sgirish 	}
833a3c5bd6dSspeer 
834a3c5bd6dSspeer 	ASSERT(LDG_VALID(ldg));
83544961713Sgirish 	if (!LDG_VALID(ldg)) {
83644961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
83744961713Sgirish 				    " npi_fzc_ldg_num_set"
83844961713Sgirish 				    " ldg <0x%x>", ldg));
83944961713Sgirish 		return (NPI_FAILURE | NPI_VIR_LDG_INVALID(ld));
84044961713Sgirish 	}
84144961713Sgirish 
84244961713Sgirish 	gnum.value = 0;
84344961713Sgirish 	gnum.bits.ldw.num = ldg;
84444961713Sgirish 
84544961713Sgirish 	NXGE_REG_WR64(handle, LDG_NUM_REG + LD_NUM_OFFSET(ld),
84644961713Sgirish 		gnum.value);
84744961713Sgirish 
84844961713Sgirish 	return (NPI_SUCCESS);
84944961713Sgirish }
85044961713Sgirish 
85144961713Sgirish /*
85244961713Sgirish  * npi_fzc_ldg_num_get():
85344961713Sgirish  *	This function is called to get the logical device group that
85444961713Sgirish  *	a logical device belongs to.
85544961713Sgirish  * Parameters:
85644961713Sgirish  *	handle		- NPI handle
85744961713Sgirish  *	ld		- logical device number (0 - 68)
85844961713Sgirish  *	*ldg_p		- pointer to store its group number.
85944961713Sgirish  * Return:
86044961713Sgirish  *	NPI_SUCCESS	-
86144961713Sgirish  *	Error:
86244961713Sgirish  *	NPI_FAILURE
86344961713Sgirish  */
864a3c5bd6dSspeer 
86544961713Sgirish npi_status_t
86644961713Sgirish npi_fzc_ldg_num_get(npi_handle_t handle, uint8_t ld, uint8_t *ldg_p)
86744961713Sgirish {
86844961713Sgirish 	uint64_t val;
86944961713Sgirish 
870a3c5bd6dSspeer 	ASSERT(LD_VALID(ld));
87144961713Sgirish 	if (!LD_VALID(ld)) {
87244961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
87344961713Sgirish 				    " npi_fzc_ldg_num_get"
87444961713Sgirish 				    " Invalid Input:",
87544961713Sgirish 				    " ld <0x%x>", ld));
87644961713Sgirish 		return (NPI_FAILURE | NPI_VIR_LD_INVALID(ld));
87744961713Sgirish 	}
87844961713Sgirish 
87944961713Sgirish 	NXGE_REG_RD64(handle, LDG_NUM_REG + LD_NUM_OFFSET(ld), &val);
88044961713Sgirish 
88144961713Sgirish 	*ldg_p = (uint8_t)(val & LDG_NUM_NUM_MASK);
88244961713Sgirish 
88344961713Sgirish 	return (NPI_SUCCESS);
88444961713Sgirish }
88544961713Sgirish 
88644961713Sgirish /*
88744961713Sgirish  * npi_ldsv_ldfs_get():
88844961713Sgirish  *	This function is called to get device state vectors.
88944961713Sgirish  * Parameters:
89044961713Sgirish  *	handle		- NPI handle
89144961713Sgirish  *	ldg		- logical device group (0 - 63)
89244961713Sgirish  *	*ldf_p		- pointer to store ldf0 and ldf1 flag bits.
89344961713Sgirish  * Return:
89444961713Sgirish  *	NPI_SUCCESS	-
89544961713Sgirish  *	Error:
89644961713Sgirish  *	NPI_FAILURE
89744961713Sgirish  */
898a3c5bd6dSspeer 
89944961713Sgirish npi_status_t
90044961713Sgirish npi_ldsv_ldfs_get(npi_handle_t handle, uint8_t ldg, uint64_t *vector0_p,
901a3c5bd6dSspeer 	uint64_t *vector1_p, uint64_t *vector2_p)
90244961713Sgirish {
90344961713Sgirish 	int	status;
90444961713Sgirish 
90544961713Sgirish 	if ((status = npi_ldsv_get(handle, ldg, VECTOR0, vector0_p))) {
90644961713Sgirish 		return (status);
90744961713Sgirish 	}
90844961713Sgirish 	if ((status = npi_ldsv_get(handle, ldg, VECTOR1, vector1_p))) {
90944961713Sgirish 		return (status);
91044961713Sgirish 	}
91144961713Sgirish 	if ((status = npi_ldsv_get(handle, ldg, VECTOR2, vector2_p))) {
91244961713Sgirish 		return (status);
91344961713Sgirish 	}
91444961713Sgirish 
91544961713Sgirish 	return (NPI_SUCCESS);
91644961713Sgirish }
91744961713Sgirish 
91844961713Sgirish /*
91944961713Sgirish  * npi_ldsv_get():
92044961713Sgirish  *	This function is called to get device state vectors.
92144961713Sgirish  * Parameters:
92244961713Sgirish  *	handle		- NPI handle
92344961713Sgirish  *	ldg		- logical device group (0 - 63)
92444961713Sgirish  *	ldf_type	- either LDF0 (0) or LDF1 (1)
92544961713Sgirish  *	vector		- vector type (0, 1 or 2)
92644961713Sgirish  *	*ldf_p		- pointer to store its flag bits.
92744961713Sgirish  * Return:
92844961713Sgirish  *	NPI_SUCCESS	-
92944961713Sgirish  *	Error:
93044961713Sgirish  *	NPI_FAILURE
93144961713Sgirish  */
932a3c5bd6dSspeer 
93344961713Sgirish npi_status_t
93444961713Sgirish npi_ldsv_get(npi_handle_t handle, uint8_t ldg, ldsv_type_t vector,
935a3c5bd6dSspeer 	uint64_t *ldf_p)
93644961713Sgirish {
93744961713Sgirish 	uint64_t		offset;
93844961713Sgirish 
939a3c5bd6dSspeer 	ASSERT(LDG_VALID(ldg));
94044961713Sgirish 	if (!LDG_VALID(ldg)) {
94144961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
94244961713Sgirish 				    " npi_ldsv_get"
94344961713Sgirish 				    " Invalid Input "
94444961713Sgirish 				    " ldg <0x%x>", ldg));
94544961713Sgirish 		return (NPI_FAILURE | NPI_VIR_LDG_INVALID(ldg));
94644961713Sgirish 	}
94744961713Sgirish 
94844961713Sgirish 	switch (vector) {
94944961713Sgirish 	case VECTOR0:
95044961713Sgirish 		offset = LDSV0_REG + LDSV_OFFSET(ldg);
95144961713Sgirish 		break;
95244961713Sgirish 
95344961713Sgirish 	case VECTOR1:
95444961713Sgirish 		offset = LDSV1_REG + LDSV_OFFSET(ldg);
95544961713Sgirish 		break;
95644961713Sgirish 
95744961713Sgirish 	case VECTOR2:
95844961713Sgirish 		offset = LDSV2_REG + LDSV_OFFSET(ldg);
95944961713Sgirish 		break;
96044961713Sgirish 
96144961713Sgirish 	default:
96244961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
96344961713Sgirish 				    " npi_ldsv_get"
96444961713Sgirish 				    " Invalid Input: "
96544961713Sgirish 				    " ldsv type <0x%x>", vector));
96644961713Sgirish 		return (NPI_FAILURE | NPI_VIR_LDSV_INVALID(vector));
96744961713Sgirish 	}
96844961713Sgirish 
96944961713Sgirish 	NXGE_REG_RD64(handle, offset, ldf_p);
97044961713Sgirish 
97144961713Sgirish 	return (NPI_SUCCESS);
97244961713Sgirish }
97344961713Sgirish 
97444961713Sgirish /*
97544961713Sgirish  * npi_ldsv_ld_get():
97644961713Sgirish  *	This function is called to get the flag bit value of a device.
97744961713Sgirish  * Parameters:
97844961713Sgirish  *	handle		- NPI handle
97944961713Sgirish  *	ldg		- logical device group (0 - 63)
98044961713Sgirish  *	ld		- logical device (0 - 68)
98144961713Sgirish  *	ldf_type	- either LDF0 (0) or LDF1 (1)
98244961713Sgirish  *	vector		- vector type (0, 1 or 2)
98344961713Sgirish  *	*ldf_p		- pointer to store its flag bits.
98444961713Sgirish  * Return:
98544961713Sgirish  *	NPI_SUCCESS	-
98644961713Sgirish  *	Error:
98744961713Sgirish  *	NPI_FAILURE
98844961713Sgirish  */
989a3c5bd6dSspeer 
99044961713Sgirish npi_status_t
99144961713Sgirish npi_ldsv_ld_get(npi_handle_t handle, uint8_t ldg, uint8_t ld,
992a3c5bd6dSspeer 	ldsv_type_t vector, ldf_type_t ldf_type, boolean_t *flag_p)
99344961713Sgirish {
99444961713Sgirish 	uint64_t		sv;
99544961713Sgirish 	uint64_t		offset;
99644961713Sgirish 
997a3c5bd6dSspeer 	ASSERT(LDG_VALID(ldg));
99844961713Sgirish 	if (!LDG_VALID(ldg)) {
99944961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
100044961713Sgirish 				    " npi_ldsv_ld_get"
100144961713Sgirish 				    " Invalid Input: "
100244961713Sgirish 				    " ldg <0x%x>", ldg));
100344961713Sgirish 		return (NPI_FAILURE | NPI_VIR_LDG_INVALID(ldg));
100444961713Sgirish 	}
1005a3c5bd6dSspeer 	ASSERT((LD_VALID(ld)) &&	\
1006a3c5bd6dSspeer 		((vector != VECTOR2) || (ld >= NXGE_MAC_LD_START)));
100744961713Sgirish 	if (!LD_VALID(ld)) {
100844961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
100944961713Sgirish 				    " npi_ldsv_ld_get Invalid Input: "
101044961713Sgirish 				    " ld <9x%x>", ld));
101144961713Sgirish 		return (NPI_FAILURE | NPI_VIR_LD_INVALID(ld));
101244961713Sgirish 	} else if (vector == VECTOR2 && ld < NXGE_MAC_LD_START) {
101344961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
101444961713Sgirish 				    " npi_ldsv_ld_get Invalid Input:"
101544961713Sgirish 				    " ld-vector2 <0x%x>", ld));
101644961713Sgirish 		return (NPI_FAILURE | NPI_VIR_LD_INVALID(ld));
101744961713Sgirish 	}
101844961713Sgirish 
101944961713Sgirish 	switch (vector) {
102044961713Sgirish 	case VECTOR0:
102144961713Sgirish 		offset = LDSV0_REG + LDSV_OFFSET(ldg);
102244961713Sgirish 		break;
102344961713Sgirish 
102444961713Sgirish 	case VECTOR1:
102544961713Sgirish 		offset = LDSV1_REG + LDSV_OFFSET(ldg);
102644961713Sgirish 		break;
102744961713Sgirish 
102844961713Sgirish 	case VECTOR2:
102944961713Sgirish 		offset = LDSV2_REG + LDSV_OFFSET(ldg);
103044961713Sgirish 
103144961713Sgirish 	default:
103244961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL, "npi_ldsv_get"
103344961713Sgirish 			"ldsv", vector));
103444961713Sgirish 		return (NPI_FAILURE | NPI_VIR_LDSV_INVALID(vector));
103544961713Sgirish 	}
103644961713Sgirish 
103744961713Sgirish 	NXGE_REG_RD64(handle, offset, &sv);
103844961713Sgirish 	if (vector != VECTOR2) {
103944961713Sgirish 		*flag_p = ((sv >> ld) & LDSV_MASK_ALL);
104044961713Sgirish 	} else {
104144961713Sgirish 		if (ldf_type) {
104244961713Sgirish 			*flag_p = (((sv >> LDSV2_LDF1_SHIFT) >>
104344961713Sgirish 				(ld - NXGE_MAC_LD_START)) & LDSV_MASK_ALL);
104444961713Sgirish 		} else {
104544961713Sgirish 			*flag_p = (((sv >> LDSV2_LDF0_SHIFT) >>
104644961713Sgirish 				(ld - NXGE_MAC_LD_START)) & LDSV_MASK_ALL);
104744961713Sgirish 		}
104844961713Sgirish 	}
104944961713Sgirish 
105044961713Sgirish 	return (NPI_SUCCESS);
105144961713Sgirish }
105244961713Sgirish 
105344961713Sgirish /*
105444961713Sgirish  * npi_ldsv_ld_ldf0_get():
105544961713Sgirish  *	This function is called to get the ldf0 bit value of a device.
105644961713Sgirish  * Parameters:
105744961713Sgirish  *	handle		- NPI handle
105844961713Sgirish  *	ldg		- logical device group (0 - 63)
105944961713Sgirish  *	ld		- logical device (0 - 68)
106044961713Sgirish  *	*ldf_p		- pointer to store its flag bits.
106144961713Sgirish  * Return:
106244961713Sgirish  *	NPI_SUCCESS	-
106344961713Sgirish  *	Error:
106444961713Sgirish  *	NPI_FAILURE
106544961713Sgirish  */
1066a3c5bd6dSspeer 
106744961713Sgirish npi_status_t
106844961713Sgirish npi_ldsv_ld_ldf0_get(npi_handle_t handle, uint8_t ldg, uint8_t ld,
1069a3c5bd6dSspeer 	boolean_t *flag_p)
107044961713Sgirish {
107144961713Sgirish 	ldsv_type_t vector;
107244961713Sgirish 
107344961713Sgirish 	if (ld >= NXGE_MAC_LD_START) {
107444961713Sgirish 		vector = VECTOR2;
107544961713Sgirish 	}
107644961713Sgirish 
107744961713Sgirish 	return (npi_ldsv_ld_get(handle, ldg, ld, vector, LDF0, flag_p));
107844961713Sgirish }
107944961713Sgirish 
108044961713Sgirish /*
108144961713Sgirish  * npi_ldsv_ld_ldf1_get():
108244961713Sgirish  *	This function is called to get the ldf1 bit value of a device.
108344961713Sgirish  * Parameters:
108444961713Sgirish  *	handle		- NPI handle
108544961713Sgirish  *	ldg		- logical device group (0 - 63)
108644961713Sgirish  *	ld		- logical device (0 - 68)
108744961713Sgirish  *	*ldf_p		- pointer to store its flag bits.
108844961713Sgirish  * Return:
108944961713Sgirish  *	NPI_SUCCESS	-
109044961713Sgirish  *	Error:
109144961713Sgirish  *	NPI_FAILURE
109244961713Sgirish  */
1093a3c5bd6dSspeer 
109444961713Sgirish npi_status_t
109544961713Sgirish npi_ldsv_ld_ldf1_get(npi_handle_t handle, uint8_t ldg, uint8_t ld,
109644961713Sgirish 		boolean_t *flag_p)
109744961713Sgirish {
109844961713Sgirish 	ldsv_type_t vector;
109944961713Sgirish 
110044961713Sgirish 	if (ld >= NXGE_MAC_LD_START) {
110144961713Sgirish 		vector = VECTOR2;
110244961713Sgirish 	}
110344961713Sgirish 
110444961713Sgirish 	return (npi_ldsv_ld_get(handle, ldg, ld, vector, LDF1, flag_p));
110544961713Sgirish }
110644961713Sgirish 
110744961713Sgirish /*
110844961713Sgirish  * npi_intr_mask_set():
110944961713Sgirish  *	This function is called to select the mask bits for both ldf0 and ldf1.
111044961713Sgirish  * Parameters:
111144961713Sgirish  *	handle		- NPI handle
111244961713Sgirish  *	ld		- logical device (0 - 68)
111344961713Sgirish  *	ldf_mask	- mask value to set (both ldf0 and ldf1).
111444961713Sgirish  * Return:
111544961713Sgirish  *	NPI_SUCCESS	-
111644961713Sgirish  *	Error:
111744961713Sgirish  *	NPI_FAILURE
111844961713Sgirish  */
1119a3c5bd6dSspeer 
112044961713Sgirish npi_status_t
112144961713Sgirish npi_intr_mask_set(npi_handle_t handle, uint8_t ld, uint8_t ldf_mask)
112244961713Sgirish {
112344961713Sgirish 	uint64_t		offset;
112444961713Sgirish 
1125a3c5bd6dSspeer 	ASSERT(LD_VALID(ld));
112644961713Sgirish 	if (!LD_VALID(ld)) {
112744961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
112844961713Sgirish 			    " npi_intr_mask_set ld", ld));
112944961713Sgirish 		return (NPI_FAILURE | NPI_VIR_LD_INVALID(ld));
113044961713Sgirish 	}
113144961713Sgirish 
113244961713Sgirish 	ldf_mask &= LD_IM0_MASK;
113344961713Sgirish 	offset = LDSV_OFFSET_MASK(ld);
113444961713Sgirish 
113544961713Sgirish 	NPI_DEBUG_MSG((handle.function, NPI_VIR_CTL,
113644961713Sgirish 		"npi_intr_mask_set: ld %d "
113744961713Sgirish 		" offset 0x%0llx "
113844961713Sgirish 		" mask 0x%x",
113944961713Sgirish 		ld, offset, ldf_mask));
114044961713Sgirish 
114144961713Sgirish 	NXGE_REG_WR64(handle, offset, (uint64_t)ldf_mask);
114244961713Sgirish 
114344961713Sgirish 	return (NPI_SUCCESS);
114444961713Sgirish }
114544961713Sgirish 
114644961713Sgirish /*
114744961713Sgirish  * npi_intr_mask_get():
114844961713Sgirish  *	This function is called to get the mask bits.
114944961713Sgirish  * Parameters:
115044961713Sgirish  *	handle		- NPI handle
115144961713Sgirish  *	ld		- logical device (0 - 68)
115244961713Sgirish  *	ldf_mask	- pointer to store mask bits info.
115344961713Sgirish  * Return:
115444961713Sgirish  *	NPI_SUCCESS	-
115544961713Sgirish  *	Error:
115644961713Sgirish  *	NPI_FAILURE
115744961713Sgirish  */
115844961713Sgirish npi_status_t
115944961713Sgirish npi_intr_mask_get(npi_handle_t handle, uint8_t ld, uint8_t *ldf_mask_p)
116044961713Sgirish {
116144961713Sgirish 	uint64_t		offset;
116244961713Sgirish 	uint64_t		val;
116344961713Sgirish 
1164a3c5bd6dSspeer 	ASSERT(LD_VALID(ld));
116544961713Sgirish 	if (!LD_VALID(ld)) {
116644961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
116744961713Sgirish 			    " npi_intr_mask_get ld", ld));
116844961713Sgirish 		return (NPI_FAILURE | NPI_VIR_LD_INVALID(ld));
116944961713Sgirish 	}
117044961713Sgirish 
117144961713Sgirish 	offset = LDSV_OFFSET_MASK(ld);
117244961713Sgirish 
117344961713Sgirish 	NXGE_REG_RD64(handle, offset, &val);
117444961713Sgirish 
117544961713Sgirish 	*ldf_mask_p = (uint8_t)(val & LD_IM_MASK);
117644961713Sgirish 
117744961713Sgirish 	return (NPI_SUCCESS);
117844961713Sgirish }
117944961713Sgirish 
118044961713Sgirish /*
118144961713Sgirish  * npi_intr_ldg_mgmt_set():
118244961713Sgirish  *	This function is called to set interrupt timer and arm bit.
118344961713Sgirish  * Parameters:
118444961713Sgirish  *	handle		- NPI handle
118544961713Sgirish  *	ldg		- logical device group (0 - 63)
118644961713Sgirish  *	arm		- B_TRUE (arm) B_FALSE (disable)
118744961713Sgirish  * Return:
118844961713Sgirish  *	NPI_SUCCESS	-
118944961713Sgirish  *	Error:
119044961713Sgirish  *	NPI_FAILURE
119144961713Sgirish  */
1192a3c5bd6dSspeer 
119344961713Sgirish npi_status_t
119444961713Sgirish npi_intr_ldg_mgmt_set(npi_handle_t handle, uint8_t ldg, boolean_t arm,
119544961713Sgirish 			uint8_t timer)
119644961713Sgirish {
119744961713Sgirish 	ldgimgm_t		mgm;
119844961713Sgirish 	uint64_t		val;
119944961713Sgirish 
1200a3c5bd6dSspeer 	ASSERT((LDG_VALID(ldg)) && (LD_INTTIMER_VALID(timer)));
120144961713Sgirish 	if (!LDG_VALID(ldg)) {
120244961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
120344961713Sgirish 				    " npi_intr_ldg_mgmt_set"
120444961713Sgirish 				    " Invalid Input: "
120544961713Sgirish 				    " ldg <0x%x>", ldg));
120644961713Sgirish 		return (NPI_FAILURE | NPI_VIR_LDG_INVALID(ldg));
120744961713Sgirish 	}
120844961713Sgirish 	if (!LD_INTTIMER_VALID(timer)) {
120944961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
121044961713Sgirish 				    " npi_intr_ldg_mgmt_set Invalid Input"
121144961713Sgirish 				    " timer <0x%x>", timer));
121244961713Sgirish 		return (NPI_FAILURE | NPI_VIR_INTM_TM_INVALID(ldg));
121344961713Sgirish 	}
121444961713Sgirish 
121544961713Sgirish 	if (arm) {
121644961713Sgirish 		mgm.bits.ldw.arm = 1;
121744961713Sgirish 	} else {
121844961713Sgirish 		NXGE_REG_RD64(handle, LDGIMGN_REG + LDSV_OFFSET(ldg), &val);
121944961713Sgirish 		mgm.value = val & LDGIMGM_ARM_MASK;
122044961713Sgirish 	}
122144961713Sgirish 
122244961713Sgirish 	mgm.bits.ldw.timer = timer;
122344961713Sgirish 	NXGE_REG_WR64(handle, LDGIMGN_REG + LDSV_OFFSET(ldg),
122444961713Sgirish 		mgm.value);
122544961713Sgirish 
122644961713Sgirish 	NPI_DEBUG_MSG((handle.function, NPI_VIR_CTL,
122744961713Sgirish 		" npi_intr_ldg_mgmt_set: ldg %d"
122844961713Sgirish 		" reg offset 0x%x",
122944961713Sgirish 		ldg, LDGIMGN_REG + LDSV_OFFSET(ldg)));
123044961713Sgirish 
123144961713Sgirish 	return (NPI_SUCCESS);
123244961713Sgirish }
123344961713Sgirish 
123444961713Sgirish /*
123544961713Sgirish  * npi_intr_ldg_mgmt_timer_get():
123644961713Sgirish  *	This function is called to get the timer counter
123744961713Sgirish  * Parameters:
123844961713Sgirish  *	handle		- NPI handle
123944961713Sgirish  *	ldg		- logical device group (0 - 63)
124044961713Sgirish  *	timer_p		- pointer to store the timer counter.
124144961713Sgirish  * Return:
124244961713Sgirish  *	NPI_SUCCESS	-
124344961713Sgirish  *	Error:
124444961713Sgirish  *	NPI_FAILURE
124544961713Sgirish  */
1246a3c5bd6dSspeer 
124744961713Sgirish npi_status_t
124844961713Sgirish npi_intr_ldg_mgmt_timer_get(npi_handle_t handle, uint8_t ldg, uint8_t *timer_p)
124944961713Sgirish {
125044961713Sgirish 	uint64_t val;
125144961713Sgirish 
1252a3c5bd6dSspeer 	ASSERT(LDG_VALID(ldg));
125344961713Sgirish 	if (!LDG_VALID(ldg)) {
125444961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
125544961713Sgirish 				    " npi_intr_ldg_mgmt_timer_get"
125644961713Sgirish 				    " Invalid Input: ldg <0x%x>", ldg));
125744961713Sgirish 		return (NPI_FAILURE | NPI_VIR_LDG_INVALID(ldg));
125844961713Sgirish 	}
125944961713Sgirish 
126044961713Sgirish 	NXGE_REG_RD64(handle, LDGIMGN_REG + LDSV_OFFSET(ldg), &val);
126144961713Sgirish 
126244961713Sgirish 	*timer_p = (uint8_t)(val & LDGIMGM_TIMER_MASK);
126344961713Sgirish 
126444961713Sgirish 	NPI_DEBUG_MSG((handle.function, NPI_VIR_CTL,
126544961713Sgirish 		" npi_intr_ldg_mgmt_timer_get: ldg %d"
126644961713Sgirish 		" reg offset 0x%x",
126744961713Sgirish 		ldg, LDGIMGN_REG + LDSV_OFFSET(ldg)));
126844961713Sgirish 
126944961713Sgirish 	return (NPI_SUCCESS);
127044961713Sgirish }
127144961713Sgirish 
127244961713Sgirish /*
127344961713Sgirish  * npi_intr_ldg_mgmt_arm():
127444961713Sgirish  *	This function is called to arm the group.
127544961713Sgirish  * Parameters:
127644961713Sgirish  *	handle		- NPI handle
127744961713Sgirish  *	ldg		- logical device group (0 - 63)
127844961713Sgirish  * Return:
127944961713Sgirish  *	NPI_SUCCESS	-
128044961713Sgirish  *	Error:
128144961713Sgirish  *	NPI_FAILURE
128244961713Sgirish  */
1283a3c5bd6dSspeer 
128444961713Sgirish npi_status_t
128544961713Sgirish npi_intr_ldg_mgmt_arm(npi_handle_t handle, uint8_t ldg)
128644961713Sgirish {
128744961713Sgirish 	ldgimgm_t		mgm;
128844961713Sgirish 
1289a3c5bd6dSspeer 	ASSERT(LDG_VALID(ldg));
129044961713Sgirish 	if (!LDG_VALID(ldg)) {
129144961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
129244961713Sgirish 				    " npi_intr_ldg_mgmt_arm"
129344961713Sgirish 				    " Invalid Input: ldg <0x%x>",
129444961713Sgirish 				    ldg));
129544961713Sgirish 		return (NPI_FAILURE | NPI_VIR_LDG_INVALID(ldg));
129644961713Sgirish 	}
129744961713Sgirish 
129844961713Sgirish 	NXGE_REG_RD64(handle, (LDGIMGN_REG + LDSV_OFFSET(ldg)), &mgm.value);
129944961713Sgirish 	mgm.bits.ldw.arm = 1;
130044961713Sgirish 
130144961713Sgirish 	NXGE_REG_WR64(handle, LDGIMGN_REG + LDSV_OFFSET(ldg),
130244961713Sgirish 			mgm.value);
130344961713Sgirish 	NPI_DEBUG_MSG((handle.function, NPI_VIR_CTL,
130444961713Sgirish 		" npi_intr_ldg_mgmt_arm: ldg %d"
130544961713Sgirish 		" reg offset 0x%x",
130644961713Sgirish 		ldg, LDGIMGN_REG + LDSV_OFFSET(ldg)));
130744961713Sgirish 
130844961713Sgirish 	return (NPI_SUCCESS);
130944961713Sgirish }
131044961713Sgirish 
131144961713Sgirish /*
131244961713Sgirish  * npi_fzc_ldg_timer_res_set():
131344961713Sgirish  *	This function is called to set the timer resolution.
131444961713Sgirish  * Parameters:
131544961713Sgirish  *	handle		- NPI handle
131644961713Sgirish  *	res		- timer resolution (# of system clocks)
131744961713Sgirish  * Return:
131844961713Sgirish  *	NPI_SUCCESS	-
131944961713Sgirish  *	Error:
132044961713Sgirish  *	NPI_FAILURE
132144961713Sgirish  */
1322a3c5bd6dSspeer 
132344961713Sgirish npi_status_t
132444961713Sgirish npi_fzc_ldg_timer_res_set(npi_handle_t handle, uint32_t res)
132544961713Sgirish {
1326a3c5bd6dSspeer 	ASSERT(res <= LDGTITMRES_RES_MASK);
132744961713Sgirish 	if (res > LDGTITMRES_RES_MASK) {
132844961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
132944961713Sgirish 				    " npi_fzc_ldg_timer_res_set"
133044961713Sgirish 				    " Invalid Input: res <0x%x>",
133144961713Sgirish 				    res));
133244961713Sgirish 		return (NPI_FAILURE | NPI_VIR_TM_RES_INVALID);
133344961713Sgirish 	}
133444961713Sgirish 
133544961713Sgirish 	NXGE_REG_WR64(handle, LDGITMRES_REG, (res & LDGTITMRES_RES_MASK));
133644961713Sgirish 
133744961713Sgirish 	return (NPI_SUCCESS);
133844961713Sgirish }
133944961713Sgirish 
134044961713Sgirish /*
134144961713Sgirish  * npi_fzc_ldg_timer_res_get():
134244961713Sgirish  *	This function is called to get the timer resolution.
134344961713Sgirish  * Parameters:
134444961713Sgirish  *	handle		- NPI handle
134544961713Sgirish  *	res_p		- pointer to store the timer resolution.
134644961713Sgirish  * Return:
134744961713Sgirish  *	NPI_SUCCESS	-
134844961713Sgirish  *	Error:
134944961713Sgirish  *	NPI_FAILURE
135044961713Sgirish  */
1351a3c5bd6dSspeer 
135244961713Sgirish npi_status_t
135344961713Sgirish npi_fzc_ldg_timer_res_get(npi_handle_t handle, uint8_t *res_p)
135444961713Sgirish {
135544961713Sgirish 	uint64_t val;
135644961713Sgirish 
135744961713Sgirish 	NXGE_REG_RD64(handle, LDGITMRES_REG, &val);
135844961713Sgirish 
135944961713Sgirish 	*res_p = (uint8_t)(val & LDGIMGM_TIMER_MASK);
136044961713Sgirish 
136144961713Sgirish 	return (NPI_SUCCESS);
136244961713Sgirish }
136344961713Sgirish 
136444961713Sgirish /*
136544961713Sgirish  * npi_fzc_sid_set():
136644961713Sgirish  *	This function is called to set the system interrupt data.
136744961713Sgirish  * Parameters:
136844961713Sgirish  *	handle		- NPI handle
136944961713Sgirish  *	ldg		- logical group (0 - 63)
137044961713Sgirish  *	sid		- NPI defined data to set
137144961713Sgirish  * Return:
137244961713Sgirish  *	NPI_SUCCESS	-
137344961713Sgirish  *	Error:
137444961713Sgirish  *	NPI_FAILURE
137544961713Sgirish  */
1376a3c5bd6dSspeer 
137744961713Sgirish npi_status_t
137844961713Sgirish npi_fzc_sid_set(npi_handle_t handle, fzc_sid_t sid)
137944961713Sgirish {
138044961713Sgirish 	sid_t		sd;
138144961713Sgirish 
1382a3c5bd6dSspeer 	ASSERT(LDG_VALID(sid.ldg));
138344961713Sgirish 	if (!LDG_VALID(sid.ldg)) {
138444961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
138544961713Sgirish 				    " npi_fzc_sid_set"
138644961713Sgirish 				    " Invalid Input: ldg <0x%x>",
138744961713Sgirish 				    sid.ldg));
138844961713Sgirish 		return (NPI_FAILURE | NPI_VIR_LDG_INVALID(sid.ldg));
138944961713Sgirish 	}
139044961713Sgirish 	if (!sid.niu) {
1391a3c5bd6dSspeer 		ASSERT(FUNC_VALID(sid.func));
139244961713Sgirish 		if (!FUNC_VALID(sid.func)) {
139344961713Sgirish 			NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
139444961713Sgirish 					    " npi_fzc_sid_set"
139544961713Sgirish 					    " Invalid Input: func <0x%x>",
139644961713Sgirish 					    sid.func));
139744961713Sgirish 			NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
1398a3c5bd6dSspeer 				"invalid FUNC: npi_fzc_sid_set(%d)", sid.func));
139944961713Sgirish 			return (NPI_FAILURE | NPI_VIR_FUNC_INVALID(sid.func));
140044961713Sgirish 		}
140144961713Sgirish 
1402a3c5bd6dSspeer 		ASSERT(SID_VECTOR_VALID(sid.vector));
140344961713Sgirish 		if (!SID_VECTOR_VALID(sid.vector)) {
140444961713Sgirish 			NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
140544961713Sgirish 					    " npi_fzc_sid_set"
140644961713Sgirish 					    " Invalid Input: vector <0x%x>",
140744961713Sgirish 					    sid.vector));
140844961713Sgirish 			NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
140944961713Sgirish 				    " invalid VECTOR: npi_fzc_sid_set(%d)",
141044961713Sgirish 				    sid.vector));
141144961713Sgirish 			return (NPI_FAILURE |
141244961713Sgirish 				NPI_VIR_SID_VEC_INVALID(sid.vector));
141344961713Sgirish 		}
141444961713Sgirish 	}
141544961713Sgirish 	sd.value = 0;
141644961713Sgirish 	if (!sid.niu) {
141744961713Sgirish 		sd.bits.ldw.data = ((sid.func << SID_DATA_FUNCNUM_SHIFT) |
141844961713Sgirish 				(sid.vector & SID_DATA_INTNUM_MASK));
141944961713Sgirish 	}
1420a3c5bd6dSspeer 
1421*56d930aeSspeer 	NPI_DEBUG_MSG((handle.function, NPI_VIR_CTL,
1422a3c5bd6dSspeer 	    " npi_fzc_sid_set: group %d 0x%llx", sid.ldg, sd.value));
142344961713Sgirish 
142444961713Sgirish 	NXGE_REG_WR64(handle,  SID_REG + LDG_SID_OFFSET(sid.ldg), sd.value);
142544961713Sgirish 
142644961713Sgirish 	return (NPI_SUCCESS);
142744961713Sgirish }
142844961713Sgirish 
142944961713Sgirish /*
143044961713Sgirish  * npi_fzc_sid_get():
143144961713Sgirish  *	This function is called to get the system interrupt data.
143244961713Sgirish  * Parameters:
143344961713Sgirish  *	handle		- NPI handle
143444961713Sgirish  *	ldg		- logical group (0 - 63)
143544961713Sgirish  *	sid_p		- NPI defined data to get
143644961713Sgirish  * Return:
143744961713Sgirish  *	NPI_SUCCESS	-
143844961713Sgirish  *	Error:
143944961713Sgirish  *	NPI_FAILURE
144044961713Sgirish  */
1441a3c5bd6dSspeer 
144244961713Sgirish npi_status_t
144344961713Sgirish npi_fzc_sid_get(npi_handle_t handle, p_fzc_sid_t sid_p)
144444961713Sgirish {
144544961713Sgirish 	sid_t		sd;
144644961713Sgirish 
1447a3c5bd6dSspeer 	ASSERT(LDG_VALID(sid_p->ldg));
144844961713Sgirish 	if (!LDG_VALID(sid_p->ldg)) {
144944961713Sgirish 		NPI_ERROR_MSG((handle.function, NPI_ERR_CTL,
145044961713Sgirish 				    " npi_fzc_sid_get"
145144961713Sgirish 				    " Invalid Input: ldg <0x%x>",
145244961713Sgirish 				    sid_p->ldg));
145344961713Sgirish 		return (NPI_FAILURE | NPI_VIR_LDG_INVALID(sid_p->ldg));
145444961713Sgirish 	}
145544961713Sgirish 	NXGE_REG_RD64(handle, (SID_REG + LDG_SID_OFFSET(sid_p->ldg)),
145644961713Sgirish 		&sd.value);
145744961713Sgirish 	if (!sid_p->niu) {
145844961713Sgirish 		sid_p->func = ((sd.bits.ldw.data & SID_DATA_FUNCNUM_MASK) >>
145944961713Sgirish 			SID_DATA_FUNCNUM_SHIFT);
146044961713Sgirish 		sid_p->vector = ((sd.bits.ldw.data & SID_DATA_INTNUM_MASK) >>
146144961713Sgirish 			SID_DATA_INTNUM_SHIFT);
146244961713Sgirish 	} else {
146344961713Sgirish 		sid_p->vector = (sd.value & SID_DATA_MASK);
146444961713Sgirish 	}
146544961713Sgirish 
146644961713Sgirish 	return (NPI_SUCCESS);
146744961713Sgirish }
146844961713Sgirish 
146944961713Sgirish /*
147044961713Sgirish  * npi_fzc_sys_err_mask_set():
147144961713Sgirish  *	This function is called to mask/unmask the device error mask bits.
147244961713Sgirish  *
147344961713Sgirish  * Parameters:
147444961713Sgirish  *	handle		- NPI handle
147544961713Sgirish  *	mask		- set bit mapped mask
147644961713Sgirish  * Return:
147744961713Sgirish  *	NPI_SUCCESS	-
147844961713Sgirish  *	Error:
147944961713Sgirish  *	NPI_FAILURE
148044961713Sgirish  */
1481a3c5bd6dSspeer 
148244961713Sgirish npi_status_t
148344961713Sgirish npi_fzc_sys_err_mask_set(npi_handle_t handle, uint64_t mask)
148444961713Sgirish {
148544961713Sgirish 	NXGE_REG_WR64(handle,  SYS_ERR_MASK_REG, mask);
148644961713Sgirish 	return (NPI_SUCCESS);
148744961713Sgirish }
148844961713Sgirish 
148944961713Sgirish /*
149044961713Sgirish  * npi_fzc_sys_err_stat_get():
149144961713Sgirish  *	This function is called to get the system error stats.
149244961713Sgirish  *
149344961713Sgirish  * Parameters:
149444961713Sgirish  *	handle		- NPI handle
149544961713Sgirish  *	err_stat	- sys_err_stat structure to hold stats.
149644961713Sgirish  * Return:
149744961713Sgirish  *	NPI_SUCCESS	-
149844961713Sgirish  *	Error:
149944961713Sgirish  *	NPI_FAILURE
150044961713Sgirish  */
1501a3c5bd6dSspeer 
150244961713Sgirish npi_status_t
150344961713Sgirish npi_fzc_sys_err_stat_get(npi_handle_t handle, p_sys_err_stat_t statp)
150444961713Sgirish {
150544961713Sgirish 	NXGE_REG_RD64(handle,  SYS_ERR_STAT_REG, &statp->value);
150644961713Sgirish 	return (NPI_SUCCESS);
150744961713Sgirish }
150844961713Sgirish 
150944961713Sgirish npi_status_t
151044961713Sgirish npi_fzc_rst_ctl_get(npi_handle_t handle, p_rst_ctl_t rstp)
151144961713Sgirish {
151244961713Sgirish 	NXGE_REG_RD64(handle, RST_CTL_REG, &rstp->value);
151344961713Sgirish 
151444961713Sgirish 	return (NPI_SUCCESS);
151544961713Sgirish }
151644961713Sgirish 
151744961713Sgirish /*
151844961713Sgirish  * npi_fzc_mpc_get():
151944961713Sgirish  *	This function is called to get the access mode.
152044961713Sgirish  * Parameters:
152144961713Sgirish  *	handle		- NPI handle
152244961713Sgirish  * Return:
152344961713Sgirish  *	NPI_SUCCESS	-
152444961713Sgirish  *
152544961713Sgirish  */
1526a3c5bd6dSspeer 
152744961713Sgirish npi_status_t
152844961713Sgirish npi_fzc_rst_ctl_reset_mac(npi_handle_t handle, uint8_t port)
152944961713Sgirish {
153044961713Sgirish 	rst_ctl_t 		rst;
153144961713Sgirish 
153244961713Sgirish 	rst.value = 0;
153344961713Sgirish 	NXGE_REG_RD64(handle, RST_CTL_REG, &rst.value);
153444961713Sgirish 	rst.value |= (1 << (RST_CTL_MAC_RST0_SHIFT + port));
153544961713Sgirish 	NXGE_REG_WR64(handle, RST_CTL_REG, rst.value);
153644961713Sgirish 
153744961713Sgirish 	return (NPI_SUCCESS);
153844961713Sgirish }
1539