xref: /onnv-gate/usr/src/uts/common/io/fibre-channel/fca/qlc/ql_mbx.c (revision 12279:f13874aa8143)
17836SJohn.Forte@Sun.COM /*
27836SJohn.Forte@Sun.COM  * CDDL HEADER START
37836SJohn.Forte@Sun.COM  *
47836SJohn.Forte@Sun.COM  * The contents of this file are subject to the terms of the
57836SJohn.Forte@Sun.COM  * Common Development and Distribution License (the "License").
67836SJohn.Forte@Sun.COM  * You may not use this file except in compliance with the License.
77836SJohn.Forte@Sun.COM  *
87836SJohn.Forte@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97836SJohn.Forte@Sun.COM  * or http://www.opensolaris.org/os/licensing.
107836SJohn.Forte@Sun.COM  * See the License for the specific language governing permissions
117836SJohn.Forte@Sun.COM  * and limitations under the License.
127836SJohn.Forte@Sun.COM  *
137836SJohn.Forte@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
147836SJohn.Forte@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157836SJohn.Forte@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
167836SJohn.Forte@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
177836SJohn.Forte@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
187836SJohn.Forte@Sun.COM  *
197836SJohn.Forte@Sun.COM  * CDDL HEADER END
207836SJohn.Forte@Sun.COM  */
217836SJohn.Forte@Sun.COM 
2211541SDaniel.Beauregard@Sun.COM /* Copyright 2010 QLogic Corporation */
237836SJohn.Forte@Sun.COM 
247836SJohn.Forte@Sun.COM /*
25*12279SDaniel.Beauregard@Sun.COM  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
267836SJohn.Forte@Sun.COM  */
277836SJohn.Forte@Sun.COM 
2811541SDaniel.Beauregard@Sun.COM #pragma ident	"Copyright 2010 QLogic Corporation; ql_mbx.c"
297836SJohn.Forte@Sun.COM 
307836SJohn.Forte@Sun.COM /*
317836SJohn.Forte@Sun.COM  * ISP2xxx Solaris Fibre Channel Adapter (FCA) driver source file.
327836SJohn.Forte@Sun.COM  *
337836SJohn.Forte@Sun.COM  * ***********************************************************************
347836SJohn.Forte@Sun.COM  * *									**
357836SJohn.Forte@Sun.COM  * *				NOTICE					**
3611541SDaniel.Beauregard@Sun.COM  * *		COPYRIGHT (C) 1996-2010 QLOGIC CORPORATION		**
377836SJohn.Forte@Sun.COM  * *			ALL RIGHTS RESERVED				**
387836SJohn.Forte@Sun.COM  * *									**
397836SJohn.Forte@Sun.COM  * ***********************************************************************
407836SJohn.Forte@Sun.COM  *
417836SJohn.Forte@Sun.COM  */
427836SJohn.Forte@Sun.COM 
437836SJohn.Forte@Sun.COM #include <ql_apps.h>
447836SJohn.Forte@Sun.COM #include <ql_api.h>
457836SJohn.Forte@Sun.COM #include <ql_debug.h>
467836SJohn.Forte@Sun.COM #include <ql_iocb.h>
477836SJohn.Forte@Sun.COM #include <ql_isr.h>
487836SJohn.Forte@Sun.COM #include <ql_mbx.h>
497836SJohn.Forte@Sun.COM #include <ql_xioctl.h>
507836SJohn.Forte@Sun.COM 
517836SJohn.Forte@Sun.COM /*
527836SJohn.Forte@Sun.COM  * Local data
537836SJohn.Forte@Sun.COM  */
547836SJohn.Forte@Sun.COM 
557836SJohn.Forte@Sun.COM /*
567836SJohn.Forte@Sun.COM  * Local prototypes
577836SJohn.Forte@Sun.COM  */
587836SJohn.Forte@Sun.COM static int ql_mailbox_command(ql_adapter_state_t *, mbx_cmd_t *);
597836SJohn.Forte@Sun.COM static int ql_task_mgmt_iocb(ql_adapter_state_t *, ql_tgt_t *, uint16_t,
607836SJohn.Forte@Sun.COM     uint32_t, uint16_t);
617836SJohn.Forte@Sun.COM static int ql_abort_cmd_iocb(ql_adapter_state_t *, ql_srb_t *);
627836SJohn.Forte@Sun.COM static int ql_setup_mbox_dma_transfer(ql_adapter_state_t *, dma_mem_t *,
637836SJohn.Forte@Sun.COM     caddr_t, uint32_t);
647836SJohn.Forte@Sun.COM static int ql_setup_mbox_dma_resources(ql_adapter_state_t *, dma_mem_t *,
657836SJohn.Forte@Sun.COM     uint32_t);
667836SJohn.Forte@Sun.COM static void ql_setup_mbox_dma_data(dma_mem_t *, caddr_t);
677836SJohn.Forte@Sun.COM static void ql_get_mbox_dma_data(dma_mem_t *, caddr_t);
687836SJohn.Forte@Sun.COM 
697836SJohn.Forte@Sun.COM /*
707836SJohn.Forte@Sun.COM  * ql_mailbox_command
717836SJohn.Forte@Sun.COM  *	Issue mailbox command and waits for completion.
727836SJohn.Forte@Sun.COM  *
737836SJohn.Forte@Sun.COM  * Input:
747836SJohn.Forte@Sun.COM  *	ha = adapter state pointer.
757836SJohn.Forte@Sun.COM  *	mcp = mailbox command parameter structure pointer.
767836SJohn.Forte@Sun.COM  *
777836SJohn.Forte@Sun.COM  * Returns:
787836SJohn.Forte@Sun.COM  *	ql local function return status code.
797836SJohn.Forte@Sun.COM  *
807836SJohn.Forte@Sun.COM  * Context:
817836SJohn.Forte@Sun.COM  *	Kernel context.
827836SJohn.Forte@Sun.COM  */
837836SJohn.Forte@Sun.COM static int
ql_mailbox_command(ql_adapter_state_t * vha,mbx_cmd_t * mcp)847836SJohn.Forte@Sun.COM ql_mailbox_command(ql_adapter_state_t *vha, mbx_cmd_t *mcp)
857836SJohn.Forte@Sun.COM {
867836SJohn.Forte@Sun.COM 	uint16_t		cnt;
877836SJohn.Forte@Sun.COM 	uint32_t		data;
887836SJohn.Forte@Sun.COM 	clock_t			timer, cv_stat;
897836SJohn.Forte@Sun.COM 	int			rval;
907836SJohn.Forte@Sun.COM 	uint32_t		set_flags = 0;
917836SJohn.Forte@Sun.COM 	uint32_t		reset_flags = 0;
927836SJohn.Forte@Sun.COM 	ql_adapter_state_t	*ha = vha->pha;
939156SDaniel.Beauregard@Sun.COM 	int			mbx_cmd = mcp->mb[0];
947836SJohn.Forte@Sun.COM 
95*12279SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started, cmd=%xh\n", ha->instance, mbx_cmd);
967836SJohn.Forte@Sun.COM 
977836SJohn.Forte@Sun.COM 	/* Acquire mailbox register lock. */
987836SJohn.Forte@Sun.COM 	MBX_REGISTER_LOCK(ha);
997836SJohn.Forte@Sun.COM 
1007836SJohn.Forte@Sun.COM 	/* Check for mailbox available, if not wait for signal. */
10111924SDaniel.Beauregard@Sun.COM 	while (ha->mailbox_flags & MBX_BUSY_FLG ||
10211924SDaniel.Beauregard@Sun.COM 	    (CFG_IST(ha, CFG_CTRL_8021) &&
10311924SDaniel.Beauregard@Sun.COM 	    RD32_IO_REG(ha, nx_host_int) & NX_MBX_CMD)) {
1047836SJohn.Forte@Sun.COM 		ha->mailbox_flags = (uint8_t)
1057836SJohn.Forte@Sun.COM 		    (ha->mailbox_flags | MBX_WANT_FLG);
1067836SJohn.Forte@Sun.COM 
1077836SJohn.Forte@Sun.COM 		if (ha->task_daemon_flags & TASK_DAEMON_POWERING_DOWN) {
1087836SJohn.Forte@Sun.COM 			EL(vha, "failed availability cmd=%xh\n", mcp->mb[0]);
1097836SJohn.Forte@Sun.COM 			MBX_REGISTER_UNLOCK(ha);
1107836SJohn.Forte@Sun.COM 			return (QL_LOCK_TIMEOUT);
1117836SJohn.Forte@Sun.COM 		}
1127836SJohn.Forte@Sun.COM 
1137836SJohn.Forte@Sun.COM 		/* Set timeout after command that is running. */
11411066Srafael.vanoni@sun.com 		timer = (mcp->timeout + 20) * drv_usectohz(1000000);
11511066Srafael.vanoni@sun.com 		cv_stat = cv_reltimedwait_sig(&ha->cv_mbx_wait,
11611066Srafael.vanoni@sun.com 		    &ha->pha->mbx_mutex, timer, TR_CLOCK_TICK);
1177836SJohn.Forte@Sun.COM 		if (cv_stat == -1 || cv_stat == 0) {
1187836SJohn.Forte@Sun.COM 			/*
1197836SJohn.Forte@Sun.COM 			 * The timeout time 'timer' was
1207836SJohn.Forte@Sun.COM 			 * reached without the condition
1217836SJohn.Forte@Sun.COM 			 * being signaled.
1227836SJohn.Forte@Sun.COM 			 */
1237836SJohn.Forte@Sun.COM 			ha->mailbox_flags = (uint8_t)(ha->mailbox_flags &
1247836SJohn.Forte@Sun.COM 			    ~MBX_WANT_FLG);
1257836SJohn.Forte@Sun.COM 			cv_broadcast(&ha->cv_mbx_wait);
1267836SJohn.Forte@Sun.COM 
1277836SJohn.Forte@Sun.COM 			/* Release mailbox register lock. */
1287836SJohn.Forte@Sun.COM 			MBX_REGISTER_UNLOCK(ha);
1297836SJohn.Forte@Sun.COM 
1307836SJohn.Forte@Sun.COM 			if (cv_stat == 0) {
1317836SJohn.Forte@Sun.COM 				EL(vha, "waiting for availability aborted, "
1327836SJohn.Forte@Sun.COM 				    "cmd=%xh\n", mcp->mb[0]);
1337836SJohn.Forte@Sun.COM 				return (QL_ABORTED);
1347836SJohn.Forte@Sun.COM 			}
1357836SJohn.Forte@Sun.COM 			EL(vha, "failed availability cmd=%xh\n", mcp->mb[0]);
1367836SJohn.Forte@Sun.COM 			return (QL_LOCK_TIMEOUT);
1377836SJohn.Forte@Sun.COM 		}
1387836SJohn.Forte@Sun.COM 	}
1397836SJohn.Forte@Sun.COM 
1407836SJohn.Forte@Sun.COM 	ha->mailbox_flags = (uint8_t)(ha->mailbox_flags | MBX_BUSY_FLG);
1417836SJohn.Forte@Sun.COM 
1427836SJohn.Forte@Sun.COM 	/* Structure pointer for return mailbox registers. */
1437836SJohn.Forte@Sun.COM 	ha->mcp = mcp;
1447836SJohn.Forte@Sun.COM 
1457836SJohn.Forte@Sun.COM 	/* Load mailbox registers. */
1467836SJohn.Forte@Sun.COM 	data = mcp->out_mb;
1477836SJohn.Forte@Sun.COM 	for (cnt = 0; cnt < ha->reg_off->mbox_cnt && data; cnt++) {
1487836SJohn.Forte@Sun.COM 		if (data & MBX_0) {
14911924SDaniel.Beauregard@Sun.COM 			WRT16_IO_REG(ha, mailbox_in[cnt], mcp->mb[cnt]);
1507836SJohn.Forte@Sun.COM 		}
1517836SJohn.Forte@Sun.COM 		data >>= 1;
1527836SJohn.Forte@Sun.COM 	}
1537836SJohn.Forte@Sun.COM 
1547836SJohn.Forte@Sun.COM 	/* Issue set host interrupt command. */
1557836SJohn.Forte@Sun.COM 	ha->mailbox_flags = (uint8_t)(ha->mailbox_flags & ~MBX_INTERRUPT);
15611924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_8021)) {
15711924SDaniel.Beauregard@Sun.COM 		WRT32_IO_REG(ha, nx_host_int, NX_MBX_CMD);
15811924SDaniel.Beauregard@Sun.COM 	} else if (CFG_IST(ha, CFG_CTRL_242581)) {
15911924SDaniel.Beauregard@Sun.COM 		WRT32_IO_REG(ha, hccr, HC24_SET_HOST_INT);
16011924SDaniel.Beauregard@Sun.COM 	} else {
16111924SDaniel.Beauregard@Sun.COM 		WRT16_IO_REG(ha, hccr, HC_SET_HOST_INT);
16211924SDaniel.Beauregard@Sun.COM 	}
1637836SJohn.Forte@Sun.COM 
1647836SJohn.Forte@Sun.COM 	/* Wait for command to complete. */
1657836SJohn.Forte@Sun.COM 	if (ha->flags & INTERRUPTS_ENABLED &&
1667836SJohn.Forte@Sun.COM 	    !(ha->task_daemon_flags & (TASK_THREAD_CALLED |
1677836SJohn.Forte@Sun.COM 	    TASK_DAEMON_POWERING_DOWN)) &&
1687836SJohn.Forte@Sun.COM 	    !ddi_in_panic()) {
16911066Srafael.vanoni@sun.com 		timer = mcp->timeout * drv_usectohz(1000000);
1707836SJohn.Forte@Sun.COM 		while (!(ha->mailbox_flags & (MBX_INTERRUPT | MBX_ABORT)) &&
1717836SJohn.Forte@Sun.COM 		    !(ha->task_daemon_flags & ISP_ABORT_NEEDED)) {
1727836SJohn.Forte@Sun.COM 
17311066Srafael.vanoni@sun.com 			if (cv_reltimedwait(&ha->cv_mbx_intr,
17411066Srafael.vanoni@sun.com 			    &ha->pha->mbx_mutex, timer, TR_CLOCK_TICK) == -1) {
1757836SJohn.Forte@Sun.COM 				/*
1767836SJohn.Forte@Sun.COM 				 * The timeout time 'timer' was
1777836SJohn.Forte@Sun.COM 				 * reached without the condition
1787836SJohn.Forte@Sun.COM 				 * being signaled.
1797836SJohn.Forte@Sun.COM 				 */
180*12279SDaniel.Beauregard@Sun.COM 				MBX_REGISTER_UNLOCK(ha);
181*12279SDaniel.Beauregard@Sun.COM 				while (INTERRUPT_PENDING(ha)) {
182*12279SDaniel.Beauregard@Sun.COM 					(void) ql_isr((caddr_t)ha);
183*12279SDaniel.Beauregard@Sun.COM 					INTR_LOCK(ha);
184*12279SDaniel.Beauregard@Sun.COM 					ha->intr_claimed = B_TRUE;
185*12279SDaniel.Beauregard@Sun.COM 					INTR_UNLOCK(ha);
186*12279SDaniel.Beauregard@Sun.COM 				}
187*12279SDaniel.Beauregard@Sun.COM 				MBX_REGISTER_LOCK(ha);
1887836SJohn.Forte@Sun.COM 				break;
1897836SJohn.Forte@Sun.COM 			}
1907836SJohn.Forte@Sun.COM 		}
1917836SJohn.Forte@Sun.COM 	} else {
1927836SJohn.Forte@Sun.COM 		/* Release mailbox register lock. */
1937836SJohn.Forte@Sun.COM 		MBX_REGISTER_UNLOCK(ha);
1947836SJohn.Forte@Sun.COM 
1957836SJohn.Forte@Sun.COM 		/* Acquire interrupt lock. */
1967836SJohn.Forte@Sun.COM 		for (timer = mcp->timeout * 100; timer; timer--) {
1977836SJohn.Forte@Sun.COM 			/* Check for pending interrupts. */
19811924SDaniel.Beauregard@Sun.COM 			while (INTERRUPT_PENDING(ha)) {
1997836SJohn.Forte@Sun.COM 				(void) ql_isr((caddr_t)ha);
2007836SJohn.Forte@Sun.COM 				INTR_LOCK(ha);
2017836SJohn.Forte@Sun.COM 				ha->intr_claimed = B_TRUE;
2027836SJohn.Forte@Sun.COM 				INTR_UNLOCK(ha);
2037836SJohn.Forte@Sun.COM 				if (ha->mailbox_flags &
2047836SJohn.Forte@Sun.COM 				    (MBX_INTERRUPT | MBX_ABORT) ||
2057836SJohn.Forte@Sun.COM 				    ha->task_daemon_flags & ISP_ABORT_NEEDED) {
2067836SJohn.Forte@Sun.COM 					break;
2077836SJohn.Forte@Sun.COM 				}
2087836SJohn.Forte@Sun.COM 			}
2097836SJohn.Forte@Sun.COM 			if (ha->mailbox_flags & (MBX_INTERRUPT | MBX_ABORT) ||
2107836SJohn.Forte@Sun.COM 			    ha->task_daemon_flags & ISP_ABORT_NEEDED) {
2117836SJohn.Forte@Sun.COM 				break;
2127836SJohn.Forte@Sun.COM 			} else if (!ddi_in_panic() && timer % 101 == 0) {
2137836SJohn.Forte@Sun.COM 				delay(drv_usectohz(10000));
2147836SJohn.Forte@Sun.COM 			} else {
2157836SJohn.Forte@Sun.COM 				drv_usecwait(10000);
2167836SJohn.Forte@Sun.COM 			}
2177836SJohn.Forte@Sun.COM 		}
2187836SJohn.Forte@Sun.COM 
2197836SJohn.Forte@Sun.COM 		/* Acquire mailbox register lock. */
2207836SJohn.Forte@Sun.COM 		MBX_REGISTER_LOCK(ha);
2217836SJohn.Forte@Sun.COM 	}
2227836SJohn.Forte@Sun.COM 
2237836SJohn.Forte@Sun.COM 	/* Mailbox command timeout? */
2247836SJohn.Forte@Sun.COM 	if (ha->task_daemon_flags & ISP_ABORT_NEEDED ||
2257836SJohn.Forte@Sun.COM 	    ha->mailbox_flags & MBX_ABORT) {
2267836SJohn.Forte@Sun.COM 		rval = QL_ABORTED;
2277836SJohn.Forte@Sun.COM 	} else if ((ha->mailbox_flags & MBX_INTERRUPT) == 0) {
228*12279SDaniel.Beauregard@Sun.COM 		if (!CFG_IST(ha, CFG_CTRL_8021)) {
229*12279SDaniel.Beauregard@Sun.COM 			if (CFG_IST(ha, CFG_DUMP_MAILBOX_TIMEOUT)) {
230*12279SDaniel.Beauregard@Sun.COM 				(void) ql_binary_fw_dump(ha, FALSE);
231*12279SDaniel.Beauregard@Sun.COM 			}
232*12279SDaniel.Beauregard@Sun.COM 			EL(vha, "command timeout, isp_abort_needed\n");
233*12279SDaniel.Beauregard@Sun.COM 			set_flags |= ISP_ABORT_NEEDED;
2347836SJohn.Forte@Sun.COM 		}
2357836SJohn.Forte@Sun.COM 		rval = QL_FUNCTION_TIMEOUT;
2367836SJohn.Forte@Sun.COM 	} else {
2377836SJohn.Forte@Sun.COM 		ha->mailbox_flags = (uint8_t)
2387836SJohn.Forte@Sun.COM 		    (ha->mailbox_flags & ~MBX_INTERRUPT);
2399156SDaniel.Beauregard@Sun.COM 		/*
2409156SDaniel.Beauregard@Sun.COM 		 * This is the expected completion path so
2419156SDaniel.Beauregard@Sun.COM 		 * return the actual mbx cmd completion status.
2429156SDaniel.Beauregard@Sun.COM 		 */
2437836SJohn.Forte@Sun.COM 		rval = mcp->mb[0];
2447836SJohn.Forte@Sun.COM 	}
2457836SJohn.Forte@Sun.COM 
2469156SDaniel.Beauregard@Sun.COM 	/*
2479156SDaniel.Beauregard@Sun.COM 	 * Clear outbound to risc mailbox registers per spec. The exception
2489156SDaniel.Beauregard@Sun.COM 	 * is on 2200 mailbox 4 and 5 affect the req and resp que indexes
2499156SDaniel.Beauregard@Sun.COM 	 * so avoid writing them.
2509156SDaniel.Beauregard@Sun.COM 	 */
2519156SDaniel.Beauregard@Sun.COM 	if (ha->cfg_flags & CFG_CTRL_2200) {
2529156SDaniel.Beauregard@Sun.COM 		data = ((mcp->out_mb & ~(MBX_4 | MBX_5)) >> 1);
2539156SDaniel.Beauregard@Sun.COM 	} else {
2549156SDaniel.Beauregard@Sun.COM 		data = (mcp->out_mb >> 1);
2559156SDaniel.Beauregard@Sun.COM 	}
2567836SJohn.Forte@Sun.COM 	for (cnt = 1; cnt < ha->reg_off->mbox_cnt && data; cnt++) {
2577836SJohn.Forte@Sun.COM 		if (data & MBX_0) {
25811924SDaniel.Beauregard@Sun.COM 			WRT16_IO_REG(ha, mailbox_in[cnt], (uint16_t)0);
2597836SJohn.Forte@Sun.COM 		}
2607836SJohn.Forte@Sun.COM 		data >>= 1;
2617836SJohn.Forte@Sun.COM 	}
2627836SJohn.Forte@Sun.COM 
2637836SJohn.Forte@Sun.COM 	/* Reset busy status. */
2647836SJohn.Forte@Sun.COM 	ha->mailbox_flags = (uint8_t)(ha->mailbox_flags &
2657836SJohn.Forte@Sun.COM 	    ~(MBX_BUSY_FLG | MBX_ABORT));
2667836SJohn.Forte@Sun.COM 	ha->mcp = NULL;
2677836SJohn.Forte@Sun.COM 
2687836SJohn.Forte@Sun.COM 	/* If thread is waiting for mailbox go signal it to start. */
2697836SJohn.Forte@Sun.COM 	if (ha->mailbox_flags & MBX_WANT_FLG) {
2707836SJohn.Forte@Sun.COM 		ha->mailbox_flags = (uint8_t)(ha->mailbox_flags &
2717836SJohn.Forte@Sun.COM 		    ~MBX_WANT_FLG);
2727836SJohn.Forte@Sun.COM 		cv_broadcast(&ha->cv_mbx_wait);
2737836SJohn.Forte@Sun.COM 	}
2747836SJohn.Forte@Sun.COM 
2757836SJohn.Forte@Sun.COM 	/* Release mailbox register lock. */
2767836SJohn.Forte@Sun.COM 	MBX_REGISTER_UNLOCK(ha);
2777836SJohn.Forte@Sun.COM 
2787836SJohn.Forte@Sun.COM 	if (set_flags != 0 || reset_flags != 0) {
2797836SJohn.Forte@Sun.COM 		ql_awaken_task_daemon(ha, NULL, set_flags, reset_flags);
2807836SJohn.Forte@Sun.COM 	}
2817836SJohn.Forte@Sun.COM 
2827836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
2839156SDaniel.Beauregard@Sun.COM 		EL(vha, "%s failed, rval=%xh, mcp->mb[0]=%xh\n",
2849156SDaniel.Beauregard@Sun.COM 		    mbx_cmd_text(mbx_cmd), rval, mcp->mb[0]);
2857836SJohn.Forte@Sun.COM 	} else {
2867836SJohn.Forte@Sun.COM 		/*EMPTY*/
2877836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
2887836SJohn.Forte@Sun.COM 	}
2897836SJohn.Forte@Sun.COM 
2907836SJohn.Forte@Sun.COM 	return (rval);
2917836SJohn.Forte@Sun.COM }
2927836SJohn.Forte@Sun.COM 
2937836SJohn.Forte@Sun.COM /*
2947836SJohn.Forte@Sun.COM  * ql_setup_mbox_dma_resources
2957836SJohn.Forte@Sun.COM  *	Prepare the data for a mailbox dma transfer.
2967836SJohn.Forte@Sun.COM  *
2977836SJohn.Forte@Sun.COM  * Input:
2987836SJohn.Forte@Sun.COM  *	ha = adapter state pointer.
2997836SJohn.Forte@Sun.COM  *	mem_desc = descriptor to contain the dma resource information.
3007836SJohn.Forte@Sun.COM  *	data = pointer to the data.
3017836SJohn.Forte@Sun.COM  *	size = size of the data in bytes.
3027836SJohn.Forte@Sun.COM  *
3037836SJohn.Forte@Sun.COM  * Returns:
3047836SJohn.Forte@Sun.COM  *	ql local function return status code.
3057836SJohn.Forte@Sun.COM  *
3067836SJohn.Forte@Sun.COM  * Context:
3077836SJohn.Forte@Sun.COM  *	Kernel context.
3087836SJohn.Forte@Sun.COM  */
3097836SJohn.Forte@Sun.COM static int
ql_setup_mbox_dma_transfer(ql_adapter_state_t * ha,dma_mem_t * mem_desc,caddr_t data,uint32_t size)3107836SJohn.Forte@Sun.COM ql_setup_mbox_dma_transfer(ql_adapter_state_t *ha, dma_mem_t *mem_desc,
3117836SJohn.Forte@Sun.COM     caddr_t data, uint32_t size)
3127836SJohn.Forte@Sun.COM {
3137836SJohn.Forte@Sun.COM 	int rval = QL_SUCCESS;
3147836SJohn.Forte@Sun.COM 
3157836SJohn.Forte@Sun.COM 	if ((rval = ql_setup_mbox_dma_resources(ha, mem_desc, size)) ==
3167836SJohn.Forte@Sun.COM 	    QL_SUCCESS) {
3177836SJohn.Forte@Sun.COM 		ql_setup_mbox_dma_data(mem_desc, data);
3187836SJohn.Forte@Sun.COM 	} else {
3197836SJohn.Forte@Sun.COM 		EL(ha, "failed, setup_mbox_dma_transfer: %xh\n", rval);
3207836SJohn.Forte@Sun.COM 	}
3217836SJohn.Forte@Sun.COM 
3227836SJohn.Forte@Sun.COM 	return (rval);
3237836SJohn.Forte@Sun.COM }
3247836SJohn.Forte@Sun.COM 
3257836SJohn.Forte@Sun.COM /*
3267836SJohn.Forte@Sun.COM  * ql_setup_mbox_dma_resources
3277836SJohn.Forte@Sun.COM  *	Prepare a dma buffer.
3287836SJohn.Forte@Sun.COM  *
3297836SJohn.Forte@Sun.COM  * Input:
3307836SJohn.Forte@Sun.COM  *	ha = adapter state pointer.
3317836SJohn.Forte@Sun.COM  *	mem_desc = descriptor to contain the dma resource information.
3327836SJohn.Forte@Sun.COM  *	data = pointer to the data.
3337836SJohn.Forte@Sun.COM  *	size = size of the data in bytes.
3347836SJohn.Forte@Sun.COM  *
3357836SJohn.Forte@Sun.COM  * Returns:
3367836SJohn.Forte@Sun.COM  *	ql local function return status code.
3377836SJohn.Forte@Sun.COM  *
3387836SJohn.Forte@Sun.COM  * Context:
3397836SJohn.Forte@Sun.COM  *	Kernel context.
3407836SJohn.Forte@Sun.COM  */
3417836SJohn.Forte@Sun.COM static int
ql_setup_mbox_dma_resources(ql_adapter_state_t * ha,dma_mem_t * mem_desc,uint32_t size)3427836SJohn.Forte@Sun.COM ql_setup_mbox_dma_resources(ql_adapter_state_t *ha, dma_mem_t *mem_desc,
3437836SJohn.Forte@Sun.COM     uint32_t size)
3447836SJohn.Forte@Sun.COM {
3457836SJohn.Forte@Sun.COM 	int	rval = QL_SUCCESS;
3467836SJohn.Forte@Sun.COM 
3477836SJohn.Forte@Sun.COM 	if ((rval = ql_get_dma_mem(ha, mem_desc, size, LITTLE_ENDIAN_DMA,
3489156SDaniel.Beauregard@Sun.COM 	    QL_DMA_RING_ALIGN)) != QL_SUCCESS) {
3497836SJohn.Forte@Sun.COM 		EL(ha, "failed, ql_get_dma_mem FC_NOMEM\n");
3507836SJohn.Forte@Sun.COM 		rval = QL_MEMORY_ALLOC_FAILED;
3517836SJohn.Forte@Sun.COM 	}
3527836SJohn.Forte@Sun.COM 
3537836SJohn.Forte@Sun.COM 	return (rval);
3547836SJohn.Forte@Sun.COM }
3557836SJohn.Forte@Sun.COM 
3567836SJohn.Forte@Sun.COM /*
3577836SJohn.Forte@Sun.COM  * ql_setup_mbox_dma_data
3587836SJohn.Forte@Sun.COM  *	Move data to the dma buffer.
3597836SJohn.Forte@Sun.COM  *
3607836SJohn.Forte@Sun.COM  * Input:
3617836SJohn.Forte@Sun.COM  *	mem_desc = descriptor to contain the dma resource information.
3627836SJohn.Forte@Sun.COM  *	data = pointer to the data.
3637836SJohn.Forte@Sun.COM  *
3647836SJohn.Forte@Sun.COM  * Returns:
3657836SJohn.Forte@Sun.COM  *
3667836SJohn.Forte@Sun.COM  * Context:
3677836SJohn.Forte@Sun.COM  *	Kernel context.
3687836SJohn.Forte@Sun.COM  */
3697836SJohn.Forte@Sun.COM static void
ql_setup_mbox_dma_data(dma_mem_t * mem_desc,caddr_t data)3707836SJohn.Forte@Sun.COM ql_setup_mbox_dma_data(dma_mem_t *mem_desc, caddr_t data)
3717836SJohn.Forte@Sun.COM {
3727836SJohn.Forte@Sun.COM 	/* Copy out going data to DMA buffer. */
3737836SJohn.Forte@Sun.COM 	ddi_rep_put8(mem_desc->acc_handle, (uint8_t *)data,
3747836SJohn.Forte@Sun.COM 	    (uint8_t *)mem_desc->bp, mem_desc->size, DDI_DEV_AUTOINCR);
3757836SJohn.Forte@Sun.COM 
3767836SJohn.Forte@Sun.COM 	/* Sync DMA buffer. */
3777836SJohn.Forte@Sun.COM 	(void) ddi_dma_sync(mem_desc->dma_handle, 0, mem_desc->size,
3787836SJohn.Forte@Sun.COM 	    DDI_DMA_SYNC_FORDEV);
3797836SJohn.Forte@Sun.COM }
3807836SJohn.Forte@Sun.COM 
3817836SJohn.Forte@Sun.COM /*
3827836SJohn.Forte@Sun.COM  * ql_get_mbox_dma_data
3837836SJohn.Forte@Sun.COM  *	Recover data from the dma buffer.
3847836SJohn.Forte@Sun.COM  *
3857836SJohn.Forte@Sun.COM  * Input:
3867836SJohn.Forte@Sun.COM  *	mem_desc = descriptor to contain the dma resource information.
3877836SJohn.Forte@Sun.COM  *	data = pointer to the data.
3887836SJohn.Forte@Sun.COM  *
3897836SJohn.Forte@Sun.COM  * Returns:
3907836SJohn.Forte@Sun.COM  *
3917836SJohn.Forte@Sun.COM  * Context:
3927836SJohn.Forte@Sun.COM  *	Kernel context.
3937836SJohn.Forte@Sun.COM  */
3947836SJohn.Forte@Sun.COM static void
ql_get_mbox_dma_data(dma_mem_t * mem_desc,caddr_t data)3957836SJohn.Forte@Sun.COM ql_get_mbox_dma_data(dma_mem_t *mem_desc, caddr_t data)
3967836SJohn.Forte@Sun.COM {
3977836SJohn.Forte@Sun.COM 	/* Sync in coming DMA buffer. */
3987836SJohn.Forte@Sun.COM 	(void) ddi_dma_sync(mem_desc->dma_handle, 0, mem_desc->size,
3997836SJohn.Forte@Sun.COM 	    DDI_DMA_SYNC_FORKERNEL);
4007836SJohn.Forte@Sun.COM 	/* Copy in coming DMA data. */
4017836SJohn.Forte@Sun.COM 	ddi_rep_get8(mem_desc->acc_handle, (uint8_t *)data,
4027836SJohn.Forte@Sun.COM 	    (uint8_t *)mem_desc->bp, mem_desc->size, DDI_DEV_AUTOINCR);
4037836SJohn.Forte@Sun.COM }
4047836SJohn.Forte@Sun.COM 
4057836SJohn.Forte@Sun.COM /*
4067836SJohn.Forte@Sun.COM  * ql_initialize_ip
4077836SJohn.Forte@Sun.COM  *	Initialize IP receive buffer queue.
4087836SJohn.Forte@Sun.COM  *
4097836SJohn.Forte@Sun.COM  * Input:
4107836SJohn.Forte@Sun.COM  *	ha = adapter state pointer.
4117836SJohn.Forte@Sun.COM  *	ha->ip_init_ctrl_blk = setup for transmit.
4127836SJohn.Forte@Sun.COM  *
4137836SJohn.Forte@Sun.COM  * Returns:
4147836SJohn.Forte@Sun.COM  *	ql local function return status code.
4157836SJohn.Forte@Sun.COM  *
4167836SJohn.Forte@Sun.COM  * Context:
4177836SJohn.Forte@Sun.COM  *	Kernel context.
4187836SJohn.Forte@Sun.COM  */
4197836SJohn.Forte@Sun.COM int
ql_initialize_ip(ql_adapter_state_t * ha)4207836SJohn.Forte@Sun.COM ql_initialize_ip(ql_adapter_state_t *ha)
4217836SJohn.Forte@Sun.COM {
4227836SJohn.Forte@Sun.COM 	ql_link_t	*link;
4237836SJohn.Forte@Sun.COM 	ql_tgt_t	*tq;
4247836SJohn.Forte@Sun.COM 	uint16_t	index;
4257836SJohn.Forte@Sun.COM 	int		rval;
4267836SJohn.Forte@Sun.COM 	dma_mem_t	mem_desc;
4277836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
4287836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
4297836SJohn.Forte@Sun.COM 
4307836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
4317836SJohn.Forte@Sun.COM 
43211924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, (CFG_CTRL_6322 | CFG_CTRL_258081)) ||
4337836SJohn.Forte@Sun.COM 	    ha->vp_index != 0) {
4347836SJohn.Forte@Sun.COM 		ha->flags &= ~IP_INITIALIZED;
4357836SJohn.Forte@Sun.COM 		EL(ha, "HBA does not support IP\n");
4367836SJohn.Forte@Sun.COM 		return (QL_FUNCTION_FAILED);
4377836SJohn.Forte@Sun.COM 	}
4387836SJohn.Forte@Sun.COM 
4397836SJohn.Forte@Sun.COM 	ha->rcvbuf_ring_ptr = ha->rcvbuf_ring_bp;
4407836SJohn.Forte@Sun.COM 	ha->rcvbuf_ring_index = 0;
4417836SJohn.Forte@Sun.COM 
4427836SJohn.Forte@Sun.COM 	/* Reset all sequence counts. */
4437836SJohn.Forte@Sun.COM 	for (index = 0; index < DEVICE_HEAD_LIST_SIZE; index++) {
4447836SJohn.Forte@Sun.COM 		for (link = ha->dev[index].first; link != NULL;
4457836SJohn.Forte@Sun.COM 		    link = link->next) {
4467836SJohn.Forte@Sun.COM 			tq = link->base_address;
4477836SJohn.Forte@Sun.COM 			tq->ub_total_seg_cnt = 0;
4487836SJohn.Forte@Sun.COM 		}
4497836SJohn.Forte@Sun.COM 	}
4507836SJohn.Forte@Sun.COM 
4517836SJohn.Forte@Sun.COM 	rval = ql_setup_mbox_dma_transfer(ha, &mem_desc,
4527836SJohn.Forte@Sun.COM 	    (caddr_t)&ha->ip_init_ctrl_blk, sizeof (ql_comb_ip_init_cb_t));
4537836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
4547836SJohn.Forte@Sun.COM 		EL(ha, "failed, setup_mbox_dma_transfer: %xh\n", rval);
4557836SJohn.Forte@Sun.COM 		return (rval);
4567836SJohn.Forte@Sun.COM 	}
4577836SJohn.Forte@Sun.COM 
4587836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_INITIALIZE_IP;
4597836SJohn.Forte@Sun.COM 	mcp->mb[2] = MSW(LSD(mem_desc.cookie.dmac_laddress));
4607836SJohn.Forte@Sun.COM 	mcp->mb[3] = LSW(LSD(mem_desc.cookie.dmac_laddress));
4617836SJohn.Forte@Sun.COM 	mcp->mb[6] = MSW(MSD(mem_desc.cookie.dmac_laddress));
4627836SJohn.Forte@Sun.COM 	mcp->mb[7] = LSW(MSD(mem_desc.cookie.dmac_laddress));
4637836SJohn.Forte@Sun.COM 	mcp->mb[8] = 0;
4647836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
4657836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_8|MBX_0;
4667836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
4677836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
4687836SJohn.Forte@Sun.COM 
4697836SJohn.Forte@Sun.COM 	ql_free_dma_resource(ha, &mem_desc);
4707836SJohn.Forte@Sun.COM 
4717836SJohn.Forte@Sun.COM 	if (rval == QL_SUCCESS) {
4727836SJohn.Forte@Sun.COM 		ADAPTER_STATE_LOCK(ha);
4737836SJohn.Forte@Sun.COM 		ha->flags |= IP_INITIALIZED;
4747836SJohn.Forte@Sun.COM 		ADAPTER_STATE_UNLOCK(ha);
4757836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
4767836SJohn.Forte@Sun.COM 	} else {
4777836SJohn.Forte@Sun.COM 		ha->flags &= ~IP_INITIALIZED;
4787836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
4797836SJohn.Forte@Sun.COM 	}
4807836SJohn.Forte@Sun.COM 	return (rval);
4817836SJohn.Forte@Sun.COM }
4827836SJohn.Forte@Sun.COM 
4837836SJohn.Forte@Sun.COM /*
4847836SJohn.Forte@Sun.COM  * ql_shutdown_ip
4857836SJohn.Forte@Sun.COM  *	Disconnects firmware IP from system buffers.
4867836SJohn.Forte@Sun.COM  *
4877836SJohn.Forte@Sun.COM  * Input:
4887836SJohn.Forte@Sun.COM  *	ha = adapter state pointer.
4897836SJohn.Forte@Sun.COM  *
4907836SJohn.Forte@Sun.COM  * Returns:
4917836SJohn.Forte@Sun.COM  *	ql local function return status code.
4927836SJohn.Forte@Sun.COM  *
4937836SJohn.Forte@Sun.COM  * Context:
4947836SJohn.Forte@Sun.COM  *	Kernel context.
4957836SJohn.Forte@Sun.COM  */
4967836SJohn.Forte@Sun.COM int
ql_shutdown_ip(ql_adapter_state_t * ha)4977836SJohn.Forte@Sun.COM ql_shutdown_ip(ql_adapter_state_t *ha)
4987836SJohn.Forte@Sun.COM {
4997836SJohn.Forte@Sun.COM 	int		rval;
5007836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
5017836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
5027836SJohn.Forte@Sun.COM 	fc_unsol_buf_t	*ubp;
5037836SJohn.Forte@Sun.COM 	ql_srb_t	*sp;
5047836SJohn.Forte@Sun.COM 	uint16_t	index;
5057836SJohn.Forte@Sun.COM 
5067836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
5077836SJohn.Forte@Sun.COM 
5087836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_UNLOAD_IP;
5097836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_0;
5107836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0;
5117836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
5127836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
5137836SJohn.Forte@Sun.COM 
5147836SJohn.Forte@Sun.COM 	ADAPTER_STATE_LOCK(ha);
5157836SJohn.Forte@Sun.COM 	QL_UB_LOCK(ha);
5167836SJohn.Forte@Sun.COM 	/* Return all unsolicited buffers that ISP-IP has. */
5177836SJohn.Forte@Sun.COM 	for (index = 0; index < QL_UB_LIMIT; index++) {
5187836SJohn.Forte@Sun.COM 		ubp = ha->ub_array[index];
5197836SJohn.Forte@Sun.COM 		if (ubp != NULL) {
5207836SJohn.Forte@Sun.COM 			sp = ubp->ub_fca_private;
5217836SJohn.Forte@Sun.COM 			sp->flags &= ~SRB_UB_IN_ISP;
5227836SJohn.Forte@Sun.COM 		}
5237836SJohn.Forte@Sun.COM 	}
5247836SJohn.Forte@Sun.COM 
5257836SJohn.Forte@Sun.COM 	ha->ub_outcnt = 0;
5267836SJohn.Forte@Sun.COM 	QL_UB_UNLOCK(ha);
5277836SJohn.Forte@Sun.COM 	ha->flags &= ~IP_INITIALIZED;
5287836SJohn.Forte@Sun.COM 	ADAPTER_STATE_UNLOCK(ha);
5297836SJohn.Forte@Sun.COM 
5307836SJohn.Forte@Sun.COM 	if (rval == QL_SUCCESS) {
5317836SJohn.Forte@Sun.COM 		/* EMPTY - no need to check return value of MBC_SHUTDOWN_IP */
5327836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
5337836SJohn.Forte@Sun.COM 	} else {
5347836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
5357836SJohn.Forte@Sun.COM 	}
5367836SJohn.Forte@Sun.COM 	return (rval);
5377836SJohn.Forte@Sun.COM }
5387836SJohn.Forte@Sun.COM 
5397836SJohn.Forte@Sun.COM /*
5407836SJohn.Forte@Sun.COM  * ql_online_selftest
5417836SJohn.Forte@Sun.COM  *	Issue online self test mailbox command.
5427836SJohn.Forte@Sun.COM  *
5437836SJohn.Forte@Sun.COM  * Input:
5447836SJohn.Forte@Sun.COM  *	ha = adapter state pointer.
5457836SJohn.Forte@Sun.COM  *
5467836SJohn.Forte@Sun.COM  * Returns:
5477836SJohn.Forte@Sun.COM  *	ql local function return status code.
5487836SJohn.Forte@Sun.COM  *
5497836SJohn.Forte@Sun.COM  * Context:
5507836SJohn.Forte@Sun.COM  *	Kernel context.
5517836SJohn.Forte@Sun.COM  */
5527836SJohn.Forte@Sun.COM int
ql_online_selftest(ql_adapter_state_t * ha)5537836SJohn.Forte@Sun.COM ql_online_selftest(ql_adapter_state_t *ha)
5547836SJohn.Forte@Sun.COM {
5557836SJohn.Forte@Sun.COM 	int		rval;
5567836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
5577836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
5587836SJohn.Forte@Sun.COM 
5597836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
5607836SJohn.Forte@Sun.COM 
5617836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_ONLINE_SELF_TEST;
5627836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_0;
5637836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0 | MBX_1 | MBX_2 | MBX_3;
5647836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
5657836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
5667836SJohn.Forte@Sun.COM 
5677836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
5687836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh, mb1=%xh, mb2=%xh, mb3=%xh\n",
5697836SJohn.Forte@Sun.COM 		    rval, mcp->mb[1], mcp->mb[2], mcp->mb[3]);
5707836SJohn.Forte@Sun.COM 	} else {
5717836SJohn.Forte@Sun.COM 		/*EMPTY*/
5727836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
5737836SJohn.Forte@Sun.COM 	}
5747836SJohn.Forte@Sun.COM 	return (rval);
5757836SJohn.Forte@Sun.COM }
5767836SJohn.Forte@Sun.COM 
5777836SJohn.Forte@Sun.COM /*
5787836SJohn.Forte@Sun.COM  * ql_loop_back
5797836SJohn.Forte@Sun.COM  *	Issue diagnostic loop back frame mailbox command.
5807836SJohn.Forte@Sun.COM  *
5817836SJohn.Forte@Sun.COM  * Input:
5829611SDaniel.Beauregard@Sun.COM  *	ha:	adapter state pointer.
5839611SDaniel.Beauregard@Sun.COM  *	findex:	FCF index.
5849611SDaniel.Beauregard@Sun.COM  *	lb:	loop back parameter structure pointer.
5857836SJohn.Forte@Sun.COM  *
5867836SJohn.Forte@Sun.COM  * Returns:
5877836SJohn.Forte@Sun.COM  *	ql local function return status code.
5887836SJohn.Forte@Sun.COM  *
5897836SJohn.Forte@Sun.COM  * Context:
5907836SJohn.Forte@Sun.COM  *	Kernel context.
5917836SJohn.Forte@Sun.COM  */
5927836SJohn.Forte@Sun.COM #ifndef apps_64bit
5937836SJohn.Forte@Sun.COM int
ql_loop_back(ql_adapter_state_t * ha,uint16_t findex,lbp_t * lb,uint32_t h_xmit,uint32_t h_rcv)5949611SDaniel.Beauregard@Sun.COM ql_loop_back(ql_adapter_state_t *ha, uint16_t findex, lbp_t *lb,
5959611SDaniel.Beauregard@Sun.COM     uint32_t h_xmit, uint32_t h_rcv)
5967836SJohn.Forte@Sun.COM {
5977836SJohn.Forte@Sun.COM 	int		rval;
5987836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
5997836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
6007836SJohn.Forte@Sun.COM 
6017836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
6027836SJohn.Forte@Sun.COM 
6037836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
6047836SJohn.Forte@Sun.COM 	mcp->mb[1] = lb->options;
6059611SDaniel.Beauregard@Sun.COM 	mcp->mb[2] = findex;
6067836SJohn.Forte@Sun.COM 	mcp->mb[6] = LSW(h_rcv);
6077836SJohn.Forte@Sun.COM 	mcp->mb[7] = MSW(h_rcv);
6087836SJohn.Forte@Sun.COM 	mcp->mb[10] = LSW(lb->transfer_count);
6097836SJohn.Forte@Sun.COM 	mcp->mb[11] = MSW(lb->transfer_count);
6107836SJohn.Forte@Sun.COM 	mcp->mb[12] = lb->transfer_segment_count;
6117836SJohn.Forte@Sun.COM 	mcp->mb[13] = lb->receive_segment_count;
6127836SJohn.Forte@Sun.COM 	mcp->mb[14] = LSW(lb->transfer_data_address);
6137836SJohn.Forte@Sun.COM 	mcp->mb[15] = MSW(lb->transfer_data_address);
6147836SJohn.Forte@Sun.COM 	mcp->mb[16] = LSW(lb->receive_data_address);
6157836SJohn.Forte@Sun.COM 	mcp->mb[17] = MSW(lb->receive_data_address);
6167836SJohn.Forte@Sun.COM 	mcp->mb[18] = LSW(lb->iteration_count);
6177836SJohn.Forte@Sun.COM 	mcp->mb[19] = MSW(lb->iteration_count);
6187836SJohn.Forte@Sun.COM 	mcp->mb[20] = LSW(h_xmit);
6197836SJohn.Forte@Sun.COM 	mcp->mb[21] = MSW(h_xmit);
6207836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
6219611SDaniel.Beauregard@Sun.COM 	    MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
6227836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
6237836SJohn.Forte@Sun.COM 	mcp->timeout = lb->iteration_count / 300;
6247836SJohn.Forte@Sun.COM 
6257836SJohn.Forte@Sun.COM 	if (mcp->timeout < MAILBOX_TOV) {
6267836SJohn.Forte@Sun.COM 		mcp->timeout = MAILBOX_TOV;
6277836SJohn.Forte@Sun.COM 	}
6287836SJohn.Forte@Sun.COM 
6297836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
6307836SJohn.Forte@Sun.COM 
6317836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
63211924SDaniel.Beauregard@Sun.COM 		EL(ha, "failed, rval = %xh, mb1=%xh, mb2=%xh, mb3=%xh\n",
63311924SDaniel.Beauregard@Sun.COM 		    rval, mcp->mb[1], mcp->mb[2], mcp->mb[3]);
6347836SJohn.Forte@Sun.COM 	} else {
6357836SJohn.Forte@Sun.COM 		/*EMPTY*/
6367836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
6377836SJohn.Forte@Sun.COM 	}
6387836SJohn.Forte@Sun.COM 	return (rval);
6397836SJohn.Forte@Sun.COM }
6407836SJohn.Forte@Sun.COM #else
6417836SJohn.Forte@Sun.COM int
ql_loop_back(ql_adapter_state_t * ha,uint16_t findex,lbp_t * lb)6429611SDaniel.Beauregard@Sun.COM ql_loop_back(ql_adapter_state_t *ha, uint16_t findex, lbp_t *lb)
6437836SJohn.Forte@Sun.COM {
6447836SJohn.Forte@Sun.COM 	int		rval;
6457836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
6467836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
6477836SJohn.Forte@Sun.COM 
6487836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
6497836SJohn.Forte@Sun.COM 
6507836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
6517836SJohn.Forte@Sun.COM 	mcp->mb[1] = lb->options;
6529611SDaniel.Beauregard@Sun.COM 	mcp->mb[2] = findex;
6537836SJohn.Forte@Sun.COM 	mcp->mb[6] = LSW(h_rcv);
6547836SJohn.Forte@Sun.COM 	mcp->mb[7] = MSW(h_rcv);
6557836SJohn.Forte@Sun.COM 	mcp->mb[6] = LSW(MSD(lb->receive_data_address));
6567836SJohn.Forte@Sun.COM 	mcp->mb[7] = MSW(MSD(lb->receive_data_address));
6577836SJohn.Forte@Sun.COM 	mcp->mb[10] = LSW(lb->transfer_count);
6587836SJohn.Forte@Sun.COM 	mcp->mb[11] = MSW(lb->transfer_count);
6597836SJohn.Forte@Sun.COM 	mcp->mb[12] = lb->transfer_segment_count;
6607836SJohn.Forte@Sun.COM 	mcp->mb[13] = lb->receive_segment_count;
6617836SJohn.Forte@Sun.COM 	mcp->mb[14] = LSW(lb->transfer_data_address);
6627836SJohn.Forte@Sun.COM 	mcp->mb[15] = MSW(lb->transfer_data_address);
6637836SJohn.Forte@Sun.COM 	mcp->mb[14] = LSW(LSD(lb->transfer_data_address));
6647836SJohn.Forte@Sun.COM 	mcp->mb[15] = MSW(LSD(lb->transfer_data_address));
6657836SJohn.Forte@Sun.COM 	mcp->mb[16] = LSW(lb->receive_data_address);
6667836SJohn.Forte@Sun.COM 	mcp->mb[17] = MSW(lb->receive_data_address);
6677836SJohn.Forte@Sun.COM 	mcp->mb[16] = LSW(LSD(lb->receive_data_address));
6687836SJohn.Forte@Sun.COM 	mcp->mb[17] = MSW(LSD(lb->receive_data_address));
6697836SJohn.Forte@Sun.COM 	mcp->mb[18] = LSW(lb->iteration_count);
6707836SJohn.Forte@Sun.COM 	mcp->mb[19] = MSW(lb->iteration_count);
6717836SJohn.Forte@Sun.COM 	mcp->mb[20] = LSW(h_xmit);
6727836SJohn.Forte@Sun.COM 	mcp->mb[21] = MSW(h_xmit);
6737836SJohn.Forte@Sun.COM 	mcp->mb[20] = LSW(MSD(lb->transfer_data_address));
6747836SJohn.Forte@Sun.COM 	mcp->mb[21] = MSW(MSD(lb->transfer_data_address));
6757836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
6769611SDaniel.Beauregard@Sun.COM 	    MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
6777836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
6787836SJohn.Forte@Sun.COM 	mcp->timeout = lb->iteration_count / 300;
6797836SJohn.Forte@Sun.COM 
6807836SJohn.Forte@Sun.COM 	if (mcp->timeout < MAILBOX_TOV) {
6817836SJohn.Forte@Sun.COM 		mcp->timeout = MAILBOX_TOV;
6827836SJohn.Forte@Sun.COM 	}
6837836SJohn.Forte@Sun.COM 
6847836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
6857836SJohn.Forte@Sun.COM 
6867836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
6877836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
6887836SJohn.Forte@Sun.COM 	} else {
6897836SJohn.Forte@Sun.COM 		/*EMPTY*/
6907836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
6917836SJohn.Forte@Sun.COM 	}
6927836SJohn.Forte@Sun.COM 	return (rval);
6937836SJohn.Forte@Sun.COM }
6947836SJohn.Forte@Sun.COM #endif
6957836SJohn.Forte@Sun.COM 
6967836SJohn.Forte@Sun.COM /*
6977836SJohn.Forte@Sun.COM  * ql_echo
6987836SJohn.Forte@Sun.COM  *	Issue an ELS echo using the user specified data to a user specified
6997836SJohn.Forte@Sun.COM  *	destination
7007836SJohn.Forte@Sun.COM  *
7017836SJohn.Forte@Sun.COM  * Input:
7027836SJohn.Forte@Sun.COM  *	ha:		adapter state pointer.
7039611SDaniel.Beauregard@Sun.COM  *	findex:		FCF index.
7047836SJohn.Forte@Sun.COM  *	echo_pt:	echo parameter structure pointer.
7057836SJohn.Forte@Sun.COM  *
7067836SJohn.Forte@Sun.COM  * Returns:
7077836SJohn.Forte@Sun.COM  *	ql local function return status code.
7087836SJohn.Forte@Sun.COM  *
7097836SJohn.Forte@Sun.COM  * Context:
7107836SJohn.Forte@Sun.COM  *	Kernel context.
7117836SJohn.Forte@Sun.COM  */
7127836SJohn.Forte@Sun.COM int
ql_echo(ql_adapter_state_t * ha,uint16_t findex,echo_t * echo_pt)7139611SDaniel.Beauregard@Sun.COM ql_echo(ql_adapter_state_t *ha, uint16_t findex, echo_t *echo_pt)
7147836SJohn.Forte@Sun.COM {
7157836SJohn.Forte@Sun.COM 	int		rval;
7167836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
7177836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
7187836SJohn.Forte@Sun.COM 
7197836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
7207836SJohn.Forte@Sun.COM 
7217836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_ECHO;			/* ECHO command */
7227836SJohn.Forte@Sun.COM 	mcp->mb[1] = echo_pt->options;		/* command options; 64 bit */
7237836SJohn.Forte@Sun.COM 						/* addressing (bit 6) and */
7247836SJohn.Forte@Sun.COM 						/* real echo (bit 15 */
7259611SDaniel.Beauregard@Sun.COM 	mcp->mb[2] = findex;
7267836SJohn.Forte@Sun.COM 
7277836SJohn.Forte@Sun.COM 	/*
7287836SJohn.Forte@Sun.COM 	 * I know this looks strange, using a field labled "not used"
7297836SJohn.Forte@Sun.COM 	 * The way the ddi_dma_cookie_t structure/union is defined
7307836SJohn.Forte@Sun.COM 	 * is a union of one 64 bit entity with an array of two 32
7317836SJohn.Forte@Sun.COM 	 * bit enititys.  Since we have routines to convert 32 bit
7327836SJohn.Forte@Sun.COM 	 * entities into 16 bit entities it is easier to use
7337836SJohn.Forte@Sun.COM 	 * both 32 bit union members then the one 64 bit union
7347836SJohn.Forte@Sun.COM 	 * member
7357836SJohn.Forte@Sun.COM 	 */
7367836SJohn.Forte@Sun.COM 	if (echo_pt->options & BIT_6) {
7377836SJohn.Forte@Sun.COM 		/* 64 bit addressing */
7387836SJohn.Forte@Sun.COM 		/* Receive data dest add in system memory bits 47-32 */
7397836SJohn.Forte@Sun.COM 		mcp->mb[6] = LSW(echo_pt->receive_data_address.dmac_notused);
7407836SJohn.Forte@Sun.COM 
7417836SJohn.Forte@Sun.COM 		/* Receive data dest add in system memory bits 63-48 */
7427836SJohn.Forte@Sun.COM 		mcp->mb[7] = MSW(echo_pt->receive_data_address.dmac_notused);
7437836SJohn.Forte@Sun.COM 
7447836SJohn.Forte@Sun.COM 		/* Transmit data source address in system memory bits 47-32 */
7457836SJohn.Forte@Sun.COM 		mcp->mb[20] = LSW(echo_pt->transfer_data_address.dmac_notused);
7467836SJohn.Forte@Sun.COM 
7477836SJohn.Forte@Sun.COM 		/* Transmit data source address in system memory bits 63-48 */
7487836SJohn.Forte@Sun.COM 		mcp->mb[21] = MSW(echo_pt->transfer_data_address.dmac_notused);
7497836SJohn.Forte@Sun.COM 	}
7507836SJohn.Forte@Sun.COM 
7517836SJohn.Forte@Sun.COM 	/* transfer count bits 15-0 */
7527836SJohn.Forte@Sun.COM 	mcp->mb[10] = LSW(echo_pt->transfer_count);
7537836SJohn.Forte@Sun.COM 
7547836SJohn.Forte@Sun.COM 	/* Transmit data source address in system memory bits 15-0 */
7557836SJohn.Forte@Sun.COM 	mcp->mb[14] = LSW(echo_pt->transfer_data_address.dmac_address);
7567836SJohn.Forte@Sun.COM 
7577836SJohn.Forte@Sun.COM 	/*  Transmit data source address in system memory bits 31-16 */
7587836SJohn.Forte@Sun.COM 	mcp->mb[15] = MSW(echo_pt->transfer_data_address.dmac_address);
7597836SJohn.Forte@Sun.COM 
7607836SJohn.Forte@Sun.COM 	/* Receive data destination address in system memory bits 15-0 */
7617836SJohn.Forte@Sun.COM 	mcp->mb[16] = LSW(echo_pt->receive_data_address.dmac_address);
7627836SJohn.Forte@Sun.COM 
7637836SJohn.Forte@Sun.COM 	/*  Receive data destination address in system memory bits 31-16 */
7647836SJohn.Forte@Sun.COM 	mcp->mb[17] = MSW(echo_pt->receive_data_address.dmac_address);
7657836SJohn.Forte@Sun.COM 
7667836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|MBX_14|MBX_10|
7679611SDaniel.Beauregard@Sun.COM 	    MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
7689611SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_3|MBX_1|MBX_0;
7697836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
7707836SJohn.Forte@Sun.COM 
7717836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
7727836SJohn.Forte@Sun.COM 
7737836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
7747836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
7757836SJohn.Forte@Sun.COM 	} else {
7767836SJohn.Forte@Sun.COM 		/*EMPTY*/
7777836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
7787836SJohn.Forte@Sun.COM 	}
7797836SJohn.Forte@Sun.COM 	return (rval);
7807836SJohn.Forte@Sun.COM }
7817836SJohn.Forte@Sun.COM 
7827836SJohn.Forte@Sun.COM /*
7837836SJohn.Forte@Sun.COM  * ql_send_change_request
7847836SJohn.Forte@Sun.COM  *	Issue send change request mailbox command.
7857836SJohn.Forte@Sun.COM  *
7867836SJohn.Forte@Sun.COM  * Input:
7877836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
7887836SJohn.Forte@Sun.COM  *	fmt:	Registration format.
7897836SJohn.Forte@Sun.COM  *
7907836SJohn.Forte@Sun.COM  * Returns:
7917836SJohn.Forte@Sun.COM  *	ql local function return status code.
7927836SJohn.Forte@Sun.COM  *
7937836SJohn.Forte@Sun.COM  * Context:
7947836SJohn.Forte@Sun.COM  *	Kernel context.
7957836SJohn.Forte@Sun.COM  */
7967836SJohn.Forte@Sun.COM int
ql_send_change_request(ql_adapter_state_t * ha,uint16_t fmt)7977836SJohn.Forte@Sun.COM ql_send_change_request(ql_adapter_state_t *ha, uint16_t fmt)
7987836SJohn.Forte@Sun.COM {
7997836SJohn.Forte@Sun.COM 	int		rval;
8007836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
8017836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
8027836SJohn.Forte@Sun.COM 
8037836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
8047836SJohn.Forte@Sun.COM 
8057836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
8067836SJohn.Forte@Sun.COM 	mcp->mb[1] = fmt;
8077836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_1|MBX_0;
8087836SJohn.Forte@Sun.COM 	if (ha->flags & VP_ENABLED) {
8097836SJohn.Forte@Sun.COM 		mcp->mb[9] = ha->vp_index;
8107836SJohn.Forte@Sun.COM 		mcp->out_mb |= MBX_9;
8117836SJohn.Forte@Sun.COM 	}
8127836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0;
8137836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
8147836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
8157836SJohn.Forte@Sun.COM 
8167836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
8177836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
8187836SJohn.Forte@Sun.COM 	} else {
8197836SJohn.Forte@Sun.COM 		/*EMPTY*/
8207836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
8217836SJohn.Forte@Sun.COM 	}
8227836SJohn.Forte@Sun.COM 	return (rval);
8237836SJohn.Forte@Sun.COM }
8247836SJohn.Forte@Sun.COM 
8257836SJohn.Forte@Sun.COM /*
8267836SJohn.Forte@Sun.COM  * ql_send_lfa
8277836SJohn.Forte@Sun.COM  *	Send a Loop Fabric Address mailbox command.
8287836SJohn.Forte@Sun.COM  *
8297836SJohn.Forte@Sun.COM  * Input:
8307836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
8317836SJohn.Forte@Sun.COM  *	lfa:	LFA command structure pointer.
8327836SJohn.Forte@Sun.COM  *
8337836SJohn.Forte@Sun.COM  * Returns:
8347836SJohn.Forte@Sun.COM  *	ql local function return status code.
8357836SJohn.Forte@Sun.COM  *
8367836SJohn.Forte@Sun.COM  * Context:
8377836SJohn.Forte@Sun.COM  *	Kernel context.
8387836SJohn.Forte@Sun.COM  */
8397836SJohn.Forte@Sun.COM int
ql_send_lfa(ql_adapter_state_t * ha,lfa_cmd_t * lfa)8407836SJohn.Forte@Sun.COM ql_send_lfa(ql_adapter_state_t *ha, lfa_cmd_t *lfa)
8417836SJohn.Forte@Sun.COM {
8427836SJohn.Forte@Sun.COM 	int		rval;
8437836SJohn.Forte@Sun.COM 	uint16_t	size;
8447836SJohn.Forte@Sun.COM 	dma_mem_t	mem_desc;
8457836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
8467836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
8477836SJohn.Forte@Sun.COM 
8487836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
8497836SJohn.Forte@Sun.COM 
8507836SJohn.Forte@Sun.COM 	/* LFA_CB sz = 4 16bit words subcommand + 10 16bit words header. */
8517836SJohn.Forte@Sun.COM 	size = (uint16_t)((lfa->subcommand_length[0] + 10) << 1);
8527836SJohn.Forte@Sun.COM 
8537836SJohn.Forte@Sun.COM 	rval = ql_setup_mbox_dma_transfer(ha, &mem_desc, (caddr_t)lfa, size);
8547836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
8557836SJohn.Forte@Sun.COM 		EL(ha, "failed, setup_mbox_dma_transfer: %xh\n", rval);
8567836SJohn.Forte@Sun.COM 		return (rval);
8577836SJohn.Forte@Sun.COM 	}
8587836SJohn.Forte@Sun.COM 
8597836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_SEND_LFA_COMMAND;
8607836SJohn.Forte@Sun.COM 	mcp->mb[1] = (uint16_t)(size >> 1);
8617836SJohn.Forte@Sun.COM 	mcp->mb[2] = MSW(LSD(mem_desc.cookie.dmac_laddress));
8627836SJohn.Forte@Sun.COM 	mcp->mb[3] = LSW(LSD(mem_desc.cookie.dmac_laddress));
8637836SJohn.Forte@Sun.COM 	mcp->mb[6] = MSW(MSD(mem_desc.cookie.dmac_laddress));
8647836SJohn.Forte@Sun.COM 	mcp->mb[7] = LSW(MSD(mem_desc.cookie.dmac_laddress));
8657836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0;
8667836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
8677836SJohn.Forte@Sun.COM 	if (ha->flags & VP_ENABLED) {
8687836SJohn.Forte@Sun.COM 		mcp->mb[9] = ha->vp_index;
8697836SJohn.Forte@Sun.COM 		mcp->out_mb |= MBX_9;
8707836SJohn.Forte@Sun.COM 	}
8717836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
8727836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
8737836SJohn.Forte@Sun.COM 
8747836SJohn.Forte@Sun.COM 	ql_free_dma_resource(ha, &mem_desc);
8757836SJohn.Forte@Sun.COM 
8767836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
8777836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
8787836SJohn.Forte@Sun.COM 	} else {
8797836SJohn.Forte@Sun.COM 		/*EMPTY*/
8807836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
8817836SJohn.Forte@Sun.COM 	}
8827836SJohn.Forte@Sun.COM 
8837836SJohn.Forte@Sun.COM 	return (rval);
8847836SJohn.Forte@Sun.COM }
8857836SJohn.Forte@Sun.COM 
8867836SJohn.Forte@Sun.COM /*
8877836SJohn.Forte@Sun.COM  * ql_clear_aca
8887836SJohn.Forte@Sun.COM  *	Issue clear ACA mailbox command.
8897836SJohn.Forte@Sun.COM  *
8907836SJohn.Forte@Sun.COM  * Input:
8917836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
8927836SJohn.Forte@Sun.COM  *	tq:	target queue pointer.
8937836SJohn.Forte@Sun.COM  *	lun:	LUN.
8947836SJohn.Forte@Sun.COM  *
8957836SJohn.Forte@Sun.COM  * Returns:
8967836SJohn.Forte@Sun.COM  *	ql local function return status code.
8977836SJohn.Forte@Sun.COM  *
8987836SJohn.Forte@Sun.COM  * Context:
8997836SJohn.Forte@Sun.COM  *	Kernel context.
9007836SJohn.Forte@Sun.COM  */
9017836SJohn.Forte@Sun.COM int
ql_clear_aca(ql_adapter_state_t * ha,ql_tgt_t * tq,uint16_t lun)9027836SJohn.Forte@Sun.COM ql_clear_aca(ql_adapter_state_t *ha, ql_tgt_t *tq, uint16_t lun)
9037836SJohn.Forte@Sun.COM {
9047836SJohn.Forte@Sun.COM 	int		rval;
9057836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
9067836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
9077836SJohn.Forte@Sun.COM 
9087836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
9097836SJohn.Forte@Sun.COM 
91011924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_24258081)) {
9117836SJohn.Forte@Sun.COM 		rval = ql_task_mgmt_iocb(ha, tq, lun, CF_CLEAR_ACA, 0);
9127836SJohn.Forte@Sun.COM 	} else {
9137836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_CLEAR_ACA;
9147836SJohn.Forte@Sun.COM 		if (CFG_IST(ha, CFG_EXT_FW_INTERFACE)) {
9157836SJohn.Forte@Sun.COM 			mcp->mb[1] = tq->loop_id;
9167836SJohn.Forte@Sun.COM 		} else {
9177836SJohn.Forte@Sun.COM 			mcp->mb[1] = (uint16_t)(tq->loop_id << 8);
9187836SJohn.Forte@Sun.COM 		}
9197836SJohn.Forte@Sun.COM 		mcp->mb[2] = lun;
9207836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_2|MBX_1|MBX_0;
9217836SJohn.Forte@Sun.COM 		mcp->in_mb = MBX_0;
9227836SJohn.Forte@Sun.COM 		mcp->timeout = MAILBOX_TOV;
9237836SJohn.Forte@Sun.COM 		rval = ql_mailbox_command(ha, mcp);
9247836SJohn.Forte@Sun.COM 	}
9257836SJohn.Forte@Sun.COM 
9267836SJohn.Forte@Sun.COM 	(void) ql_marker(ha, tq->loop_id, lun, MK_SYNC_ID);
9277836SJohn.Forte@Sun.COM 
9287836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
9297836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
9307836SJohn.Forte@Sun.COM 	} else {
9317836SJohn.Forte@Sun.COM 		/*EMPTY*/
9327836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
9337836SJohn.Forte@Sun.COM 	}
9347836SJohn.Forte@Sun.COM 
9357836SJohn.Forte@Sun.COM 	return (rval);
9367836SJohn.Forte@Sun.COM }
9377836SJohn.Forte@Sun.COM 
9387836SJohn.Forte@Sun.COM /*
9397836SJohn.Forte@Sun.COM  * ql_target_reset
9407836SJohn.Forte@Sun.COM  *	Issue target reset mailbox command.
9417836SJohn.Forte@Sun.COM  *
9427836SJohn.Forte@Sun.COM  * Input:
9437836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
9447836SJohn.Forte@Sun.COM  *	tq:	target queue pointer.
9457836SJohn.Forte@Sun.COM  *	delay:	seconds.
9467836SJohn.Forte@Sun.COM  *
9477836SJohn.Forte@Sun.COM  * Returns:
9487836SJohn.Forte@Sun.COM  *	ql local function return status code.
9497836SJohn.Forte@Sun.COM  *
9507836SJohn.Forte@Sun.COM  * Context:
9517836SJohn.Forte@Sun.COM  *	Kernel context.
9527836SJohn.Forte@Sun.COM  */
9537836SJohn.Forte@Sun.COM int
ql_target_reset(ql_adapter_state_t * ha,ql_tgt_t * tq,uint16_t delay)9547836SJohn.Forte@Sun.COM ql_target_reset(ql_adapter_state_t *ha, ql_tgt_t *tq, uint16_t delay)
9557836SJohn.Forte@Sun.COM {
9567836SJohn.Forte@Sun.COM 	ql_link_t	*link;
9577836SJohn.Forte@Sun.COM 	uint16_t	index;
9587836SJohn.Forte@Sun.COM 	int		rval;
9597836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
9607836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
9617836SJohn.Forte@Sun.COM 
9627836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
9637836SJohn.Forte@Sun.COM 
96411924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_24258081)) {
9657836SJohn.Forte@Sun.COM 		/* queue = NULL, all targets. */
9667836SJohn.Forte@Sun.COM 		if (tq == NULL) {
9677836SJohn.Forte@Sun.COM 			for (index = 0; index < DEVICE_HEAD_LIST_SIZE;
9687836SJohn.Forte@Sun.COM 			    index++) {
9697836SJohn.Forte@Sun.COM 				for (link = ha->dev[index].first; link !=
9707836SJohn.Forte@Sun.COM 				    NULL; link = link->next) {
9717836SJohn.Forte@Sun.COM 					tq = link->base_address;
9727836SJohn.Forte@Sun.COM 					if (!VALID_DEVICE_ID(ha,
9737836SJohn.Forte@Sun.COM 					    tq->loop_id)) {
9747836SJohn.Forte@Sun.COM 						continue;
9757836SJohn.Forte@Sun.COM 					}
97611541SDaniel.Beauregard@Sun.COM 
97711541SDaniel.Beauregard@Sun.COM 					if (CFG_IST(ha, CFG_FAST_TIMEOUT)) {
97811541SDaniel.Beauregard@Sun.COM 						rval = ql_task_mgmt_iocb(ha,
97911541SDaniel.Beauregard@Sun.COM 						    tq, 0, CF_DO_NOT_SEND |
98011541SDaniel.Beauregard@Sun.COM 						    CF_TARGET_RESET, delay);
98111541SDaniel.Beauregard@Sun.COM 					} else {
98211541SDaniel.Beauregard@Sun.COM 						rval = ql_task_mgmt_iocb(ha,
98311541SDaniel.Beauregard@Sun.COM 						    tq, 0, CF_TARGET_RESET,
98411541SDaniel.Beauregard@Sun.COM 						    delay);
98511541SDaniel.Beauregard@Sun.COM 					}
9867836SJohn.Forte@Sun.COM 
9877836SJohn.Forte@Sun.COM 					if (rval != QL_SUCCESS) {
9887836SJohn.Forte@Sun.COM 						break;
9897836SJohn.Forte@Sun.COM 					}
9907836SJohn.Forte@Sun.COM 				}
9917836SJohn.Forte@Sun.COM 
9927836SJohn.Forte@Sun.COM 				if (link != NULL) {
9937836SJohn.Forte@Sun.COM 					break;
9947836SJohn.Forte@Sun.COM 				}
9957836SJohn.Forte@Sun.COM 			}
9967836SJohn.Forte@Sun.COM 			tq = NULL;
9977836SJohn.Forte@Sun.COM 		} else {
99811541SDaniel.Beauregard@Sun.COM 
99911541SDaniel.Beauregard@Sun.COM 			if (CFG_IST(ha, CFG_FAST_TIMEOUT)) {
100011541SDaniel.Beauregard@Sun.COM 				rval = ql_task_mgmt_iocb(ha, tq, 0,
100111541SDaniel.Beauregard@Sun.COM 				    CF_TARGET_RESET | CF_DO_NOT_SEND, delay);
100211541SDaniel.Beauregard@Sun.COM 			} else {
100311541SDaniel.Beauregard@Sun.COM 				rval = ql_task_mgmt_iocb(ha, tq, 0,
100411541SDaniel.Beauregard@Sun.COM 				    CF_TARGET_RESET, delay);
100511541SDaniel.Beauregard@Sun.COM 			}
10067836SJohn.Forte@Sun.COM 		}
10077836SJohn.Forte@Sun.COM 	} else {
10087836SJohn.Forte@Sun.COM 		/* queue = NULL, all targets. */
10097836SJohn.Forte@Sun.COM 		if (tq == NULL) {
10107836SJohn.Forte@Sun.COM 			mcp->mb[0] = MBC_RESET;
10117836SJohn.Forte@Sun.COM 			mcp->mb[1] = delay;
10127836SJohn.Forte@Sun.COM 			mcp->out_mb = MBX_1|MBX_0;
10137836SJohn.Forte@Sun.COM 		} else {
10147836SJohn.Forte@Sun.COM 			mcp->mb[0] = MBC_TARGET_RESET;
10157836SJohn.Forte@Sun.COM 			if (CFG_IST(ha, CFG_EXT_FW_INTERFACE)) {
10167836SJohn.Forte@Sun.COM 				mcp->mb[1] = tq->loop_id;
10177836SJohn.Forte@Sun.COM 			} else {
10187836SJohn.Forte@Sun.COM 				mcp->mb[1] = (uint16_t)(tq->loop_id << 8);
10197836SJohn.Forte@Sun.COM 			}
10207836SJohn.Forte@Sun.COM 			mcp->mb[2] = delay;
10217836SJohn.Forte@Sun.COM 			mcp->out_mb = MBX_2|MBX_1|MBX_0;
10227836SJohn.Forte@Sun.COM 		}
10237836SJohn.Forte@Sun.COM 		mcp->in_mb = MBX_0;
10247836SJohn.Forte@Sun.COM 		mcp->timeout = MAILBOX_TOV;
10257836SJohn.Forte@Sun.COM 		rval = ql_mailbox_command(ha, mcp);
10267836SJohn.Forte@Sun.COM 	}
10277836SJohn.Forte@Sun.COM 
10287836SJohn.Forte@Sun.COM 	tq == NULL ? (void) ql_marker(ha, 0, 0, MK_SYNC_ALL) :
10297836SJohn.Forte@Sun.COM 	    (void) ql_marker(ha, tq->loop_id, 0, MK_SYNC_ID);
10307836SJohn.Forte@Sun.COM 
10317836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
10327836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
10337836SJohn.Forte@Sun.COM 	} else {
10347836SJohn.Forte@Sun.COM 		/*EMPTY*/
10357836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
10367836SJohn.Forte@Sun.COM 	}
10377836SJohn.Forte@Sun.COM 
10387836SJohn.Forte@Sun.COM 	return (rval);
10397836SJohn.Forte@Sun.COM }
10407836SJohn.Forte@Sun.COM 
10417836SJohn.Forte@Sun.COM /*
10427836SJohn.Forte@Sun.COM  * ql_abort_target
10437836SJohn.Forte@Sun.COM  *	Issue abort target mailbox command.
10447836SJohn.Forte@Sun.COM  *
10457836SJohn.Forte@Sun.COM  * Input:
10467836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
10477836SJohn.Forte@Sun.COM  *	tq:	target queue pointer.
10487836SJohn.Forte@Sun.COM  *	delay:	in seconds.
10497836SJohn.Forte@Sun.COM  *
10507836SJohn.Forte@Sun.COM  * Returns:
10519446SDaniel.Beauregard@Sun.COM  *	ql local function return status code.
10527836SJohn.Forte@Sun.COM  *
10537836SJohn.Forte@Sun.COM  * Context:
10547836SJohn.Forte@Sun.COM  *	Kernel context.
10557836SJohn.Forte@Sun.COM  */
10567836SJohn.Forte@Sun.COM int
ql_abort_target(ql_adapter_state_t * ha,ql_tgt_t * tq,uint16_t delay)10577836SJohn.Forte@Sun.COM ql_abort_target(ql_adapter_state_t *ha, ql_tgt_t *tq, uint16_t delay)
10587836SJohn.Forte@Sun.COM {
10597836SJohn.Forte@Sun.COM 	int		rval;
10607836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
10617836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
10627836SJohn.Forte@Sun.COM 
10637836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
10647836SJohn.Forte@Sun.COM 
106511924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_24258081)) {
10667836SJohn.Forte@Sun.COM 		rval = ql_task_mgmt_iocb(ha, tq, 0,
10677836SJohn.Forte@Sun.COM 		    CF_DO_NOT_SEND | CF_TARGET_RESET, delay);
10687836SJohn.Forte@Sun.COM 	} else {
10697836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_ABORT_TARGET;
10707836SJohn.Forte@Sun.COM 		/* Don't send Task Mgt */
10717836SJohn.Forte@Sun.COM 		if (CFG_IST(ha, CFG_EXT_FW_INTERFACE)) {
10727836SJohn.Forte@Sun.COM 			mcp->mb[1] = tq->loop_id;
10737836SJohn.Forte@Sun.COM 			mcp->mb[10] = BIT_0;
10747836SJohn.Forte@Sun.COM 			mcp->out_mb = MBX_10|MBX_2|MBX_1|MBX_0;
10757836SJohn.Forte@Sun.COM 		} else {
10767836SJohn.Forte@Sun.COM 			mcp->mb[1] = (uint16_t)(tq->loop_id << 8 | BIT_0);
10777836SJohn.Forte@Sun.COM 			mcp->out_mb = MBX_2|MBX_1|MBX_0;
10787836SJohn.Forte@Sun.COM 		}
10797836SJohn.Forte@Sun.COM 		mcp->mb[2] = delay;
10807836SJohn.Forte@Sun.COM 		mcp->in_mb = MBX_0;
10817836SJohn.Forte@Sun.COM 		mcp->timeout = MAILBOX_TOV;
10827836SJohn.Forte@Sun.COM 		rval = ql_mailbox_command(ha, mcp);
10837836SJohn.Forte@Sun.COM 	}
10847836SJohn.Forte@Sun.COM 
10857836SJohn.Forte@Sun.COM 	(void) ql_marker(ha, tq->loop_id, 0, MK_SYNC_ID);
10867836SJohn.Forte@Sun.COM 
10877836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
10887836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh, d_id=%xh\n", rval, tq->d_id.b24);
10897836SJohn.Forte@Sun.COM 	} else {
10907836SJohn.Forte@Sun.COM 		/*EMPTY*/
10917836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
10927836SJohn.Forte@Sun.COM 	}
10937836SJohn.Forte@Sun.COM 	return (rval);
10947836SJohn.Forte@Sun.COM }
10957836SJohn.Forte@Sun.COM 
10967836SJohn.Forte@Sun.COM /*
10977836SJohn.Forte@Sun.COM  * ql_lun_reset
10987836SJohn.Forte@Sun.COM  *	Issue LUN reset task management mailbox command.
10997836SJohn.Forte@Sun.COM  *
11007836SJohn.Forte@Sun.COM  * Input:
11017836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
11027836SJohn.Forte@Sun.COM  *	tq:	target queue pointer.
11037836SJohn.Forte@Sun.COM  *	lun:	LUN.
11047836SJohn.Forte@Sun.COM  *
11057836SJohn.Forte@Sun.COM  * Returns:
11067836SJohn.Forte@Sun.COM  *	ql local function return status code.
11077836SJohn.Forte@Sun.COM  *
11087836SJohn.Forte@Sun.COM  * Context:
11097836SJohn.Forte@Sun.COM  *	Kernel context.
11107836SJohn.Forte@Sun.COM  */
11117836SJohn.Forte@Sun.COM int
ql_lun_reset(ql_adapter_state_t * ha,ql_tgt_t * tq,uint16_t lun)11127836SJohn.Forte@Sun.COM ql_lun_reset(ql_adapter_state_t *ha, ql_tgt_t *tq, uint16_t lun)
11137836SJohn.Forte@Sun.COM {
11147836SJohn.Forte@Sun.COM 	int		rval;
11157836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
11167836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
11177836SJohn.Forte@Sun.COM 
11187836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
11197836SJohn.Forte@Sun.COM 
112011924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_24258081)) {
11217836SJohn.Forte@Sun.COM 		rval = ql_task_mgmt_iocb(ha, tq, lun, CF_LUN_RESET, 0);
11227836SJohn.Forte@Sun.COM 	} else {
11237836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_LUN_RESET;
11247836SJohn.Forte@Sun.COM 		if (CFG_IST(ha, CFG_EXT_FW_INTERFACE)) {
11257836SJohn.Forte@Sun.COM 			mcp->mb[1] = tq->loop_id;
11267836SJohn.Forte@Sun.COM 		} else {
11277836SJohn.Forte@Sun.COM 			mcp->mb[1] = (uint16_t)(tq->loop_id << 8);
11287836SJohn.Forte@Sun.COM 		}
11297836SJohn.Forte@Sun.COM 		mcp->mb[2] = lun;
11307836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
11317836SJohn.Forte@Sun.COM 		mcp->in_mb = MBX_0;
11327836SJohn.Forte@Sun.COM 		mcp->timeout = MAILBOX_TOV;
11337836SJohn.Forte@Sun.COM 		rval = ql_mailbox_command(ha, mcp);
11347836SJohn.Forte@Sun.COM 	}
11357836SJohn.Forte@Sun.COM 
11367836SJohn.Forte@Sun.COM 	(void) ql_marker(ha, tq->loop_id, lun, MK_SYNC_ID);
11377836SJohn.Forte@Sun.COM 
11387836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
11397836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh, d_id=%xh\n", rval, tq->d_id.b24);
11407836SJohn.Forte@Sun.COM 	} else {
11417836SJohn.Forte@Sun.COM 		/*EMPTY*/
11427836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
11437836SJohn.Forte@Sun.COM 	}
11447836SJohn.Forte@Sun.COM 	return (rval);
11457836SJohn.Forte@Sun.COM }
11467836SJohn.Forte@Sun.COM 
11477836SJohn.Forte@Sun.COM /*
11487836SJohn.Forte@Sun.COM  * ql_clear_task_set
11497836SJohn.Forte@Sun.COM  *	Issue clear task set mailbox command.
11507836SJohn.Forte@Sun.COM  *
11517836SJohn.Forte@Sun.COM  * Input:
11527836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
11537836SJohn.Forte@Sun.COM  *	tq:	target queue pointer.
11547836SJohn.Forte@Sun.COM  *	lun:	LUN.
11557836SJohn.Forte@Sun.COM  *
11567836SJohn.Forte@Sun.COM  * Returns:
11577836SJohn.Forte@Sun.COM  *	ql local function return status code.
11587836SJohn.Forte@Sun.COM  *
11597836SJohn.Forte@Sun.COM  * Context:
11607836SJohn.Forte@Sun.COM  *	Kernel context.
11617836SJohn.Forte@Sun.COM  */
11627836SJohn.Forte@Sun.COM int
ql_clear_task_set(ql_adapter_state_t * ha,ql_tgt_t * tq,uint16_t lun)11637836SJohn.Forte@Sun.COM ql_clear_task_set(ql_adapter_state_t *ha, ql_tgt_t *tq, uint16_t lun)
11647836SJohn.Forte@Sun.COM {
11657836SJohn.Forte@Sun.COM 	int		rval;
11667836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
11677836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
11687836SJohn.Forte@Sun.COM 
11697836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
11707836SJohn.Forte@Sun.COM 
117111924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_24258081)) {
11727836SJohn.Forte@Sun.COM 		rval = ql_task_mgmt_iocb(ha, tq, lun, CF_CLEAR_TASK_SET, 0);
11737836SJohn.Forte@Sun.COM 	} else {
11747836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_CLEAR_TASK_SET;
11757836SJohn.Forte@Sun.COM 		if (CFG_IST(ha, CFG_EXT_FW_INTERFACE)) {
11767836SJohn.Forte@Sun.COM 			mcp->mb[1] = tq->loop_id;
11777836SJohn.Forte@Sun.COM 		} else {
11787836SJohn.Forte@Sun.COM 			mcp->mb[1] = (uint16_t)(tq->loop_id << 8);
11797836SJohn.Forte@Sun.COM 		}
11807836SJohn.Forte@Sun.COM 		mcp->mb[2] = lun;
11817836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_2|MBX_1|MBX_0;
11827836SJohn.Forte@Sun.COM 		mcp->in_mb = MBX_0;
11837836SJohn.Forte@Sun.COM 		mcp->timeout = MAILBOX_TOV;
11847836SJohn.Forte@Sun.COM 		rval = ql_mailbox_command(ha, mcp);
11857836SJohn.Forte@Sun.COM 	}
11867836SJohn.Forte@Sun.COM 
11877836SJohn.Forte@Sun.COM 	(void) ql_marker(ha, tq->loop_id, lun, MK_SYNC_ID);
11887836SJohn.Forte@Sun.COM 
11897836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
11907836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh, d_id=%xh\n", rval, tq->d_id.b24);
11917836SJohn.Forte@Sun.COM 	} else {
11927836SJohn.Forte@Sun.COM 		/*EMPTY*/
11937836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
11947836SJohn.Forte@Sun.COM 	}
11957836SJohn.Forte@Sun.COM 
11967836SJohn.Forte@Sun.COM 	return (rval);
11977836SJohn.Forte@Sun.COM }
11987836SJohn.Forte@Sun.COM 
11997836SJohn.Forte@Sun.COM /*
12007836SJohn.Forte@Sun.COM  * ql_abort_task_set
12017836SJohn.Forte@Sun.COM  *	Issue abort task set mailbox command.
12027836SJohn.Forte@Sun.COM  *
12037836SJohn.Forte@Sun.COM  * Input:
12047836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
12057836SJohn.Forte@Sun.COM  *	tq:	target queue pointer.
12067836SJohn.Forte@Sun.COM  *	lun:	LUN.
12077836SJohn.Forte@Sun.COM  *
12087836SJohn.Forte@Sun.COM  * Returns:
12097836SJohn.Forte@Sun.COM  *	ql local function return status code.
12107836SJohn.Forte@Sun.COM  *
12117836SJohn.Forte@Sun.COM  * Context:
12127836SJohn.Forte@Sun.COM  *	Kernel context.
12137836SJohn.Forte@Sun.COM  */
12147836SJohn.Forte@Sun.COM int
ql_abort_task_set(ql_adapter_state_t * ha,ql_tgt_t * tq,uint16_t lun)12157836SJohn.Forte@Sun.COM ql_abort_task_set(ql_adapter_state_t *ha, ql_tgt_t *tq, uint16_t lun)
12167836SJohn.Forte@Sun.COM {
12177836SJohn.Forte@Sun.COM 	int		rval;
12187836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
12197836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
12207836SJohn.Forte@Sun.COM 
12217836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
12227836SJohn.Forte@Sun.COM 
122311924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_24258081)) {
12247836SJohn.Forte@Sun.COM 		rval = ql_task_mgmt_iocb(ha, tq, lun, CF_ABORT_TASK_SET, 0);
12257836SJohn.Forte@Sun.COM 	} else {
12267836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_ABORT_TASK_SET;
12277836SJohn.Forte@Sun.COM 		if (CFG_IST(ha, CFG_EXT_FW_INTERFACE)) {
12287836SJohn.Forte@Sun.COM 			mcp->mb[1] = tq->loop_id;
12297836SJohn.Forte@Sun.COM 		} else {
12307836SJohn.Forte@Sun.COM 			mcp->mb[1] = (uint16_t)(tq->loop_id << 8);
12317836SJohn.Forte@Sun.COM 		}
12327836SJohn.Forte@Sun.COM 		mcp->mb[2] = lun;
12337836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_2|MBX_1|MBX_0;
12347836SJohn.Forte@Sun.COM 		mcp->in_mb = MBX_0;
12357836SJohn.Forte@Sun.COM 		mcp->timeout = MAILBOX_TOV;
12367836SJohn.Forte@Sun.COM 		rval = ql_mailbox_command(ha, mcp);
12377836SJohn.Forte@Sun.COM 	}
12387836SJohn.Forte@Sun.COM 
12397836SJohn.Forte@Sun.COM 	(void) ql_marker(ha, tq->loop_id, lun, MK_SYNC_ID);
12407836SJohn.Forte@Sun.COM 
12417836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
12427836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh, d_id=%xh\n", rval, tq->d_id.b24);
12437836SJohn.Forte@Sun.COM 	} else {
12447836SJohn.Forte@Sun.COM 		/*EMPTY*/
12457836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
12467836SJohn.Forte@Sun.COM 	}
12477836SJohn.Forte@Sun.COM 
12487836SJohn.Forte@Sun.COM 	return (rval);
12497836SJohn.Forte@Sun.COM }
12507836SJohn.Forte@Sun.COM 
12517836SJohn.Forte@Sun.COM /*
12527836SJohn.Forte@Sun.COM  * ql_task_mgmt_iocb
12537836SJohn.Forte@Sun.COM  *	Function issues task management IOCB.
12547836SJohn.Forte@Sun.COM  *
12557836SJohn.Forte@Sun.COM  * Input:
12567836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
12577836SJohn.Forte@Sun.COM  *	tq:	target queue pointer.
12587836SJohn.Forte@Sun.COM  *	lun:	LUN.
12597836SJohn.Forte@Sun.COM  *	flags:	control flags.
12607836SJohn.Forte@Sun.COM  *	delay:	seconds.
12617836SJohn.Forte@Sun.COM  *
12627836SJohn.Forte@Sun.COM  * Returns:
12637836SJohn.Forte@Sun.COM  *	ql local function return status code.
12647836SJohn.Forte@Sun.COM  *
12657836SJohn.Forte@Sun.COM  * Context:
12667836SJohn.Forte@Sun.COM  *	Kernel context
12677836SJohn.Forte@Sun.COM  */
12687836SJohn.Forte@Sun.COM static int
ql_task_mgmt_iocb(ql_adapter_state_t * ha,ql_tgt_t * tq,uint16_t lun,uint32_t flags,uint16_t delay)12697836SJohn.Forte@Sun.COM ql_task_mgmt_iocb(ql_adapter_state_t *ha, ql_tgt_t *tq, uint16_t lun,
12707836SJohn.Forte@Sun.COM     uint32_t flags, uint16_t delay)
12717836SJohn.Forte@Sun.COM {
12727836SJohn.Forte@Sun.COM 	ql_mbx_iocb_t	*pkt;
12737836SJohn.Forte@Sun.COM 	int		rval;
12747836SJohn.Forte@Sun.COM 	uint32_t	pkt_size;
12757836SJohn.Forte@Sun.COM 
12767836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
12777836SJohn.Forte@Sun.COM 
12787836SJohn.Forte@Sun.COM 	pkt_size = sizeof (ql_mbx_iocb_t);
12797836SJohn.Forte@Sun.COM 	pkt = kmem_zalloc(pkt_size, KM_SLEEP);
12807836SJohn.Forte@Sun.COM 	if (pkt == NULL) {
12817836SJohn.Forte@Sun.COM 		EL(ha, "failed, kmem_zalloc\n");
12827836SJohn.Forte@Sun.COM 		return (QL_MEMORY_ALLOC_FAILED);
12837836SJohn.Forte@Sun.COM 	}
12847836SJohn.Forte@Sun.COM 
12857836SJohn.Forte@Sun.COM 	pkt->mgmt.entry_type = TASK_MGMT_TYPE;
12867836SJohn.Forte@Sun.COM 	pkt->mgmt.entry_count = 1;
12877836SJohn.Forte@Sun.COM 
12887836SJohn.Forte@Sun.COM 	pkt->mgmt.n_port_hdl = (uint16_t)LE_16(tq->loop_id);
12897836SJohn.Forte@Sun.COM 	pkt->mgmt.delay = (uint16_t)LE_16(delay);
12907836SJohn.Forte@Sun.COM 	pkt->mgmt.timeout = LE_16(MAILBOX_TOV);
12917836SJohn.Forte@Sun.COM 	pkt->mgmt.fcp_lun[2] = LSB(lun);
12927836SJohn.Forte@Sun.COM 	pkt->mgmt.fcp_lun[3] = MSB(lun);
12937836SJohn.Forte@Sun.COM 	pkt->mgmt.control_flags = LE_32(flags);
12947836SJohn.Forte@Sun.COM 	pkt->mgmt.target_id[0] = tq->d_id.b.al_pa;
12957836SJohn.Forte@Sun.COM 	pkt->mgmt.target_id[1] = tq->d_id.b.area;
12967836SJohn.Forte@Sun.COM 	pkt->mgmt.target_id[2] = tq->d_id.b.domain;
12977836SJohn.Forte@Sun.COM 	pkt->mgmt.vp_index = ha->vp_index;
12987836SJohn.Forte@Sun.COM 
12997836SJohn.Forte@Sun.COM 	rval = ql_issue_mbx_iocb(ha, (caddr_t)pkt, pkt_size);
13007836SJohn.Forte@Sun.COM 	if (rval == QL_SUCCESS && (pkt->sts24.entry_status & 0x3c) != 0) {
13017836SJohn.Forte@Sun.COM 		EL(ha, "failed, entry_status=%xh, d_id=%xh\n",
13027836SJohn.Forte@Sun.COM 		    pkt->sts24.entry_status, tq->d_id.b24);
13037836SJohn.Forte@Sun.COM 		rval = QL_FUNCTION_PARAMETER_ERROR;
13047836SJohn.Forte@Sun.COM 	}
13057836SJohn.Forte@Sun.COM 
13067836SJohn.Forte@Sun.COM 	LITTLE_ENDIAN_16(&pkt->sts24.comp_status);
13077836SJohn.Forte@Sun.COM 
13087836SJohn.Forte@Sun.COM 	if (rval == QL_SUCCESS && pkt->sts24.comp_status != CS_COMPLETE) {
13097836SJohn.Forte@Sun.COM 		EL(ha, "failed, comp_status=%xh, d_id=%xh\n",
13107836SJohn.Forte@Sun.COM 		    pkt->sts24.comp_status, tq->d_id.b24);
13117836SJohn.Forte@Sun.COM 		rval = QL_FUNCTION_FAILED;
13127836SJohn.Forte@Sun.COM 	}
13137836SJohn.Forte@Sun.COM 
13147836SJohn.Forte@Sun.COM 	kmem_free(pkt, pkt_size);
13157836SJohn.Forte@Sun.COM 
13167836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
13177836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
13187836SJohn.Forte@Sun.COM 	} else {
13197836SJohn.Forte@Sun.COM 		/*EMPTY*/
13207836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
13217836SJohn.Forte@Sun.COM 	}
13227836SJohn.Forte@Sun.COM 
13237836SJohn.Forte@Sun.COM 	return (rval);
13247836SJohn.Forte@Sun.COM }
13257836SJohn.Forte@Sun.COM 
13267836SJohn.Forte@Sun.COM /*
13277836SJohn.Forte@Sun.COM  * ql_loop_port_bypass
13287836SJohn.Forte@Sun.COM  *	Issue loop port bypass mailbox command.
13297836SJohn.Forte@Sun.COM  *
13307836SJohn.Forte@Sun.COM  * Input:
13317836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
13327836SJohn.Forte@Sun.COM  *	tq:	target queue pointer.
13337836SJohn.Forte@Sun.COM  *
13347836SJohn.Forte@Sun.COM  * Returns:
13357836SJohn.Forte@Sun.COM  *	ql local function return status code.
13367836SJohn.Forte@Sun.COM  *
13377836SJohn.Forte@Sun.COM  * Context:
13387836SJohn.Forte@Sun.COM  *	Kernel context.
13397836SJohn.Forte@Sun.COM  */
13407836SJohn.Forte@Sun.COM int
ql_loop_port_bypass(ql_adapter_state_t * ha,ql_tgt_t * tq)13417836SJohn.Forte@Sun.COM ql_loop_port_bypass(ql_adapter_state_t *ha, ql_tgt_t *tq)
13427836SJohn.Forte@Sun.COM {
13437836SJohn.Forte@Sun.COM 	int		rval;
13447836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
13457836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
13467836SJohn.Forte@Sun.COM 
13477836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
13487836SJohn.Forte@Sun.COM 
13497836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_LOOP_PORT_BYPASS;
13507836SJohn.Forte@Sun.COM 
135111924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_24258081)) {
13527836SJohn.Forte@Sun.COM 		mcp->mb[1] = tq->d_id.b.al_pa;
13537836SJohn.Forte@Sun.COM 	} else if (CFG_IST(ha, CFG_EXT_FW_INTERFACE)) {
13547836SJohn.Forte@Sun.COM 		mcp->mb[1] = tq->loop_id;
13557836SJohn.Forte@Sun.COM 	} else {
13567836SJohn.Forte@Sun.COM 		mcp->mb[1] = (uint16_t)(tq->loop_id << 8);
13577836SJohn.Forte@Sun.COM 	}
13587836SJohn.Forte@Sun.COM 
13597836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_1|MBX_0;
13607836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0;
13617836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
13627836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
13637836SJohn.Forte@Sun.COM 
13647836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
13657836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh, d_id=%xh\n", rval, tq->d_id.b24);
13667836SJohn.Forte@Sun.COM 	} else {
13677836SJohn.Forte@Sun.COM 		/*EMPTY*/
13687836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
13697836SJohn.Forte@Sun.COM 	}
13707836SJohn.Forte@Sun.COM 
13717836SJohn.Forte@Sun.COM 	return (rval);
13727836SJohn.Forte@Sun.COM }
13737836SJohn.Forte@Sun.COM 
13747836SJohn.Forte@Sun.COM /*
13757836SJohn.Forte@Sun.COM  * ql_loop_port_enable
13767836SJohn.Forte@Sun.COM  *	Issue loop port enable mailbox command.
13777836SJohn.Forte@Sun.COM  *
13787836SJohn.Forte@Sun.COM  * Input:
13797836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
13807836SJohn.Forte@Sun.COM  *	tq:	target queue pointer.
13817836SJohn.Forte@Sun.COM  *
13827836SJohn.Forte@Sun.COM  * Returns:
13837836SJohn.Forte@Sun.COM  *	ql local function return status code.
13847836SJohn.Forte@Sun.COM  *
13857836SJohn.Forte@Sun.COM  * Context:
13867836SJohn.Forte@Sun.COM  *	Kernel context.
13877836SJohn.Forte@Sun.COM  */
13887836SJohn.Forte@Sun.COM int
ql_loop_port_enable(ql_adapter_state_t * ha,ql_tgt_t * tq)13897836SJohn.Forte@Sun.COM ql_loop_port_enable(ql_adapter_state_t *ha, ql_tgt_t *tq)
13907836SJohn.Forte@Sun.COM {
13917836SJohn.Forte@Sun.COM 	int		rval;
13927836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
13937836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
13947836SJohn.Forte@Sun.COM 
13957836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
13967836SJohn.Forte@Sun.COM 
13977836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_LOOP_PORT_ENABLE;
13987836SJohn.Forte@Sun.COM 
139911924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_24258081)) {
14007836SJohn.Forte@Sun.COM 		mcp->mb[1] = tq->d_id.b.al_pa;
14017836SJohn.Forte@Sun.COM 	} else if (CFG_IST(ha, CFG_EXT_FW_INTERFACE)) {
14027836SJohn.Forte@Sun.COM 		mcp->mb[1] = tq->loop_id;
14037836SJohn.Forte@Sun.COM 	} else {
14047836SJohn.Forte@Sun.COM 		mcp->mb[1] = (uint16_t)(tq->loop_id << 8);
14057836SJohn.Forte@Sun.COM 	}
14067836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_1|MBX_0;
14077836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0;
14087836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
14097836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
14107836SJohn.Forte@Sun.COM 
14117836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
14127836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh, d_id=%xh\n", rval, tq->d_id.b24);
14137836SJohn.Forte@Sun.COM 	} else {
14147836SJohn.Forte@Sun.COM 		/*EMPTY*/
14157836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
14167836SJohn.Forte@Sun.COM 	}
14177836SJohn.Forte@Sun.COM 
14187836SJohn.Forte@Sun.COM 	return (rval);
14197836SJohn.Forte@Sun.COM }
14207836SJohn.Forte@Sun.COM 
14217836SJohn.Forte@Sun.COM /*
14227836SJohn.Forte@Sun.COM  * ql_login_lport
14237836SJohn.Forte@Sun.COM  *	Issue login loop port mailbox command.
14247836SJohn.Forte@Sun.COM  *
14257836SJohn.Forte@Sun.COM  * Input:
14267836SJohn.Forte@Sun.COM  *	ha:		adapter state pointer.
14277836SJohn.Forte@Sun.COM  *	tq:		target queue pointer.
14287836SJohn.Forte@Sun.COM  *	loop_id:	FC loop id.
14297836SJohn.Forte@Sun.COM  *	opt:		options.
14307836SJohn.Forte@Sun.COM  *			LLF_NONE, LLF_PLOGI
14317836SJohn.Forte@Sun.COM  *
14327836SJohn.Forte@Sun.COM  * Returns:
14337836SJohn.Forte@Sun.COM  *	ql local function return status code.
14347836SJohn.Forte@Sun.COM  *
14357836SJohn.Forte@Sun.COM  * Context:
14367836SJohn.Forte@Sun.COM  *	Kernel context.
14377836SJohn.Forte@Sun.COM  */
14387836SJohn.Forte@Sun.COM int
ql_login_lport(ql_adapter_state_t * ha,ql_tgt_t * tq,uint16_t loop_id,uint16_t opt)14397836SJohn.Forte@Sun.COM ql_login_lport(ql_adapter_state_t *ha, ql_tgt_t *tq, uint16_t loop_id,
14407836SJohn.Forte@Sun.COM     uint16_t opt)
14417836SJohn.Forte@Sun.COM {
14427836SJohn.Forte@Sun.COM 	int		rval;
14437836SJohn.Forte@Sun.COM 	uint16_t	flags;
14447836SJohn.Forte@Sun.COM 	ql_mbx_data_t	mr;
14457836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
14467836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
14477836SJohn.Forte@Sun.COM 
14487836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started, d_id=%xh, loop_id=%xh\n",
14497836SJohn.Forte@Sun.COM 	    ha->instance, tq->d_id.b24, loop_id);
14507836SJohn.Forte@Sun.COM 
145111924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_24258081)) {
14527836SJohn.Forte@Sun.COM 		flags = CF_CMD_PLOGI;
14537836SJohn.Forte@Sun.COM 		if ((opt & LLF_PLOGI) == 0) {
14547836SJohn.Forte@Sun.COM 			flags = (uint16_t)(flags | CFO_COND_PLOGI);
14557836SJohn.Forte@Sun.COM 		}
14567836SJohn.Forte@Sun.COM 		rval = ql_log_iocb(ha, tq, loop_id, flags, &mr);
14577836SJohn.Forte@Sun.COM 	} else {
14587836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
14597836SJohn.Forte@Sun.COM 		if (CFG_IST(ha, CFG_EXT_FW_INTERFACE)) {
14607836SJohn.Forte@Sun.COM 			mcp->mb[1] = loop_id;
14617836SJohn.Forte@Sun.COM 		} else {
14627836SJohn.Forte@Sun.COM 			mcp->mb[1] = (uint16_t)(loop_id << 8);
14637836SJohn.Forte@Sun.COM 		}
14647836SJohn.Forte@Sun.COM 		mcp->mb[2] = opt;
14657836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_2|MBX_1|MBX_0;
14667836SJohn.Forte@Sun.COM 		mcp->in_mb = MBX_0;
14677836SJohn.Forte@Sun.COM 		mcp->timeout = MAILBOX_TOV;
14687836SJohn.Forte@Sun.COM 		rval = ql_mailbox_command(ha, mcp);
14697836SJohn.Forte@Sun.COM 	}
14707836SJohn.Forte@Sun.COM 
14717836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
14727836SJohn.Forte@Sun.COM 		EL(ha, "d_id=%xh, loop_id=%xh, failed=%xh\n", tq->d_id.b24,
14737836SJohn.Forte@Sun.COM 		    loop_id, rval);
14747836SJohn.Forte@Sun.COM 	} else {
14757836SJohn.Forte@Sun.COM 		/*EMPTY*/
14767836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
14777836SJohn.Forte@Sun.COM 	}
14787836SJohn.Forte@Sun.COM 
14797836SJohn.Forte@Sun.COM 	return (rval);
14807836SJohn.Forte@Sun.COM }
14817836SJohn.Forte@Sun.COM 
14827836SJohn.Forte@Sun.COM /*
14837836SJohn.Forte@Sun.COM  * ql_login_fport
14847836SJohn.Forte@Sun.COM  *	Issue login fabric port mailbox command.
14857836SJohn.Forte@Sun.COM  *
14867836SJohn.Forte@Sun.COM  * Input:
14877836SJohn.Forte@Sun.COM  *	ha:		adapter state pointer.
14887836SJohn.Forte@Sun.COM  *	tq:		target queue pointer.
14897836SJohn.Forte@Sun.COM  *	loop_id:	FC loop id.
14907836SJohn.Forte@Sun.COM  *	opt:		options.
14917836SJohn.Forte@Sun.COM  *			LFF_NONE, LFF_NO_PLOGI, LFF_NO_PRLI
14927836SJohn.Forte@Sun.COM  *	mr:		pointer for mailbox data.
14937836SJohn.Forte@Sun.COM  *
14947836SJohn.Forte@Sun.COM  * Returns:
14957836SJohn.Forte@Sun.COM  *	ql local function return status code.
14967836SJohn.Forte@Sun.COM  *
14977836SJohn.Forte@Sun.COM  * Context:
14987836SJohn.Forte@Sun.COM  *	Kernel context.
14997836SJohn.Forte@Sun.COM  */
15007836SJohn.Forte@Sun.COM int
ql_login_fport(ql_adapter_state_t * ha,ql_tgt_t * tq,uint16_t loop_id,uint16_t opt,ql_mbx_data_t * mr)15017836SJohn.Forte@Sun.COM ql_login_fport(ql_adapter_state_t *ha, ql_tgt_t *tq, uint16_t loop_id,
15027836SJohn.Forte@Sun.COM     uint16_t opt, ql_mbx_data_t *mr)
15037836SJohn.Forte@Sun.COM {
15047836SJohn.Forte@Sun.COM 	int		rval;
15057836SJohn.Forte@Sun.COM 	uint16_t	flags;
15067836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
15077836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
15087836SJohn.Forte@Sun.COM 
15097836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started, d_id=%xh, loop_id=%xh\n",
15107836SJohn.Forte@Sun.COM 	    ha->instance, tq->d_id.b24, loop_id);
15117836SJohn.Forte@Sun.COM 
15127836SJohn.Forte@Sun.COM 	if ((tq->d_id.b24 & 0xffffff) == 0xfffffa) {
15137836SJohn.Forte@Sun.COM 		opt = (uint16_t)(opt | LFF_NO_PRLI);
15147836SJohn.Forte@Sun.COM 	}
15157836SJohn.Forte@Sun.COM 
151611924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_24258081)) {
15177836SJohn.Forte@Sun.COM 		flags = CF_CMD_PLOGI;
15187836SJohn.Forte@Sun.COM 		if (opt & LFF_NO_PLOGI) {
15197836SJohn.Forte@Sun.COM 			flags = (uint16_t)(flags | CFO_COND_PLOGI);
15207836SJohn.Forte@Sun.COM 		}
15217836SJohn.Forte@Sun.COM 		if (opt & LFF_NO_PRLI) {
15227836SJohn.Forte@Sun.COM 			flags = (uint16_t)(flags | CFO_SKIP_PRLI);
15237836SJohn.Forte@Sun.COM 		}
15247836SJohn.Forte@Sun.COM 		rval = ql_log_iocb(ha, tq, loop_id, flags, mr);
15257836SJohn.Forte@Sun.COM 	} else {
15267836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
15277836SJohn.Forte@Sun.COM 		if (CFG_IST(ha, CFG_EXT_FW_INTERFACE)) {
15287836SJohn.Forte@Sun.COM 			mcp->mb[1] = loop_id;
15297836SJohn.Forte@Sun.COM 			mcp->mb[10] = opt;
15307836SJohn.Forte@Sun.COM 			mcp->out_mb = MBX_10|MBX_3|MBX_2|MBX_1|MBX_0;
15317836SJohn.Forte@Sun.COM 		} else {
15327836SJohn.Forte@Sun.COM 			mcp->mb[1] = (uint16_t)(loop_id << 8 | opt);
15337836SJohn.Forte@Sun.COM 			mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
15347836SJohn.Forte@Sun.COM 		}
15357836SJohn.Forte@Sun.COM 		mcp->mb[2] = MSW(tq->d_id.b24);
15367836SJohn.Forte@Sun.COM 		mcp->mb[3] = LSW(tq->d_id.b24);
15377836SJohn.Forte@Sun.COM 		mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
15387836SJohn.Forte@Sun.COM 		mcp->timeout = MAILBOX_TOV;
15397836SJohn.Forte@Sun.COM 		rval = ql_mailbox_command(ha, mcp);
15407836SJohn.Forte@Sun.COM 
15417836SJohn.Forte@Sun.COM 		/* Return mailbox data. */
15427836SJohn.Forte@Sun.COM 		if (mr != NULL) {
15437836SJohn.Forte@Sun.COM 			mr->mb[0] = mcp->mb[0];
15447836SJohn.Forte@Sun.COM 			mr->mb[1] = mcp->mb[1];
15457836SJohn.Forte@Sun.COM 			mr->mb[2] = mcp->mb[2];
15467836SJohn.Forte@Sun.COM 			mr->mb[6] = mcp->mb[6];
15477836SJohn.Forte@Sun.COM 			mr->mb[7] = mcp->mb[7];
15487836SJohn.Forte@Sun.COM 		}
15497836SJohn.Forte@Sun.COM 	}
15507836SJohn.Forte@Sun.COM 
15517836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
15527836SJohn.Forte@Sun.COM 		EL(ha, "d_id=%xh, loop_id=%xh, failed=%xh, mb1=%02xh, "
15537836SJohn.Forte@Sun.COM 		    "mb2=%04x\n", tq->d_id.b24, loop_id, rval, mr->mb[1],
15547836SJohn.Forte@Sun.COM 		    mr->mb[2]);
15557836SJohn.Forte@Sun.COM 	} else {
15567836SJohn.Forte@Sun.COM 		/*EMPTY*/
15577836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
15587836SJohn.Forte@Sun.COM 	}
15597836SJohn.Forte@Sun.COM 
15607836SJohn.Forte@Sun.COM 	return (rval);
15617836SJohn.Forte@Sun.COM }
15627836SJohn.Forte@Sun.COM 
15637836SJohn.Forte@Sun.COM /*
15647836SJohn.Forte@Sun.COM  * ql_logout_fabric_port
15657836SJohn.Forte@Sun.COM  *	Issue logout fabric port mailbox command.
15667836SJohn.Forte@Sun.COM  *
15677836SJohn.Forte@Sun.COM  * Input:
15687836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
15697836SJohn.Forte@Sun.COM  *	tq:	target queue pointer.
15707836SJohn.Forte@Sun.COM  *
15717836SJohn.Forte@Sun.COM  * Returns:
15727836SJohn.Forte@Sun.COM  *	ql local function return status code.
15737836SJohn.Forte@Sun.COM  *
15747836SJohn.Forte@Sun.COM  * Context:
15757836SJohn.Forte@Sun.COM  *	Kernel context.
15767836SJohn.Forte@Sun.COM  */
15777836SJohn.Forte@Sun.COM int
ql_logout_fabric_port(ql_adapter_state_t * ha,ql_tgt_t * tq)15787836SJohn.Forte@Sun.COM ql_logout_fabric_port(ql_adapter_state_t *ha, ql_tgt_t *tq)
15797836SJohn.Forte@Sun.COM {
15807836SJohn.Forte@Sun.COM 	int		rval;
15819446SDaniel.Beauregard@Sun.COM 	uint16_t	flag;
15827836SJohn.Forte@Sun.COM 	ql_mbx_data_t	mr;
15837836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
15847836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
15857836SJohn.Forte@Sun.COM 
15869446SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started, loop_id=%xh d_id=%xh\n",
15879446SDaniel.Beauregard@Sun.COM 	    ha->instance, tq->loop_id, tq->d_id.b24);
15889446SDaniel.Beauregard@Sun.COM 
158911924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_24258081)) {
15909446SDaniel.Beauregard@Sun.COM 		flag = (uint16_t)(RESERVED_LOOP_ID(ha, tq->loop_id) ?
15919446SDaniel.Beauregard@Sun.COM 		    CFO_EXPLICIT_LOGO |CF_CMD_LOGO | CFO_FREE_N_PORT_HANDLE :
15929446SDaniel.Beauregard@Sun.COM 		    CFO_IMPLICIT_LOGO |CF_CMD_LOGO | CFO_FREE_N_PORT_HANDLE);
15939446SDaniel.Beauregard@Sun.COM 		rval = ql_log_iocb(ha, tq, tq->loop_id, flag, &mr);
15947836SJohn.Forte@Sun.COM 	} else {
15959446SDaniel.Beauregard@Sun.COM 		flag = (uint16_t)(RESERVED_LOOP_ID(ha, tq->loop_id) ?  1 : 0);
15967836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
15977836SJohn.Forte@Sun.COM 		if (CFG_IST(ha, CFG_EXT_FW_INTERFACE)) {
15987836SJohn.Forte@Sun.COM 			mcp->mb[1] = tq->loop_id;
15999446SDaniel.Beauregard@Sun.COM 			mcp->mb[10] = flag;
16007836SJohn.Forte@Sun.COM 			mcp->out_mb = MBX_10|MBX_1|MBX_0;
16017836SJohn.Forte@Sun.COM 		} else {
16029446SDaniel.Beauregard@Sun.COM 			mcp->mb[1] = (uint16_t)(tq->loop_id << 8 | flag);
16037836SJohn.Forte@Sun.COM 			mcp->out_mb = MBX_1|MBX_0;
16047836SJohn.Forte@Sun.COM 		}
16057836SJohn.Forte@Sun.COM 		mcp->in_mb = MBX_0;
16067836SJohn.Forte@Sun.COM 		mcp->timeout = MAILBOX_TOV;
16077836SJohn.Forte@Sun.COM 		rval = ql_mailbox_command(ha, mcp);
16087836SJohn.Forte@Sun.COM 	}
16097836SJohn.Forte@Sun.COM 
16107836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
16117836SJohn.Forte@Sun.COM 		EL(ha, "d_id=%xh, loop_id=%xh, failed=%xh\n", rval,
16127836SJohn.Forte@Sun.COM 		    tq->d_id.b24, tq->loop_id);
16137836SJohn.Forte@Sun.COM 	} else {
16147836SJohn.Forte@Sun.COM 		/*EMPTY*/
16157836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
16167836SJohn.Forte@Sun.COM 	}
16177836SJohn.Forte@Sun.COM 
16187836SJohn.Forte@Sun.COM 	return (rval);
16197836SJohn.Forte@Sun.COM }
16207836SJohn.Forte@Sun.COM 
16217836SJohn.Forte@Sun.COM /*
16227836SJohn.Forte@Sun.COM  * ql_log_iocb
16237836SJohn.Forte@Sun.COM  *	Function issues login/logout IOCB.
16247836SJohn.Forte@Sun.COM  *
16257836SJohn.Forte@Sun.COM  * Input:
16267836SJohn.Forte@Sun.COM  *	ha:		adapter state pointer.
16277836SJohn.Forte@Sun.COM  *	tq:		target queue pointer.
16287836SJohn.Forte@Sun.COM  *	loop_id:	FC Loop ID.
16297836SJohn.Forte@Sun.COM  *	flags:		control flags.
16307836SJohn.Forte@Sun.COM  *	mr:		pointer for mailbox data.
16317836SJohn.Forte@Sun.COM  *
16327836SJohn.Forte@Sun.COM  * Returns:
16337836SJohn.Forte@Sun.COM  *	ql local function return status code.
16347836SJohn.Forte@Sun.COM  *
16357836SJohn.Forte@Sun.COM  * Context:
16367836SJohn.Forte@Sun.COM  *	Kernel context.
16377836SJohn.Forte@Sun.COM  */
16387836SJohn.Forte@Sun.COM int
ql_log_iocb(ql_adapter_state_t * ha,ql_tgt_t * tq,uint16_t loop_id,uint16_t flags,ql_mbx_data_t * mr)16397836SJohn.Forte@Sun.COM ql_log_iocb(ql_adapter_state_t *ha, ql_tgt_t *tq, uint16_t loop_id,
16407836SJohn.Forte@Sun.COM     uint16_t flags, ql_mbx_data_t *mr)
16417836SJohn.Forte@Sun.COM {
16427836SJohn.Forte@Sun.COM 	ql_mbx_iocb_t	*pkt;
16437836SJohn.Forte@Sun.COM 	int		rval;
16447836SJohn.Forte@Sun.COM 	uint32_t	pkt_size;
16457836SJohn.Forte@Sun.COM 
16467836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
16477836SJohn.Forte@Sun.COM 
16487836SJohn.Forte@Sun.COM 	pkt_size = sizeof (ql_mbx_iocb_t);
16497836SJohn.Forte@Sun.COM 	pkt = kmem_zalloc(pkt_size, KM_SLEEP);
16507836SJohn.Forte@Sun.COM 	if (pkt == NULL) {
16517836SJohn.Forte@Sun.COM 		EL(ha, "failed, kmem_zalloc\n");
16527836SJohn.Forte@Sun.COM 		return (QL_MEMORY_ALLOC_FAILED);
16537836SJohn.Forte@Sun.COM 	}
16547836SJohn.Forte@Sun.COM 
16557836SJohn.Forte@Sun.COM 	pkt->log.entry_type = LOG_TYPE;
16567836SJohn.Forte@Sun.COM 	pkt->log.entry_count = 1;
16577836SJohn.Forte@Sun.COM 	pkt->log.n_port_hdl = (uint16_t)LE_16(loop_id);
16587836SJohn.Forte@Sun.COM 	pkt->log.control_flags = (uint16_t)LE_16(flags);
16597836SJohn.Forte@Sun.COM 	pkt->log.port_id[0] = tq->d_id.b.al_pa;
16607836SJohn.Forte@Sun.COM 	pkt->log.port_id[1] = tq->d_id.b.area;
16617836SJohn.Forte@Sun.COM 	pkt->log.port_id[2] = tq->d_id.b.domain;
16627836SJohn.Forte@Sun.COM 	pkt->log.vp_index = ha->vp_index;
16637836SJohn.Forte@Sun.COM 
16647836SJohn.Forte@Sun.COM 	rval = ql_issue_mbx_iocb(ha, (caddr_t)pkt, pkt_size);
16657836SJohn.Forte@Sun.COM 	if (rval == QL_SUCCESS && (pkt->log.entry_status & 0x3c) != 0) {
16667836SJohn.Forte@Sun.COM 		EL(ha, "failed, entry_status=%xh, d_id=%xh\n",
16677836SJohn.Forte@Sun.COM 		    pkt->log.entry_status, tq->d_id.b24);
16687836SJohn.Forte@Sun.COM 		rval = QL_FUNCTION_PARAMETER_ERROR;
16697836SJohn.Forte@Sun.COM 	}
16707836SJohn.Forte@Sun.COM 
16717836SJohn.Forte@Sun.COM 	if (rval == QL_SUCCESS) {
16727836SJohn.Forte@Sun.COM 		if (pkt->log.rsp_size == 0xB) {
16737836SJohn.Forte@Sun.COM 			LITTLE_ENDIAN_32(&pkt->log.io_param[5]);
16747836SJohn.Forte@Sun.COM 			tq->cmn_features = MSW(pkt->log.io_param[5]);
16757836SJohn.Forte@Sun.COM 			LITTLE_ENDIAN_32(&pkt->log.io_param[6]);
16767836SJohn.Forte@Sun.COM 			tq->conc_sequences = MSW(pkt->log.io_param[6]);
16777836SJohn.Forte@Sun.COM 			tq->relative_offset = LSW(pkt->log.io_param[6]);
16787836SJohn.Forte@Sun.COM 			LITTLE_ENDIAN_32(&pkt->log.io_param[9]);
16797836SJohn.Forte@Sun.COM 			tq->class3_recipient_ctl = MSW(pkt->log.io_param[9]);
16807836SJohn.Forte@Sun.COM 			tq->class3_conc_sequences = LSW(pkt->log.io_param[9]);
16817836SJohn.Forte@Sun.COM 			LITTLE_ENDIAN_32(&pkt->log.io_param[10]);
16827836SJohn.Forte@Sun.COM 			tq->class3_open_sequences_per_exch =
16837836SJohn.Forte@Sun.COM 			    MSW(pkt->log.io_param[10]);
16847836SJohn.Forte@Sun.COM 			tq->prli_payload_length = 0x14;
16857836SJohn.Forte@Sun.COM 		}
16867836SJohn.Forte@Sun.COM 		if (mr != NULL) {
16877836SJohn.Forte@Sun.COM 			LITTLE_ENDIAN_16(&pkt->log.status);
16887836SJohn.Forte@Sun.COM 			LITTLE_ENDIAN_32(&pkt->log.io_param[0]);
16897836SJohn.Forte@Sun.COM 			LITTLE_ENDIAN_32(&pkt->log.io_param[1]);
16907836SJohn.Forte@Sun.COM 
16917836SJohn.Forte@Sun.COM 			if (pkt->log.status != CS_COMPLETE) {
16927836SJohn.Forte@Sun.COM 				EL(ha, "failed, status=%xh, iop0=%xh, iop1="
16937836SJohn.Forte@Sun.COM 				    "%xh\n", pkt->log.status,
16947836SJohn.Forte@Sun.COM 				    pkt->log.io_param[0],
16957836SJohn.Forte@Sun.COM 				    pkt->log.io_param[1]);
16967836SJohn.Forte@Sun.COM 
16977836SJohn.Forte@Sun.COM 				switch (pkt->log.io_param[0]) {
16987836SJohn.Forte@Sun.COM 				case CS0_NO_LINK:
16997836SJohn.Forte@Sun.COM 				case CS0_FIRMWARE_NOT_READY:
17007836SJohn.Forte@Sun.COM 					mr->mb[0] = MBS_COMMAND_ERROR;
17017836SJohn.Forte@Sun.COM 					mr->mb[1] = 1;
17027836SJohn.Forte@Sun.COM 					break;
17037836SJohn.Forte@Sun.COM 				case CS0_NO_IOCB:
17047836SJohn.Forte@Sun.COM 				case CS0_NO_PCB_ALLOCATED:
17057836SJohn.Forte@Sun.COM 					mr->mb[0] = MBS_COMMAND_ERROR;
17067836SJohn.Forte@Sun.COM 					mr->mb[1] = 2;
17077836SJohn.Forte@Sun.COM 					break;
17087836SJohn.Forte@Sun.COM 				case CS0_NO_EXCH_CTRL_BLK:
17097836SJohn.Forte@Sun.COM 					mr->mb[0] = MBS_COMMAND_ERROR;
17107836SJohn.Forte@Sun.COM 					mr->mb[1] = 3;
17117836SJohn.Forte@Sun.COM 					break;
17127836SJohn.Forte@Sun.COM 				case CS0_COMMAND_FAILED:
17137836SJohn.Forte@Sun.COM 					mr->mb[0] = MBS_COMMAND_ERROR;
17147836SJohn.Forte@Sun.COM 					mr->mb[1] = 4;
17157836SJohn.Forte@Sun.COM 					switch (LSB(pkt->log.io_param[1])) {
17167836SJohn.Forte@Sun.COM 					case CS1_PLOGI_RESPONSE_FAILED:
17177836SJohn.Forte@Sun.COM 						mr->mb[2] = 3;
17187836SJohn.Forte@Sun.COM 						break;
17197836SJohn.Forte@Sun.COM 					case CS1_PRLI_FAILED:
17207836SJohn.Forte@Sun.COM 						mr->mb[2] = 4;
17217836SJohn.Forte@Sun.COM 						break;
17227836SJohn.Forte@Sun.COM 					case CS1_PRLI_RESPONSE_FAILED:
17237836SJohn.Forte@Sun.COM 						mr->mb[2] = 5;
17247836SJohn.Forte@Sun.COM 						break;
17257836SJohn.Forte@Sun.COM 					case CS1_COMMAND_LOGGED_OUT:
17267836SJohn.Forte@Sun.COM 						mr->mb[2] = 7;
17277836SJohn.Forte@Sun.COM 						break;
17287836SJohn.Forte@Sun.COM 					case CS1_PLOGI_FAILED:
17297836SJohn.Forte@Sun.COM 					default:
17307836SJohn.Forte@Sun.COM 						EL(ha, "log iop1 = %xh\n",
17317836SJohn.Forte@Sun.COM 						    LSB(pkt->log.io_param[1]))
17327836SJohn.Forte@Sun.COM 						mr->mb[2] = 2;
17337836SJohn.Forte@Sun.COM 						break;
17347836SJohn.Forte@Sun.COM 					}
17357836SJohn.Forte@Sun.COM 					break;
17367836SJohn.Forte@Sun.COM 				case CS0_PORT_NOT_LOGGED_IN:
17377836SJohn.Forte@Sun.COM 					mr->mb[0] = MBS_COMMAND_ERROR;
17387836SJohn.Forte@Sun.COM 					mr->mb[1] = 4;
17397836SJohn.Forte@Sun.COM 					mr->mb[2] = 7;
17407836SJohn.Forte@Sun.COM 					break;
17417836SJohn.Forte@Sun.COM 				case CS0_NO_FLOGI_ACC:
17427836SJohn.Forte@Sun.COM 				case CS0_NO_FABRIC_PRESENT:
17437836SJohn.Forte@Sun.COM 					mr->mb[0] = MBS_COMMAND_ERROR;
17447836SJohn.Forte@Sun.COM 					mr->mb[1] = 5;
17457836SJohn.Forte@Sun.COM 					break;
17467836SJohn.Forte@Sun.COM 				case CS0_ELS_REJECT_RECEIVED:
17477836SJohn.Forte@Sun.COM 					mr->mb[0] = MBS_COMMAND_ERROR;
17487836SJohn.Forte@Sun.COM 					mr->mb[1] = 0xd;
17497836SJohn.Forte@Sun.COM 					break;
17507836SJohn.Forte@Sun.COM 				case CS0_PORT_ID_USED:
17517836SJohn.Forte@Sun.COM 					mr->mb[0] = MBS_PORT_ID_USED;
17527836SJohn.Forte@Sun.COM 					mr->mb[1] = LSW(pkt->log.io_param[1]);
17537836SJohn.Forte@Sun.COM 					break;
17547836SJohn.Forte@Sun.COM 				case CS0_N_PORT_HANDLE_USED:
17557836SJohn.Forte@Sun.COM 					mr->mb[0] = MBS_LOOP_ID_USED;
17567836SJohn.Forte@Sun.COM 					mr->mb[1] = MSW(pkt->log.io_param[1]);
17577836SJohn.Forte@Sun.COM 					mr->mb[2] = LSW(pkt->log.io_param[1]);
17587836SJohn.Forte@Sun.COM 					break;
17597836SJohn.Forte@Sun.COM 				case CS0_NO_N_PORT_HANDLE_AVAILABLE:
17607836SJohn.Forte@Sun.COM 					mr->mb[0] = MBS_ALL_IDS_IN_USE;
17617836SJohn.Forte@Sun.COM 					break;
17627836SJohn.Forte@Sun.COM 				case CS0_CMD_PARAMETER_ERROR:
17637836SJohn.Forte@Sun.COM 				default:
17647836SJohn.Forte@Sun.COM 					EL(ha, "pkt->log iop[0]=%xh\n",
17657836SJohn.Forte@Sun.COM 					    pkt->log.io_param[0]);
17667836SJohn.Forte@Sun.COM 					mr->mb[0] =
17677836SJohn.Forte@Sun.COM 					    MBS_COMMAND_PARAMETER_ERROR;
17687836SJohn.Forte@Sun.COM 					break;
17697836SJohn.Forte@Sun.COM 				}
17707836SJohn.Forte@Sun.COM 			} else {
17717836SJohn.Forte@Sun.COM 				QL_PRINT_3(CE_CONT, "(%d): status=%xh\n",
17727836SJohn.Forte@Sun.COM 				    ha->instance, pkt->log.status);
17737836SJohn.Forte@Sun.COM 
17747836SJohn.Forte@Sun.COM 				mr->mb[0] = MBS_COMMAND_COMPLETE;
17757836SJohn.Forte@Sun.COM 				mr->mb[1] = (uint16_t)
17767836SJohn.Forte@Sun.COM 				    (pkt->log.io_param[0] & BIT_4 ? 0 : BIT_0);
17777836SJohn.Forte@Sun.COM 				if (pkt->log.io_param[0] & BIT_8) {
17787836SJohn.Forte@Sun.COM 					mr->mb[1] = (uint16_t)
17797836SJohn.Forte@Sun.COM 					    (mr->mb[1] | BIT_1);
17807836SJohn.Forte@Sun.COM 				}
17817836SJohn.Forte@Sun.COM 			}
17827836SJohn.Forte@Sun.COM 			rval = mr->mb[0];
17837836SJohn.Forte@Sun.COM 		}
17847836SJohn.Forte@Sun.COM 
17857836SJohn.Forte@Sun.COM 	}
17867836SJohn.Forte@Sun.COM 
17877836SJohn.Forte@Sun.COM 	kmem_free(pkt, pkt_size);
17887836SJohn.Forte@Sun.COM 
17897836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
17907836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh, d_id=%xh\n", rval, tq->d_id.b24);
17917836SJohn.Forte@Sun.COM 	} else {
17927836SJohn.Forte@Sun.COM 		/*EMPTY*/
17937836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
17947836SJohn.Forte@Sun.COM 	}
17957836SJohn.Forte@Sun.COM 
17967836SJohn.Forte@Sun.COM 	return (rval);
17977836SJohn.Forte@Sun.COM }
17987836SJohn.Forte@Sun.COM 
17997836SJohn.Forte@Sun.COM /*
18007836SJohn.Forte@Sun.COM  * ql_get_port_database
18017836SJohn.Forte@Sun.COM  *	Issue get port database mailbox command
18027836SJohn.Forte@Sun.COM  *	and copy context to device queue.
18037836SJohn.Forte@Sun.COM  *
18047836SJohn.Forte@Sun.COM  * Input:
18057836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
18067836SJohn.Forte@Sun.COM  *	tq:	target queue pointer.
18077836SJohn.Forte@Sun.COM  *	opt:	options.
18087836SJohn.Forte@Sun.COM  *		PDF_NONE, PDF_PLOGI, PDF_ADISC
18097836SJohn.Forte@Sun.COM  * Returns:
18107836SJohn.Forte@Sun.COM  *	ql local function return status code.
18117836SJohn.Forte@Sun.COM  *
18127836SJohn.Forte@Sun.COM  * Context:
18137836SJohn.Forte@Sun.COM  *	Kernel context.
18147836SJohn.Forte@Sun.COM  */
18157836SJohn.Forte@Sun.COM int
ql_get_port_database(ql_adapter_state_t * ha,ql_tgt_t * tq,uint8_t opt)18167836SJohn.Forte@Sun.COM ql_get_port_database(ql_adapter_state_t *ha, ql_tgt_t *tq, uint8_t opt)
18177836SJohn.Forte@Sun.COM {
18187836SJohn.Forte@Sun.COM 	int			rval;
18197836SJohn.Forte@Sun.COM 	dma_mem_t		mem_desc;
18207836SJohn.Forte@Sun.COM 	mbx_cmd_t		mc = {0};
18217836SJohn.Forte@Sun.COM 	mbx_cmd_t		*mcp = &mc;
18227836SJohn.Forte@Sun.COM 	port_database_23_t	*pd23;
18237836SJohn.Forte@Sun.COM 
18247836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
18257836SJohn.Forte@Sun.COM 
18267836SJohn.Forte@Sun.COM 	pd23 = (port_database_23_t *)kmem_zalloc(PORT_DATABASE_SIZE, KM_SLEEP);
18277836SJohn.Forte@Sun.COM 	if (pd23 == NULL) {
18287836SJohn.Forte@Sun.COM 		rval = QL_MEMORY_ALLOC_FAILED;
18297836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
18307836SJohn.Forte@Sun.COM 		return (rval);
18317836SJohn.Forte@Sun.COM 	}
18327836SJohn.Forte@Sun.COM 
18337836SJohn.Forte@Sun.COM 	if ((rval = ql_setup_mbox_dma_resources(ha, &mem_desc,
18347836SJohn.Forte@Sun.COM 	    PORT_DATABASE_SIZE)) != QL_SUCCESS) {
18357836SJohn.Forte@Sun.COM 		return (QL_MEMORY_ALLOC_FAILED);
18367836SJohn.Forte@Sun.COM 	}
18377836SJohn.Forte@Sun.COM 
183811924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_24258081)) {
18397836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_GET_PORT_DATABASE;
18407836SJohn.Forte@Sun.COM 		mcp->mb[1] = tq->loop_id;
18417836SJohn.Forte@Sun.COM 		mcp->mb[4] = CHAR_TO_SHORT(tq->d_id.b.al_pa, tq->d_id.b.area);
18427836SJohn.Forte@Sun.COM 		mcp->mb[5] = (uint16_t)tq->d_id.b.domain;
18437836SJohn.Forte@Sun.COM 		mcp->mb[9] = ha->vp_index;
18447836SJohn.Forte@Sun.COM 		mcp->mb[10] = (uint16_t)(opt | PDF_ADISC);
18457836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_10|MBX_9|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|
18467836SJohn.Forte@Sun.COM 		    MBX_2|MBX_1|MBX_0;
18477836SJohn.Forte@Sun.COM 	} else {
18487836SJohn.Forte@Sun.COM 		mcp->mb[0] = (uint16_t)(opt == PDF_NONE ?
18497836SJohn.Forte@Sun.COM 		    MBC_GET_PORT_DATABASE : MBC_ENHANCED_GET_PORT_DATABASE);
18507836SJohn.Forte@Sun.COM 		if (CFG_IST(ha, CFG_EXT_FW_INTERFACE)) {
18517836SJohn.Forte@Sun.COM 			mcp->mb[1] = tq->loop_id;
18527836SJohn.Forte@Sun.COM 			mcp->mb[10] = opt;
18537836SJohn.Forte@Sun.COM 			mcp->out_mb = MBX_10|MBX_7|MBX_6|MBX_3|
18547836SJohn.Forte@Sun.COM 			    MBX_2|MBX_1|MBX_0;
18557836SJohn.Forte@Sun.COM 		} else {
18567836SJohn.Forte@Sun.COM 			mcp->mb[1] = (uint16_t)(tq->loop_id << 8 | opt);
18577836SJohn.Forte@Sun.COM 			mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
18587836SJohn.Forte@Sun.COM 		}
18597836SJohn.Forte@Sun.COM 	}
18607836SJohn.Forte@Sun.COM 
18617836SJohn.Forte@Sun.COM 	mcp->mb[2] = MSW(LSD(mem_desc.cookie.dmac_laddress));
18627836SJohn.Forte@Sun.COM 	mcp->mb[3] = LSW(LSD(mem_desc.cookie.dmac_laddress));
18637836SJohn.Forte@Sun.COM 	mcp->mb[6] = MSW(MSD(mem_desc.cookie.dmac_laddress));
18647836SJohn.Forte@Sun.COM 	mcp->mb[7] = LSW(MSD(mem_desc.cookie.dmac_laddress));
18657836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0;
18667836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
18677836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
18687836SJohn.Forte@Sun.COM 
18697836SJohn.Forte@Sun.COM 	if (rval == QL_SUCCESS) {
18707836SJohn.Forte@Sun.COM 		ql_get_mbox_dma_data(&mem_desc, (caddr_t)pd23);
18717836SJohn.Forte@Sun.COM 	}
18727836SJohn.Forte@Sun.COM 
18737836SJohn.Forte@Sun.COM 	ql_free_dma_resource(ha, &mem_desc);
18747836SJohn.Forte@Sun.COM 
18757836SJohn.Forte@Sun.COM 	if (rval == QL_SUCCESS) {
187611924SDaniel.Beauregard@Sun.COM 		if (CFG_IST(ha, CFG_CTRL_24258081)) {
18777836SJohn.Forte@Sun.COM 			port_database_24_t *pd24 = (port_database_24_t *)pd23;
18787836SJohn.Forte@Sun.COM 
18797836SJohn.Forte@Sun.COM 			tq->master_state = pd24->current_login_state;
18807836SJohn.Forte@Sun.COM 			tq->slave_state = pd24->last_stable_login_state;
18817836SJohn.Forte@Sun.COM 			if (PD_PORT_LOGIN(tq)) {
18827836SJohn.Forte@Sun.COM 				/* Names are big endian. */
18837836SJohn.Forte@Sun.COM 				bcopy((void *)&pd24->port_name[0],
18847836SJohn.Forte@Sun.COM 				    (void *)&tq->port_name[0], 8);
18857836SJohn.Forte@Sun.COM 				bcopy((void *)&pd24->node_name[0],
18867836SJohn.Forte@Sun.COM 				    (void *)&tq->node_name[0], 8);
18877836SJohn.Forte@Sun.COM 				tq->hard_addr.b.al_pa = pd24->hard_address[2];
18887836SJohn.Forte@Sun.COM 				tq->hard_addr.b.area = pd24->hard_address[1];
18897836SJohn.Forte@Sun.COM 				tq->hard_addr.b.domain = pd24->hard_address[0];
18907836SJohn.Forte@Sun.COM 				tq->class3_rcv_data_size =
18917836SJohn.Forte@Sun.COM 				    pd24->receive_data_size;
18927836SJohn.Forte@Sun.COM 				LITTLE_ENDIAN_16(&tq->class3_rcv_data_size);
18937836SJohn.Forte@Sun.COM 				tq->prli_svc_param_word_0 =
18947836SJohn.Forte@Sun.COM 				    pd24->PRLI_service_parameter_word_0;
18957836SJohn.Forte@Sun.COM 				LITTLE_ENDIAN_16(&tq->prli_svc_param_word_0);
18967836SJohn.Forte@Sun.COM 				tq->prli_svc_param_word_3 =
18977836SJohn.Forte@Sun.COM 				    pd24->PRLI_service_parameter_word_3;
18987836SJohn.Forte@Sun.COM 				LITTLE_ENDIAN_16(&tq->prli_svc_param_word_3);
18997836SJohn.Forte@Sun.COM 			}
19007836SJohn.Forte@Sun.COM 		} else {
19017836SJohn.Forte@Sun.COM 			tq->master_state = pd23->master_state;
19027836SJohn.Forte@Sun.COM 			tq->slave_state = pd23->slave_state;
19037836SJohn.Forte@Sun.COM 			if (PD_PORT_LOGIN(tq)) {
19047836SJohn.Forte@Sun.COM 				/* Names are big endian. */
19057836SJohn.Forte@Sun.COM 				bcopy((void *)&pd23->port_name[0],
19067836SJohn.Forte@Sun.COM 				    (void *)&tq->port_name[0], 8);
19077836SJohn.Forte@Sun.COM 				bcopy((void *)&pd23->node_name[0],
19087836SJohn.Forte@Sun.COM 				    (void *)&tq->node_name[0], 8);
19097836SJohn.Forte@Sun.COM 				tq->hard_addr.b.al_pa = pd23->hard_address[2];
19107836SJohn.Forte@Sun.COM 				tq->hard_addr.b.area = pd23->hard_address[1];
19117836SJohn.Forte@Sun.COM 				tq->hard_addr.b.domain = pd23->hard_address[0];
19127836SJohn.Forte@Sun.COM 				tq->cmn_features = pd23->common_features;
19137836SJohn.Forte@Sun.COM 				LITTLE_ENDIAN_16(&tq->cmn_features);
19147836SJohn.Forte@Sun.COM 				tq->conc_sequences =
19157836SJohn.Forte@Sun.COM 				    pd23->total_concurrent_sequences;
19167836SJohn.Forte@Sun.COM 				LITTLE_ENDIAN_16(&tq->conc_sequences);
19177836SJohn.Forte@Sun.COM 				tq->relative_offset =
19187836SJohn.Forte@Sun.COM 				    pd23->RO_by_information_category;
19197836SJohn.Forte@Sun.COM 				LITTLE_ENDIAN_16(&tq->relative_offset);
19207836SJohn.Forte@Sun.COM 				tq->class3_recipient_ctl = pd23->recipient;
19217836SJohn.Forte@Sun.COM 				LITTLE_ENDIAN_16(&tq->class3_recipient_ctl);
19227836SJohn.Forte@Sun.COM 				tq->class3_rcv_data_size =
19237836SJohn.Forte@Sun.COM 				    pd23->receive_data_size;
19247836SJohn.Forte@Sun.COM 				LITTLE_ENDIAN_16(&tq->class3_rcv_data_size);
19257836SJohn.Forte@Sun.COM 				tq->class3_conc_sequences =
19267836SJohn.Forte@Sun.COM 				    pd23->concurrent_sequences;
19277836SJohn.Forte@Sun.COM 				LITTLE_ENDIAN_16(&tq->class3_conc_sequences);
19287836SJohn.Forte@Sun.COM 				tq->class3_open_sequences_per_exch =
19297836SJohn.Forte@Sun.COM 				    pd23->open_sequences_per_exchange;
19307836SJohn.Forte@Sun.COM 				LITTLE_ENDIAN_16(
19317836SJohn.Forte@Sun.COM 				    &tq->class3_open_sequences_per_exch);
19327836SJohn.Forte@Sun.COM 				tq->prli_payload_length =
19337836SJohn.Forte@Sun.COM 				    pd23->PRLI_payload_length;
19347836SJohn.Forte@Sun.COM 				LITTLE_ENDIAN_16(&tq->prli_payload_length);
19357836SJohn.Forte@Sun.COM 				tq->prli_svc_param_word_0 =
19367836SJohn.Forte@Sun.COM 				    pd23->PRLI_service_parameter_word_0;
19377836SJohn.Forte@Sun.COM 				LITTLE_ENDIAN_16(&tq->prli_svc_param_word_0);
19387836SJohn.Forte@Sun.COM 				tq->prli_svc_param_word_3 =
19397836SJohn.Forte@Sun.COM 				    pd23->PRLI_service_parameter_word_3;
19407836SJohn.Forte@Sun.COM 				LITTLE_ENDIAN_16(&tq->prli_svc_param_word_3);
19417836SJohn.Forte@Sun.COM 			}
19427836SJohn.Forte@Sun.COM 		}
19437836SJohn.Forte@Sun.COM 
19447836SJohn.Forte@Sun.COM 		if (!PD_PORT_LOGIN(tq)) {
19457836SJohn.Forte@Sun.COM 			EL(ha, "d_id=%xh, loop_id=%xh, not logged in "
19467836SJohn.Forte@Sun.COM 			    "master=%xh, slave=%xh\n", tq->d_id.b24,
19477836SJohn.Forte@Sun.COM 			    tq->loop_id, tq->master_state, tq->slave_state);
19489156SDaniel.Beauregard@Sun.COM 			rval = QL_NOT_LOGGED_IN;
19497836SJohn.Forte@Sun.COM 		} else {
19509156SDaniel.Beauregard@Sun.COM 			tq->flags = tq->prli_svc_param_word_3 &
19519156SDaniel.Beauregard@Sun.COM 			    PRLI_W3_TARGET_FUNCTION ?
19527836SJohn.Forte@Sun.COM 			    tq->flags & ~TQF_INITIATOR_DEVICE :
19537836SJohn.Forte@Sun.COM 			    tq->flags | TQF_INITIATOR_DEVICE;
19547836SJohn.Forte@Sun.COM 
19557836SJohn.Forte@Sun.COM 			if ((tq->flags & TQF_INITIATOR_DEVICE) == 0) {
19569156SDaniel.Beauregard@Sun.COM 				tq->flags = tq->prli_svc_param_word_3 &
19579156SDaniel.Beauregard@Sun.COM 				    PRLI_W3_RETRY ?
19587836SJohn.Forte@Sun.COM 				    tq->flags | TQF_TAPE_DEVICE :
19597836SJohn.Forte@Sun.COM 				    tq->flags & ~TQF_TAPE_DEVICE;
19607836SJohn.Forte@Sun.COM 			} else {
19617836SJohn.Forte@Sun.COM 				tq->flags &= ~TQF_TAPE_DEVICE;
19627836SJohn.Forte@Sun.COM 			}
19637836SJohn.Forte@Sun.COM 		}
19647836SJohn.Forte@Sun.COM 	}
19657836SJohn.Forte@Sun.COM 
19667836SJohn.Forte@Sun.COM 	kmem_free(pd23, PORT_DATABASE_SIZE);
19677836SJohn.Forte@Sun.COM 
19689156SDaniel.Beauregard@Sun.COM 	if ((rval != QL_SUCCESS) && (rval != QL_PARAMETER_ERROR)) {
19697836SJohn.Forte@Sun.COM 		EL(ha, "d_id=%xh, loop_id=%xh, failed=%xh\n", tq->d_id.b24,
19707836SJohn.Forte@Sun.COM 		    tq->loop_id, rval);
19717836SJohn.Forte@Sun.COM 	} else {
19727836SJohn.Forte@Sun.COM 		/*EMPTY*/
19737836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
19747836SJohn.Forte@Sun.COM 	}
19757836SJohn.Forte@Sun.COM 
19767836SJohn.Forte@Sun.COM 	return (rval);
19777836SJohn.Forte@Sun.COM }
19787836SJohn.Forte@Sun.COM 
19797836SJohn.Forte@Sun.COM /*
19807836SJohn.Forte@Sun.COM  * ql_get_loop_position_map
19817836SJohn.Forte@Sun.COM  *	Issue get loop position map mailbox command.
19827836SJohn.Forte@Sun.COM  *
19837836SJohn.Forte@Sun.COM  * Input:
19847836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
19857836SJohn.Forte@Sun.COM  *	size:	size of data buffer.
19867836SJohn.Forte@Sun.COM  *	bufp:	data pointer for DMA data.
19877836SJohn.Forte@Sun.COM  *
19887836SJohn.Forte@Sun.COM  * Returns:
19897836SJohn.Forte@Sun.COM  *	ql local function return status code.
19907836SJohn.Forte@Sun.COM  *
19917836SJohn.Forte@Sun.COM  * Context:
19927836SJohn.Forte@Sun.COM  *	Kernel context.
19937836SJohn.Forte@Sun.COM  */
19947836SJohn.Forte@Sun.COM int
ql_get_loop_position_map(ql_adapter_state_t * ha,size_t size,caddr_t bufp)19957836SJohn.Forte@Sun.COM ql_get_loop_position_map(ql_adapter_state_t *ha, size_t size, caddr_t bufp)
19967836SJohn.Forte@Sun.COM {
19977836SJohn.Forte@Sun.COM 	int		rval;
19987836SJohn.Forte@Sun.COM 	dma_mem_t	mem_desc;
19997836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
20007836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
20017836SJohn.Forte@Sun.COM 
20027836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
20037836SJohn.Forte@Sun.COM 
20047836SJohn.Forte@Sun.COM 	if ((rval = ql_setup_mbox_dma_resources(ha, &mem_desc,
20057836SJohn.Forte@Sun.COM 	    (uint32_t)size)) != QL_SUCCESS) {
20067836SJohn.Forte@Sun.COM 		EL(ha, "setup_mbox_dma_resources failed: %xh\n", rval);
20077836SJohn.Forte@Sun.COM 		return (QL_MEMORY_ALLOC_FAILED);
20087836SJohn.Forte@Sun.COM 	}
20097836SJohn.Forte@Sun.COM 
20107836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
20117836SJohn.Forte@Sun.COM 	mcp->mb[2] = MSW(LSD(mem_desc.cookie.dmac_laddress));
20127836SJohn.Forte@Sun.COM 	mcp->mb[3] = LSW(LSD(mem_desc.cookie.dmac_laddress));
20137836SJohn.Forte@Sun.COM 	mcp->mb[6] = MSW(MSD(mem_desc.cookie.dmac_laddress));
20147836SJohn.Forte@Sun.COM 	mcp->mb[7] = LSW(MSD(mem_desc.cookie.dmac_laddress));
20157836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
20167836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_1|MBX_0;
20177836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
20187836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
20197836SJohn.Forte@Sun.COM 
20207836SJohn.Forte@Sun.COM 	if (rval == QL_SUCCESS) {
20217836SJohn.Forte@Sun.COM 		ql_get_mbox_dma_data(&mem_desc, bufp);
20227836SJohn.Forte@Sun.COM 	}
20237836SJohn.Forte@Sun.COM 
20247836SJohn.Forte@Sun.COM 	ql_free_dma_resource(ha, &mem_desc);
20257836SJohn.Forte@Sun.COM 
20267836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
20277836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
20287836SJohn.Forte@Sun.COM 	} else {
20297836SJohn.Forte@Sun.COM 		/*EMPTY*/
20307836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
20317836SJohn.Forte@Sun.COM 	}
20327836SJohn.Forte@Sun.COM 
20337836SJohn.Forte@Sun.COM 	return (rval);
20347836SJohn.Forte@Sun.COM }
20357836SJohn.Forte@Sun.COM 
20367836SJohn.Forte@Sun.COM /*
20377836SJohn.Forte@Sun.COM  * ql_set_rnid_params
20387836SJohn.Forte@Sun.COM  *	Issue set RNID parameters mailbox command.
20397836SJohn.Forte@Sun.COM  *
20407836SJohn.Forte@Sun.COM  * Input:
20417836SJohn.Forte@Sun.COM  *	ha:		adapter state pointer.
20427836SJohn.Forte@Sun.COM  *	size:		size of data buffer.
20437836SJohn.Forte@Sun.COM  *	bufp:		data pointer for DMA data.
20447836SJohn.Forte@Sun.COM  *
20457836SJohn.Forte@Sun.COM  * Returns:
20467836SJohn.Forte@Sun.COM  *	ql local function return status code.
20477836SJohn.Forte@Sun.COM  *
20487836SJohn.Forte@Sun.COM  * Context:
20497836SJohn.Forte@Sun.COM  *	Kernel context.
20507836SJohn.Forte@Sun.COM  */
20517836SJohn.Forte@Sun.COM int
ql_set_rnid_params(ql_adapter_state_t * ha,size_t size,caddr_t bufp)20527836SJohn.Forte@Sun.COM ql_set_rnid_params(ql_adapter_state_t *ha, size_t size, caddr_t bufp)
20537836SJohn.Forte@Sun.COM {
20547836SJohn.Forte@Sun.COM 	int		rval;
20557836SJohn.Forte@Sun.COM 	dma_mem_t	mem_desc;
20567836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
20577836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
20587836SJohn.Forte@Sun.COM 
20597836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
20607836SJohn.Forte@Sun.COM 
20617836SJohn.Forte@Sun.COM 	if ((rval = ql_setup_mbox_dma_transfer(ha, &mem_desc, bufp,
20627836SJohn.Forte@Sun.COM 	    (uint32_t)size)) != QL_SUCCESS) {
20637836SJohn.Forte@Sun.COM 		EL(ha, "failed, setup_mbox_dma_transfer: %x\n", rval);
20647836SJohn.Forte@Sun.COM 		return (rval);
20657836SJohn.Forte@Sun.COM 	}
20667836SJohn.Forte@Sun.COM 
20677836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_SET_PARAMETERS;
20687836SJohn.Forte@Sun.COM 	mcp->mb[2] = MSW(LSD(mem_desc.cookie.dmac_laddress));
20697836SJohn.Forte@Sun.COM 	mcp->mb[3] = LSW(LSD(mem_desc.cookie.dmac_laddress));
20707836SJohn.Forte@Sun.COM 	mcp->mb[6] = MSW(MSD(mem_desc.cookie.dmac_laddress));
20717836SJohn.Forte@Sun.COM 	mcp->mb[7] = LSW(MSD(mem_desc.cookie.dmac_laddress));
20727836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
20737836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0;
20747836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
20757836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
20767836SJohn.Forte@Sun.COM 
20777836SJohn.Forte@Sun.COM 	ql_free_dma_resource(ha, &mem_desc);
20787836SJohn.Forte@Sun.COM 
20797836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
20807836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
20817836SJohn.Forte@Sun.COM 	} else {
20827836SJohn.Forte@Sun.COM 		/*EMPTY*/
20837836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
20847836SJohn.Forte@Sun.COM 	}
20857836SJohn.Forte@Sun.COM 
20867836SJohn.Forte@Sun.COM 	return (rval);
20877836SJohn.Forte@Sun.COM }
20887836SJohn.Forte@Sun.COM 
20897836SJohn.Forte@Sun.COM /*
20907836SJohn.Forte@Sun.COM  * ql_send_rnid_els
20917836SJohn.Forte@Sun.COM  *	Issue a send node identfication data mailbox command.
20927836SJohn.Forte@Sun.COM  *
20937836SJohn.Forte@Sun.COM  * Input:
20947836SJohn.Forte@Sun.COM  *	ha:		adapter state pointer.
20957836SJohn.Forte@Sun.COM  *	loop_id:	FC loop id.
20967836SJohn.Forte@Sun.COM  *	opt:		options.
20977836SJohn.Forte@Sun.COM  *	size:		size of data buffer.
20987836SJohn.Forte@Sun.COM  *	bufp:		data pointer for DMA data.
20997836SJohn.Forte@Sun.COM  *
21007836SJohn.Forte@Sun.COM  * Returns:
21017836SJohn.Forte@Sun.COM  *	ql local function return status code.
21027836SJohn.Forte@Sun.COM  *
21037836SJohn.Forte@Sun.COM  * Context:
21047836SJohn.Forte@Sun.COM  *	Kernel context.
21057836SJohn.Forte@Sun.COM  */
21067836SJohn.Forte@Sun.COM int
ql_send_rnid_els(ql_adapter_state_t * ha,uint16_t loop_id,uint8_t opt,size_t size,caddr_t bufp)21077836SJohn.Forte@Sun.COM ql_send_rnid_els(ql_adapter_state_t *ha, uint16_t loop_id, uint8_t opt,
21087836SJohn.Forte@Sun.COM     size_t size, caddr_t bufp)
21097836SJohn.Forte@Sun.COM {
21107836SJohn.Forte@Sun.COM 	int		rval;
21117836SJohn.Forte@Sun.COM 	dma_mem_t	mem_desc;
21127836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
21137836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
21147836SJohn.Forte@Sun.COM 
21157836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
21167836SJohn.Forte@Sun.COM 
21177836SJohn.Forte@Sun.COM 	if ((rval = ql_setup_mbox_dma_resources(ha, &mem_desc,
21187836SJohn.Forte@Sun.COM 	    (uint32_t)size)) != QL_SUCCESS) {
21197836SJohn.Forte@Sun.COM 		return (QL_MEMORY_ALLOC_FAILED);
21207836SJohn.Forte@Sun.COM 	}
21217836SJohn.Forte@Sun.COM 
21227836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_SEND_RNID_ELS;
212311924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_24258081)) {
21247836SJohn.Forte@Sun.COM 		mcp->mb[1] = loop_id;
21257836SJohn.Forte@Sun.COM 		mcp->mb[9] = ha->vp_index;
21267836SJohn.Forte@Sun.COM 		mcp->mb[10] = opt;
21277836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_10|MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
21287836SJohn.Forte@Sun.COM 	} else if (CFG_IST(ha, CFG_EXT_FW_INTERFACE)) {
21297836SJohn.Forte@Sun.COM 		mcp->mb[1] = loop_id;
21307836SJohn.Forte@Sun.COM 		mcp->mb[10] = opt;
21317836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
21327836SJohn.Forte@Sun.COM 	} else {
21337836SJohn.Forte@Sun.COM 		mcp->mb[1] = (uint16_t)(loop_id << 8 | opt);
21347836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
21357836SJohn.Forte@Sun.COM 	}
21367836SJohn.Forte@Sun.COM 	mcp->mb[2] = MSW(LSD(mem_desc.cookie.dmac_laddress));
21377836SJohn.Forte@Sun.COM 	mcp->mb[3] = LSW(LSD(mem_desc.cookie.dmac_laddress));
21387836SJohn.Forte@Sun.COM 	mcp->mb[6] = MSW(MSD(mem_desc.cookie.dmac_laddress));
21397836SJohn.Forte@Sun.COM 	mcp->mb[7] = LSW(MSD(mem_desc.cookie.dmac_laddress));
21407836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0;
21417836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
21427836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
21437836SJohn.Forte@Sun.COM 
21447836SJohn.Forte@Sun.COM 	if (rval == QL_SUCCESS) {
21457836SJohn.Forte@Sun.COM 		ql_get_mbox_dma_data(&mem_desc, bufp);
21467836SJohn.Forte@Sun.COM 	}
21477836SJohn.Forte@Sun.COM 
21487836SJohn.Forte@Sun.COM 	ql_free_dma_resource(ha, &mem_desc);
21497836SJohn.Forte@Sun.COM 
21507836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
21517836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
21527836SJohn.Forte@Sun.COM 	} else {
21537836SJohn.Forte@Sun.COM 		/*EMPTY*/
21547836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
21557836SJohn.Forte@Sun.COM 	}
21567836SJohn.Forte@Sun.COM 
21577836SJohn.Forte@Sun.COM 	return (rval);
21587836SJohn.Forte@Sun.COM }
21597836SJohn.Forte@Sun.COM 
21607836SJohn.Forte@Sun.COM /*
21617836SJohn.Forte@Sun.COM  * ql_get_rnid_params
21627836SJohn.Forte@Sun.COM  *	Issue get RNID parameters mailbox command.
21637836SJohn.Forte@Sun.COM  *
21647836SJohn.Forte@Sun.COM  * Input:
21657836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
21667836SJohn.Forte@Sun.COM  *	size:	size of data buffer.
21677836SJohn.Forte@Sun.COM  *	bufp:	data pointer for DMA data.
21687836SJohn.Forte@Sun.COM  *
21697836SJohn.Forte@Sun.COM  * Returns:
21707836SJohn.Forte@Sun.COM  *	ql local function return status code.
21717836SJohn.Forte@Sun.COM  *
21727836SJohn.Forte@Sun.COM  * Context:
21737836SJohn.Forte@Sun.COM  *	Kernel context.
21747836SJohn.Forte@Sun.COM  */
21757836SJohn.Forte@Sun.COM int
ql_get_rnid_params(ql_adapter_state_t * ha,size_t size,caddr_t bufp)21767836SJohn.Forte@Sun.COM ql_get_rnid_params(ql_adapter_state_t *ha, size_t size, caddr_t bufp)
21777836SJohn.Forte@Sun.COM {
21787836SJohn.Forte@Sun.COM 	int		rval;
21797836SJohn.Forte@Sun.COM 	dma_mem_t	mem_desc;
21807836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
21817836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
21827836SJohn.Forte@Sun.COM 
21837836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
21847836SJohn.Forte@Sun.COM 
21857836SJohn.Forte@Sun.COM 	if ((rval = ql_setup_mbox_dma_resources(ha, &mem_desc,
21867836SJohn.Forte@Sun.COM 	    (uint32_t)size)) != QL_SUCCESS) {
21877836SJohn.Forte@Sun.COM 		return (QL_MEMORY_ALLOC_FAILED);
21887836SJohn.Forte@Sun.COM 	}
21897836SJohn.Forte@Sun.COM 
21907836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_GET_PARAMETERS;
21917836SJohn.Forte@Sun.COM 	mcp->mb[2] = MSW(LSD(mem_desc.cookie.dmac_laddress));
21927836SJohn.Forte@Sun.COM 	mcp->mb[3] = LSW(LSD(mem_desc.cookie.dmac_laddress));
21937836SJohn.Forte@Sun.COM 	mcp->mb[6] = MSW(MSD(mem_desc.cookie.dmac_laddress));
21947836SJohn.Forte@Sun.COM 	mcp->mb[7] = LSW(MSD(mem_desc.cookie.dmac_laddress));
21957836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
21967836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0;
21977836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
21987836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
21997836SJohn.Forte@Sun.COM 
22007836SJohn.Forte@Sun.COM 	if (rval == QL_SUCCESS) {
22017836SJohn.Forte@Sun.COM 		ql_get_mbox_dma_data(&mem_desc, bufp);
22027836SJohn.Forte@Sun.COM 	}
22037836SJohn.Forte@Sun.COM 
22047836SJohn.Forte@Sun.COM 	ql_free_dma_resource(ha, &mem_desc);
22057836SJohn.Forte@Sun.COM 
22067836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
22077836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
22087836SJohn.Forte@Sun.COM 	} else {
22097836SJohn.Forte@Sun.COM 		/*EMPTY*/
22107836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
22117836SJohn.Forte@Sun.COM 	}
22127836SJohn.Forte@Sun.COM 
22137836SJohn.Forte@Sun.COM 	return (rval);
22147836SJohn.Forte@Sun.COM }
22157836SJohn.Forte@Sun.COM 
22167836SJohn.Forte@Sun.COM /*
22177836SJohn.Forte@Sun.COM  * ql_get_link_status
22187836SJohn.Forte@Sun.COM  *	Issue get link status mailbox command.
22197836SJohn.Forte@Sun.COM  *
22207836SJohn.Forte@Sun.COM  * Input:
22217836SJohn.Forte@Sun.COM  *	ha:		adapter state pointer.
22227836SJohn.Forte@Sun.COM  *	loop_id:	FC loop id or n_port_hdl.
22237836SJohn.Forte@Sun.COM  *	size:		size of data buffer.
22247836SJohn.Forte@Sun.COM  *	bufp:		data pointer for DMA data.
22257836SJohn.Forte@Sun.COM  *	port_no:	port number to query.
22267836SJohn.Forte@Sun.COM  *
22277836SJohn.Forte@Sun.COM  * Returns:
22287836SJohn.Forte@Sun.COM  *	ql local function return status code.
22297836SJohn.Forte@Sun.COM  *
22307836SJohn.Forte@Sun.COM  * Context:
22317836SJohn.Forte@Sun.COM  *	Kernel context.
22327836SJohn.Forte@Sun.COM  */
22337836SJohn.Forte@Sun.COM int
ql_get_link_status(ql_adapter_state_t * ha,uint16_t loop_id,size_t size,caddr_t bufp,uint8_t port_no)22347836SJohn.Forte@Sun.COM ql_get_link_status(ql_adapter_state_t *ha, uint16_t loop_id, size_t size,
22357836SJohn.Forte@Sun.COM     caddr_t bufp, uint8_t port_no)
22367836SJohn.Forte@Sun.COM {
22377836SJohn.Forte@Sun.COM 	dma_mem_t	mem_desc;
22387836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
22397836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
22407836SJohn.Forte@Sun.COM 	int		rval = QL_SUCCESS;
22417836SJohn.Forte@Sun.COM 	int		retry = 0;
22427836SJohn.Forte@Sun.COM 
22437836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
22447836SJohn.Forte@Sun.COM 
22457836SJohn.Forte@Sun.COM 	do {
22467836SJohn.Forte@Sun.COM 		if ((rval = ql_setup_mbox_dma_resources(ha, &mem_desc,
22477836SJohn.Forte@Sun.COM 		    (uint32_t)size)) != QL_SUCCESS) {
22487836SJohn.Forte@Sun.COM 			EL(ha, "setup_mbox_dma_resources failed: %xh\n", rval);
22497836SJohn.Forte@Sun.COM 			return (QL_MEMORY_ALLOC_FAILED);
22507836SJohn.Forte@Sun.COM 		}
22517836SJohn.Forte@Sun.COM 
22527836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_GET_LINK_STATUS;
225311924SDaniel.Beauregard@Sun.COM 		if (CFG_IST(ha, CFG_CTRL_24258081)) {
22547836SJohn.Forte@Sun.COM 			if (loop_id == ha->loop_id) {
22557836SJohn.Forte@Sun.COM 				mcp->mb[0] = MBC_GET_STATUS_COUNTS;
22567836SJohn.Forte@Sun.COM 				mcp->mb[8] = (uint16_t)(size >> 2);
22577836SJohn.Forte@Sun.COM 				mcp->out_mb = MBX_10|MBX_8;
22587836SJohn.Forte@Sun.COM 			} else {
22597836SJohn.Forte@Sun.COM 				mcp->mb[1] = loop_id;
22607836SJohn.Forte@Sun.COM 				mcp->mb[4] = port_no;
22617836SJohn.Forte@Sun.COM 				mcp->mb[10] = (uint16_t)(retry ? BIT_3 : 0);
22627836SJohn.Forte@Sun.COM 				mcp->out_mb = MBX_10|MBX_4;
22637836SJohn.Forte@Sun.COM 			}
22647836SJohn.Forte@Sun.COM 		} else {
22657836SJohn.Forte@Sun.COM 			if (retry) {
22667836SJohn.Forte@Sun.COM 				port_no = (uint8_t)(port_no | BIT_3);
22677836SJohn.Forte@Sun.COM 			}
22687836SJohn.Forte@Sun.COM 			if (CFG_IST(ha, CFG_EXT_FW_INTERFACE)) {
22697836SJohn.Forte@Sun.COM 				mcp->mb[1] = loop_id;
22707836SJohn.Forte@Sun.COM 				mcp->mb[10] = port_no;
22717836SJohn.Forte@Sun.COM 				mcp->out_mb = MBX_10;
22727836SJohn.Forte@Sun.COM 			} else {
22737836SJohn.Forte@Sun.COM 				mcp->mb[1] = (uint16_t)((loop_id << 8) |
22747836SJohn.Forte@Sun.COM 				    port_no);
22757836SJohn.Forte@Sun.COM 				mcp->out_mb = 0;
22767836SJohn.Forte@Sun.COM 			}
22777836SJohn.Forte@Sun.COM 		}
22787836SJohn.Forte@Sun.COM 		mcp->mb[2] = MSW(LSD(mem_desc.cookie.dmac_laddress));
22797836SJohn.Forte@Sun.COM 		mcp->mb[3] = LSW(LSD(mem_desc.cookie.dmac_laddress));
22807836SJohn.Forte@Sun.COM 		mcp->mb[6] = MSW(MSD(mem_desc.cookie.dmac_laddress));
22817836SJohn.Forte@Sun.COM 		mcp->mb[7] = LSW(MSD(mem_desc.cookie.dmac_laddress));
22827836SJohn.Forte@Sun.COM 		mcp->in_mb = MBX_1|MBX_0;
22837836SJohn.Forte@Sun.COM 		mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
22847836SJohn.Forte@Sun.COM 		mcp->timeout = MAILBOX_TOV;
22857836SJohn.Forte@Sun.COM 
22867836SJohn.Forte@Sun.COM 		rval = ql_mailbox_command(ha, mcp);
22877836SJohn.Forte@Sun.COM 
22887836SJohn.Forte@Sun.COM 		if (rval == QL_SUCCESS) {
22897836SJohn.Forte@Sun.COM 			ql_get_mbox_dma_data(&mem_desc, bufp);
22907836SJohn.Forte@Sun.COM 		}
22917836SJohn.Forte@Sun.COM 
22927836SJohn.Forte@Sun.COM 		ql_free_dma_resource(ha, &mem_desc);
22937836SJohn.Forte@Sun.COM 
22947836SJohn.Forte@Sun.COM 		if (rval != QL_SUCCESS) {
22957836SJohn.Forte@Sun.COM 			EL(ha, "failed=%xh, mbx1=%xh\n", rval, mcp->mb[1]);
22967836SJohn.Forte@Sun.COM 		}
22977836SJohn.Forte@Sun.COM 
22987836SJohn.Forte@Sun.COM 		/*
22997836SJohn.Forte@Sun.COM 		 * Some of the devices want d_id in the payload,
23007836SJohn.Forte@Sun.COM 		 * strictly as per standard. Let's retry.
23017836SJohn.Forte@Sun.COM 		 */
23027836SJohn.Forte@Sun.COM 
23037836SJohn.Forte@Sun.COM 	} while (rval == QL_COMMAND_ERROR && !retry++);
23047836SJohn.Forte@Sun.COM 
23057836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
23067836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh, mbx1=%xh\n", rval, mcp->mb[1]);
23077836SJohn.Forte@Sun.COM 	} else {
23087836SJohn.Forte@Sun.COM 		/*EMPTY*/
23097836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
23107836SJohn.Forte@Sun.COM 	}
23117836SJohn.Forte@Sun.COM 
23127836SJohn.Forte@Sun.COM 	return (rval);
23137836SJohn.Forte@Sun.COM }
23147836SJohn.Forte@Sun.COM 
23157836SJohn.Forte@Sun.COM /*
23167836SJohn.Forte@Sun.COM  * ql_get_status_counts
23177836SJohn.Forte@Sun.COM  *	Issue get adapter link status counts mailbox command.
23187836SJohn.Forte@Sun.COM  *
23197836SJohn.Forte@Sun.COM  * Input:
23207836SJohn.Forte@Sun.COM  *	ha:		adapter state pointer.
23217836SJohn.Forte@Sun.COM  *	loop_id:	FC loop id or n_port_hdl.
23227836SJohn.Forte@Sun.COM  *	size:		size of data buffer.
23237836SJohn.Forte@Sun.COM  *	bufp:		data pointer for DMA data.
23247836SJohn.Forte@Sun.COM  *	port_no:	port number to query.
23257836SJohn.Forte@Sun.COM  *
23267836SJohn.Forte@Sun.COM  * Returns:
23277836SJohn.Forte@Sun.COM  *	ql local function return status code.
23287836SJohn.Forte@Sun.COM  *
23297836SJohn.Forte@Sun.COM  * Context:
23307836SJohn.Forte@Sun.COM  *	Kernel context.
23317836SJohn.Forte@Sun.COM  */
23327836SJohn.Forte@Sun.COM int
ql_get_status_counts(ql_adapter_state_t * ha,uint16_t loop_id,size_t size,caddr_t bufp,uint8_t port_no)23337836SJohn.Forte@Sun.COM ql_get_status_counts(ql_adapter_state_t *ha, uint16_t loop_id, size_t size,
23347836SJohn.Forte@Sun.COM     caddr_t bufp, uint8_t port_no)
23357836SJohn.Forte@Sun.COM {
23367836SJohn.Forte@Sun.COM 	dma_mem_t	mem_desc;
23377836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
23387836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
23397836SJohn.Forte@Sun.COM 	int		rval = QL_SUCCESS;
23407836SJohn.Forte@Sun.COM 
23417836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
23427836SJohn.Forte@Sun.COM 
23437836SJohn.Forte@Sun.COM 	if ((rval = ql_setup_mbox_dma_resources(ha, &mem_desc,
23447836SJohn.Forte@Sun.COM 	    (uint32_t)size)) != QL_SUCCESS) {
23457836SJohn.Forte@Sun.COM 		EL(ha, "setup_mbox_dma_resources failed: %x\n", rval);
23467836SJohn.Forte@Sun.COM 		return (QL_MEMORY_ALLOC_FAILED);
23477836SJohn.Forte@Sun.COM 	}
23487836SJohn.Forte@Sun.COM 
234911924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_24258081)) {
23507836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_GET_STATUS_COUNTS;
23517836SJohn.Forte@Sun.COM 		mcp->mb[8] = (uint16_t)(size / 4);
23527836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_10|MBX_8;
23537836SJohn.Forte@Sun.COM 	} else {
23547836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_GET_LINK_STATUS;
23557836SJohn.Forte@Sun.COM 
23567836SJohn.Forte@Sun.COM 		/* allows reporting when link is down */
23577836SJohn.Forte@Sun.COM 		if (CFG_IST(ha, CFG_CTRL_2200) == 0) {
23587836SJohn.Forte@Sun.COM 			port_no = (uint8_t)(port_no | BIT_6);
23597836SJohn.Forte@Sun.COM 		}
23607836SJohn.Forte@Sun.COM 
23617836SJohn.Forte@Sun.COM 		if (CFG_IST(ha, CFG_EXT_FW_INTERFACE)) {
23627836SJohn.Forte@Sun.COM 			mcp->mb[1] = loop_id;
23637836SJohn.Forte@Sun.COM 			mcp->mb[10] = port_no;
23647836SJohn.Forte@Sun.COM 			mcp->out_mb = MBX_10|MBX_1;
23657836SJohn.Forte@Sun.COM 		} else {
23667836SJohn.Forte@Sun.COM 			mcp->mb[1] = (uint16_t)((loop_id << 8) |
23677836SJohn.Forte@Sun.COM 			    port_no);
23687836SJohn.Forte@Sun.COM 			mcp->out_mb = MBX_1;
23697836SJohn.Forte@Sun.COM 		}
23707836SJohn.Forte@Sun.COM 	}
23717836SJohn.Forte@Sun.COM 	mcp->mb[2] = MSW(LSD(mem_desc.cookie.dmac_laddress));
23727836SJohn.Forte@Sun.COM 	mcp->mb[3] = LSW(LSD(mem_desc.cookie.dmac_laddress));
23737836SJohn.Forte@Sun.COM 	mcp->mb[6] = MSW(MSD(mem_desc.cookie.dmac_laddress));
23747836SJohn.Forte@Sun.COM 	mcp->mb[7] = LSW(MSD(mem_desc.cookie.dmac_laddress));
23757836SJohn.Forte@Sun.COM 	mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
23767836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_2|MBX_1|MBX_0;
23777836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
23787836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
23797836SJohn.Forte@Sun.COM 
23807836SJohn.Forte@Sun.COM 	if (rval == QL_SUCCESS) {
23817836SJohn.Forte@Sun.COM 		ql_get_mbox_dma_data(&mem_desc, bufp);
23827836SJohn.Forte@Sun.COM 	}
23837836SJohn.Forte@Sun.COM 
23847836SJohn.Forte@Sun.COM 	ql_free_dma_resource(ha, &mem_desc);
23857836SJohn.Forte@Sun.COM 
23867836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
23877836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh, mbx1=%xh, mbx2=%xh\n", rval,
23887836SJohn.Forte@Sun.COM 		    mcp->mb[1], mcp->mb[2]);
23897836SJohn.Forte@Sun.COM 	} else {
23907836SJohn.Forte@Sun.COM 		/*EMPTY*/
23917836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
23927836SJohn.Forte@Sun.COM 	}
23937836SJohn.Forte@Sun.COM 
23947836SJohn.Forte@Sun.COM 	return (rval);
23957836SJohn.Forte@Sun.COM }
23967836SJohn.Forte@Sun.COM 
23977836SJohn.Forte@Sun.COM /*
23987836SJohn.Forte@Sun.COM  * ql_reset_link_status
23997836SJohn.Forte@Sun.COM  *	Issue Reset Link Error Status mailbox command
24007836SJohn.Forte@Sun.COM  *
24017836SJohn.Forte@Sun.COM  * Input:
24027836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
24037836SJohn.Forte@Sun.COM  *
24047836SJohn.Forte@Sun.COM  * Returns:
24057836SJohn.Forte@Sun.COM  *	ql local function return status code.
24067836SJohn.Forte@Sun.COM  *
24077836SJohn.Forte@Sun.COM  * Context:
24087836SJohn.Forte@Sun.COM  *	Kernel context.
24097836SJohn.Forte@Sun.COM  */
24107836SJohn.Forte@Sun.COM int
ql_reset_link_status(ql_adapter_state_t * ha)24117836SJohn.Forte@Sun.COM ql_reset_link_status(ql_adapter_state_t *ha)
24127836SJohn.Forte@Sun.COM {
24137836SJohn.Forte@Sun.COM 	int		rval;
24147836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
24157836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
24167836SJohn.Forte@Sun.COM 
24179446SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
24187836SJohn.Forte@Sun.COM 
24197836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_RESET_LINK_STATUS;
24207836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_0;
24217836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0;
24227836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
24237836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
24247836SJohn.Forte@Sun.COM 
24257836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
24267836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
24277836SJohn.Forte@Sun.COM 	} else {
24287836SJohn.Forte@Sun.COM 		/*EMPTY*/
24297836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
24307836SJohn.Forte@Sun.COM 	}
24317836SJohn.Forte@Sun.COM 
24327836SJohn.Forte@Sun.COM 	return (rval);
24337836SJohn.Forte@Sun.COM }
24347836SJohn.Forte@Sun.COM 
24357836SJohn.Forte@Sun.COM /*
24367836SJohn.Forte@Sun.COM  * ql_loop_reset
24377836SJohn.Forte@Sun.COM  *	Issue loop reset.
24387836SJohn.Forte@Sun.COM  *
24397836SJohn.Forte@Sun.COM  * Input:
24407836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
24417836SJohn.Forte@Sun.COM  *
24427836SJohn.Forte@Sun.COM  * Returns:
24437836SJohn.Forte@Sun.COM  *	ql local function return status code.
24447836SJohn.Forte@Sun.COM  *
24457836SJohn.Forte@Sun.COM  * Context:
24467836SJohn.Forte@Sun.COM  *	Kernel context.
24477836SJohn.Forte@Sun.COM  */
24487836SJohn.Forte@Sun.COM int
ql_loop_reset(ql_adapter_state_t * ha)24497836SJohn.Forte@Sun.COM ql_loop_reset(ql_adapter_state_t *ha)
24507836SJohn.Forte@Sun.COM {
24517836SJohn.Forte@Sun.COM 	int	rval;
24527836SJohn.Forte@Sun.COM 
24537836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
24547836SJohn.Forte@Sun.COM 
24557836SJohn.Forte@Sun.COM 	if (CFG_IST(ha, CFG_ENABLE_LIP_RESET)) {
24567836SJohn.Forte@Sun.COM 		rval = ql_lip_reset(ha, 0xff);
24577836SJohn.Forte@Sun.COM 	} else if (CFG_IST(ha, CFG_ENABLE_FULL_LIP_LOGIN)) {
24587836SJohn.Forte@Sun.COM 		rval = ql_full_login_lip(ha);
24597836SJohn.Forte@Sun.COM 	} else if (CFG_IST(ha, CFG_ENABLE_TARGET_RESET)) {
24607836SJohn.Forte@Sun.COM 		rval = ql_target_reset(ha, NULL, ha->loop_reset_delay);
24617836SJohn.Forte@Sun.COM 	} else {
24627836SJohn.Forte@Sun.COM 		rval = ql_initiate_lip(ha);
24637836SJohn.Forte@Sun.COM 	}
24647836SJohn.Forte@Sun.COM 
24657836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
24667836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
24677836SJohn.Forte@Sun.COM 	} else {
24687836SJohn.Forte@Sun.COM 		/*EMPTY*/
24697836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
24707836SJohn.Forte@Sun.COM 	}
24717836SJohn.Forte@Sun.COM 
24727836SJohn.Forte@Sun.COM 	return (rval);
24737836SJohn.Forte@Sun.COM }
24747836SJohn.Forte@Sun.COM 
24757836SJohn.Forte@Sun.COM /*
24767836SJohn.Forte@Sun.COM  * ql_initiate_lip
24777836SJohn.Forte@Sun.COM  *	Initiate LIP mailbox command.
24787836SJohn.Forte@Sun.COM  *
24797836SJohn.Forte@Sun.COM  * Input:
24807836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
24817836SJohn.Forte@Sun.COM  *
24827836SJohn.Forte@Sun.COM  * Returns:
24837836SJohn.Forte@Sun.COM  *	ql local function return status code.
24847836SJohn.Forte@Sun.COM  *
24857836SJohn.Forte@Sun.COM  * Context:
24867836SJohn.Forte@Sun.COM  *	Kernel context.
24877836SJohn.Forte@Sun.COM  */
24887836SJohn.Forte@Sun.COM int
ql_initiate_lip(ql_adapter_state_t * ha)24897836SJohn.Forte@Sun.COM ql_initiate_lip(ql_adapter_state_t *ha)
24907836SJohn.Forte@Sun.COM {
24917836SJohn.Forte@Sun.COM 	int		rval;
24927836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
24937836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
24947836SJohn.Forte@Sun.COM 
24957836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
24967836SJohn.Forte@Sun.COM 
249711924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_24258081)) {
24987836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_LIP_FULL_LOGIN;
249911924SDaniel.Beauregard@Sun.COM 		mcp->mb[1] = (uint16_t)(CFG_IST(ha, CFG_CTRL_8081) ?
25009611SDaniel.Beauregard@Sun.COM 		    BIT_1 : BIT_4);
25017836SJohn.Forte@Sun.COM 		mcp->mb[3] = ha->loop_reset_delay;
25027836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
25037836SJohn.Forte@Sun.COM 	} else {
25047836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_INITIATE_LIP;
25057836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_0;
25067836SJohn.Forte@Sun.COM 	}
25077836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0;
25087836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
25097836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
25107836SJohn.Forte@Sun.COM 
25117836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
25127836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
25137836SJohn.Forte@Sun.COM 	} else {
25147836SJohn.Forte@Sun.COM 		/*EMPTY*/
25157836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
25167836SJohn.Forte@Sun.COM 	}
25177836SJohn.Forte@Sun.COM 
25187836SJohn.Forte@Sun.COM 	return (rval);
25197836SJohn.Forte@Sun.COM }
25207836SJohn.Forte@Sun.COM 
25217836SJohn.Forte@Sun.COM /*
25227836SJohn.Forte@Sun.COM  * ql_full_login_lip
25237836SJohn.Forte@Sun.COM  *	Issue full login LIP mailbox command.
25247836SJohn.Forte@Sun.COM  *
25257836SJohn.Forte@Sun.COM  * Input:
25267836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
25277836SJohn.Forte@Sun.COM  *
25287836SJohn.Forte@Sun.COM  * Returns:
25297836SJohn.Forte@Sun.COM  *	ql local function return status code.
25307836SJohn.Forte@Sun.COM  *
25317836SJohn.Forte@Sun.COM  * Context:
25327836SJohn.Forte@Sun.COM  *	Kernel context.
25337836SJohn.Forte@Sun.COM  */
25347836SJohn.Forte@Sun.COM int
ql_full_login_lip(ql_adapter_state_t * ha)25357836SJohn.Forte@Sun.COM ql_full_login_lip(ql_adapter_state_t *ha)
25367836SJohn.Forte@Sun.COM {
25377836SJohn.Forte@Sun.COM 	int		rval;
25387836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
25397836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
25407836SJohn.Forte@Sun.COM 
25417836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
25427836SJohn.Forte@Sun.COM 
25437836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_LIP_FULL_LOGIN;
25449446SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_2425)) {
25459446SDaniel.Beauregard@Sun.COM 		mcp->mb[1] = BIT_3;
254611924SDaniel.Beauregard@Sun.COM 	} else if (CFG_IST(ha, CFG_CTRL_8081)) {
25479446SDaniel.Beauregard@Sun.COM 		mcp->mb[1] = BIT_1;
25489446SDaniel.Beauregard@Sun.COM 	}
25497836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
25507836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0;
25517836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
25527836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
25537836SJohn.Forte@Sun.COM 
25547836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
25557836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
25567836SJohn.Forte@Sun.COM 	} else {
25577836SJohn.Forte@Sun.COM 		/*EMPTY*/
25587836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done", ha->instance);
25597836SJohn.Forte@Sun.COM 	}
25607836SJohn.Forte@Sun.COM 
25617836SJohn.Forte@Sun.COM 	return (rval);
25627836SJohn.Forte@Sun.COM }
25637836SJohn.Forte@Sun.COM 
25647836SJohn.Forte@Sun.COM /*
25657836SJohn.Forte@Sun.COM  * ql_lip_reset
25667836SJohn.Forte@Sun.COM  *	Issue lip reset to a port.
25677836SJohn.Forte@Sun.COM  *
25687836SJohn.Forte@Sun.COM  * Input:
25697836SJohn.Forte@Sun.COM  *	ha:		adapter state pointer.
25707836SJohn.Forte@Sun.COM  *	loop_id:	FC loop id.
25717836SJohn.Forte@Sun.COM  *
25727836SJohn.Forte@Sun.COM  * Returns:
25737836SJohn.Forte@Sun.COM  *	ql local function return status code.
25747836SJohn.Forte@Sun.COM  *
25757836SJohn.Forte@Sun.COM  * Context:
25767836SJohn.Forte@Sun.COM  *	Kernel context.
25777836SJohn.Forte@Sun.COM  */
25787836SJohn.Forte@Sun.COM int
ql_lip_reset(ql_adapter_state_t * ha,uint16_t loop_id)25797836SJohn.Forte@Sun.COM ql_lip_reset(ql_adapter_state_t *ha, uint16_t loop_id)
25807836SJohn.Forte@Sun.COM {
25817836SJohn.Forte@Sun.COM 	int		rval;
25827836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
25837836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
25847836SJohn.Forte@Sun.COM 
25857836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
25867836SJohn.Forte@Sun.COM 
258711924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_24258081)) {
25887836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_LIP_FULL_LOGIN;
258911924SDaniel.Beauregard@Sun.COM 		mcp->mb[1] = (uint16_t)(CFG_IST(ha, CFG_CTRL_8081) ?
25909611SDaniel.Beauregard@Sun.COM 		    BIT_1 : BIT_6);
25917836SJohn.Forte@Sun.COM 		mcp->mb[3] = ha->loop_reset_delay;
25927836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
25937836SJohn.Forte@Sun.COM 	} else {
25947836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_LIP_RESET;
25957836SJohn.Forte@Sun.COM 		if (CFG_IST(ha, CFG_EXT_FW_INTERFACE)) {
25967836SJohn.Forte@Sun.COM 			mcp->mb[1] = loop_id;
25977836SJohn.Forte@Sun.COM 			mcp->out_mb = MBX_10|MBX_3|MBX_2|MBX_1|MBX_0;
25987836SJohn.Forte@Sun.COM 		} else {
25997836SJohn.Forte@Sun.COM 			mcp->mb[1] = (uint16_t)(loop_id << 8);
26007836SJohn.Forte@Sun.COM 			mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
26017836SJohn.Forte@Sun.COM 		}
26027836SJohn.Forte@Sun.COM 		mcp->mb[2] = ha->loop_reset_delay;
26037836SJohn.Forte@Sun.COM 	}
26047836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0;
26057836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
26067836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
26077836SJohn.Forte@Sun.COM 
26087836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
26097836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
26107836SJohn.Forte@Sun.COM 	} else {
26117836SJohn.Forte@Sun.COM 		/*EMPTY*/
26127836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
26137836SJohn.Forte@Sun.COM 	}
26147836SJohn.Forte@Sun.COM 
26157836SJohn.Forte@Sun.COM 	return (rval);
26167836SJohn.Forte@Sun.COM }
26177836SJohn.Forte@Sun.COM 
26187836SJohn.Forte@Sun.COM /*
26197836SJohn.Forte@Sun.COM  * ql_abort_command
26207836SJohn.Forte@Sun.COM  *	Abort command aborts a specified IOCB.
26217836SJohn.Forte@Sun.COM  *
26227836SJohn.Forte@Sun.COM  * Input:
26237836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
26247836SJohn.Forte@Sun.COM  *	sp:	SRB structure pointer.
26257836SJohn.Forte@Sun.COM  *
26267836SJohn.Forte@Sun.COM  * Returns:
26277836SJohn.Forte@Sun.COM  *	ql local function return status code.
26287836SJohn.Forte@Sun.COM  *
26297836SJohn.Forte@Sun.COM  * Context:
26307836SJohn.Forte@Sun.COM  *	Kernel context.
26317836SJohn.Forte@Sun.COM  */
26327836SJohn.Forte@Sun.COM int
ql_abort_command(ql_adapter_state_t * ha,ql_srb_t * sp)26337836SJohn.Forte@Sun.COM ql_abort_command(ql_adapter_state_t *ha, ql_srb_t *sp)
26347836SJohn.Forte@Sun.COM {
26357836SJohn.Forte@Sun.COM 	int		rval;
26367836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
26377836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
26387836SJohn.Forte@Sun.COM 	ql_tgt_t	*tq = sp->lun_queue->target_queue;
26397836SJohn.Forte@Sun.COM 
26407836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
26417836SJohn.Forte@Sun.COM 
264211924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_24258081)) {
26437836SJohn.Forte@Sun.COM 		rval = ql_abort_cmd_iocb(ha, sp);
26447836SJohn.Forte@Sun.COM 	} else {
26457836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_ABORT_COMMAND_IOCB;
26467836SJohn.Forte@Sun.COM 		if (CFG_IST(ha, CFG_EXT_FW_INTERFACE)) {
26477836SJohn.Forte@Sun.COM 			mcp->mb[1] = tq->loop_id;
26487836SJohn.Forte@Sun.COM 		} else {
26497836SJohn.Forte@Sun.COM 			mcp->mb[1] = (uint16_t)(tq->loop_id << 8);
26507836SJohn.Forte@Sun.COM 		}
26517836SJohn.Forte@Sun.COM 		mcp->mb[2] = LSW(sp->handle);
26527836SJohn.Forte@Sun.COM 		mcp->mb[3] = MSW(sp->handle);
26537836SJohn.Forte@Sun.COM 		mcp->mb[6] = (uint16_t)(sp->flags & SRB_FCP_CMD_PKT ?
26547836SJohn.Forte@Sun.COM 		    sp->lun_queue->lun_no : 0);
26557836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
26567836SJohn.Forte@Sun.COM 		mcp->in_mb = MBX_0;
26577836SJohn.Forte@Sun.COM 		mcp->timeout = MAILBOX_TOV;
26587836SJohn.Forte@Sun.COM 		rval = ql_mailbox_command(ha, mcp);
26597836SJohn.Forte@Sun.COM 	}
26607836SJohn.Forte@Sun.COM 
26617836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
26627836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh, d_id=%xh, handle=%xh\n", rval,
26637836SJohn.Forte@Sun.COM 		    tq->d_id.b24, sp->handle);
26647836SJohn.Forte@Sun.COM 	} else {
26657836SJohn.Forte@Sun.COM 		/*EMPTY*/
26667836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
26677836SJohn.Forte@Sun.COM 	}
26687836SJohn.Forte@Sun.COM 
26697836SJohn.Forte@Sun.COM 	return (rval);
26707836SJohn.Forte@Sun.COM }
26717836SJohn.Forte@Sun.COM 
26727836SJohn.Forte@Sun.COM /*
26737836SJohn.Forte@Sun.COM  * ql_abort_cmd_iocb
26747836SJohn.Forte@Sun.COM  *	Function issues abort command IOCB.
26757836SJohn.Forte@Sun.COM  *
26767836SJohn.Forte@Sun.COM  * Input:
26777836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
26787836SJohn.Forte@Sun.COM  *	sp:	SRB structure pointer.
26797836SJohn.Forte@Sun.COM  *
26807836SJohn.Forte@Sun.COM  * Returns:
26817836SJohn.Forte@Sun.COM  *	ql local function return status code.
26827836SJohn.Forte@Sun.COM  *
26837836SJohn.Forte@Sun.COM  * Context:
26847836SJohn.Forte@Sun.COM  *	Interrupt or Kernel context, no mailbox commands allowed.
26857836SJohn.Forte@Sun.COM  */
26867836SJohn.Forte@Sun.COM static int
ql_abort_cmd_iocb(ql_adapter_state_t * ha,ql_srb_t * sp)26877836SJohn.Forte@Sun.COM ql_abort_cmd_iocb(ql_adapter_state_t *ha, ql_srb_t *sp)
26887836SJohn.Forte@Sun.COM {
26897836SJohn.Forte@Sun.COM 	ql_mbx_iocb_t	*pkt;
26907836SJohn.Forte@Sun.COM 	int		rval;
26917836SJohn.Forte@Sun.COM 	uint32_t	pkt_size;
26927836SJohn.Forte@Sun.COM 	uint16_t	comp_status;
26937836SJohn.Forte@Sun.COM 	ql_tgt_t	*tq = sp->lun_queue->target_queue;
26947836SJohn.Forte@Sun.COM 
26957836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
26967836SJohn.Forte@Sun.COM 
26977836SJohn.Forte@Sun.COM 	pkt_size = sizeof (ql_mbx_iocb_t);
26987836SJohn.Forte@Sun.COM 	if ((pkt = kmem_zalloc(pkt_size, KM_SLEEP)) == NULL) {
26997836SJohn.Forte@Sun.COM 		EL(ha, "failed, kmem_zalloc\n");
27007836SJohn.Forte@Sun.COM 		return (QL_MEMORY_ALLOC_FAILED);
27017836SJohn.Forte@Sun.COM 	}
27027836SJohn.Forte@Sun.COM 
27037836SJohn.Forte@Sun.COM 	pkt->abo.entry_type = ABORT_CMD_TYPE;
27047836SJohn.Forte@Sun.COM 	pkt->abo.entry_count = 1;
27057836SJohn.Forte@Sun.COM 	pkt->abo.n_port_hdl = (uint16_t)LE_16(tq->loop_id);
2706*12279SDaniel.Beauregard@Sun.COM 	if (!CFG_IST(ha, CFG_CTRL_8021)) {
2707*12279SDaniel.Beauregard@Sun.COM 		pkt->abo.options = AF_NO_ABTS;
2708*12279SDaniel.Beauregard@Sun.COM 	}
27097836SJohn.Forte@Sun.COM 	pkt->abo.cmd_handle = LE_32(sp->handle);
27107836SJohn.Forte@Sun.COM 	pkt->abo.target_id[0] = tq->d_id.b.al_pa;
27117836SJohn.Forte@Sun.COM 	pkt->abo.target_id[1] = tq->d_id.b.area;
27127836SJohn.Forte@Sun.COM 	pkt->abo.target_id[2] = tq->d_id.b.domain;
27137836SJohn.Forte@Sun.COM 	pkt->abo.vp_index = ha->vp_index;
27147836SJohn.Forte@Sun.COM 
27157836SJohn.Forte@Sun.COM 	rval = ql_issue_mbx_iocb(ha, (caddr_t)pkt, pkt_size);
27167836SJohn.Forte@Sun.COM 
2717*12279SDaniel.Beauregard@Sun.COM 	if (rval == QL_SUCCESS) {
2718*12279SDaniel.Beauregard@Sun.COM 		if ((pkt->abo.entry_status  & 0x3c) != 0) {
2719*12279SDaniel.Beauregard@Sun.COM 			EL(ha, "failed, entry_status=%xh, d_id=%xh\n",
2720*12279SDaniel.Beauregard@Sun.COM 			    pkt->abo.entry_status, tq->d_id.b24);
2721*12279SDaniel.Beauregard@Sun.COM 			rval = QL_FUNCTION_PARAMETER_ERROR;
2722*12279SDaniel.Beauregard@Sun.COM 		} else {
2723*12279SDaniel.Beauregard@Sun.COM 			comp_status = (uint16_t)LE_16(pkt->abo.n_port_hdl);
2724*12279SDaniel.Beauregard@Sun.COM 			if (comp_status != CS_COMPLETE) {
2725*12279SDaniel.Beauregard@Sun.COM 				EL(ha, "failed, comp_status=%xh, d_id=%xh\n",
2726*12279SDaniel.Beauregard@Sun.COM 				    comp_status, tq->d_id.b24);
2727*12279SDaniel.Beauregard@Sun.COM 				rval = QL_FUNCTION_FAILED;
2728*12279SDaniel.Beauregard@Sun.COM 			}
2729*12279SDaniel.Beauregard@Sun.COM 		}
27307836SJohn.Forte@Sun.COM 	}
27317836SJohn.Forte@Sun.COM 
27327836SJohn.Forte@Sun.COM 	kmem_free(pkt, pkt_size);
27337836SJohn.Forte@Sun.COM 
27347836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
27357836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh, d_id=%xh\n", rval, tq->d_id.b24);
27367836SJohn.Forte@Sun.COM 	} else {
27377836SJohn.Forte@Sun.COM 		/*EMPTY*/
27387836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
27397836SJohn.Forte@Sun.COM 	}
27407836SJohn.Forte@Sun.COM 
27417836SJohn.Forte@Sun.COM 	return (rval);
27427836SJohn.Forte@Sun.COM }
27437836SJohn.Forte@Sun.COM 
27447836SJohn.Forte@Sun.COM /*
27457836SJohn.Forte@Sun.COM  * ql_verify_checksum
27467836SJohn.Forte@Sun.COM  *	Verify loaded RISC firmware.
27477836SJohn.Forte@Sun.COM  *
27487836SJohn.Forte@Sun.COM  * Input:
27497836SJohn.Forte@Sun.COM  *	ha = adapter state pointer.
27507836SJohn.Forte@Sun.COM  *
27517836SJohn.Forte@Sun.COM  * Returns:
27527836SJohn.Forte@Sun.COM  *	ql local function return status code.
27537836SJohn.Forte@Sun.COM  *
27547836SJohn.Forte@Sun.COM  * Context:
27557836SJohn.Forte@Sun.COM  *	Kernel context.
27567836SJohn.Forte@Sun.COM  */
27577836SJohn.Forte@Sun.COM int
ql_verify_checksum(ql_adapter_state_t * ha)27587836SJohn.Forte@Sun.COM ql_verify_checksum(ql_adapter_state_t *ha)
27597836SJohn.Forte@Sun.COM {
27607836SJohn.Forte@Sun.COM 	int		rval;
27617836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
27627836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
27637836SJohn.Forte@Sun.COM 
27647836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
27657836SJohn.Forte@Sun.COM 
27667836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_VERIFY_CHECKSUM;
276711924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_24258081)) {
27687836SJohn.Forte@Sun.COM 		mcp->mb[1] = MSW(ha->risc_fw[0].addr);
27697836SJohn.Forte@Sun.COM 		mcp->mb[2] = LSW(ha->risc_fw[0].addr);
27707836SJohn.Forte@Sun.COM 	} else {
27717836SJohn.Forte@Sun.COM 		mcp->mb[1] = LSW(ha->risc_fw[0].addr);
27727836SJohn.Forte@Sun.COM 	}
27737836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_2|MBX_1|MBX_0;
27747836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_2|MBX_1|MBX_0;
27757836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
27767836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
27777836SJohn.Forte@Sun.COM 
27787836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
27797836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
27807836SJohn.Forte@Sun.COM 	} else {
27817836SJohn.Forte@Sun.COM 		/*EMPTY*/
27827836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
27837836SJohn.Forte@Sun.COM 	}
27847836SJohn.Forte@Sun.COM 
27857836SJohn.Forte@Sun.COM 	return (rval);
27867836SJohn.Forte@Sun.COM }
27877836SJohn.Forte@Sun.COM 
27887836SJohn.Forte@Sun.COM /*
27897836SJohn.Forte@Sun.COM  * ql_get_id_list
27907836SJohn.Forte@Sun.COM  *	Get d_id and loop ID list.
27917836SJohn.Forte@Sun.COM  *
27927836SJohn.Forte@Sun.COM  * Input:
27937836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
27947836SJohn.Forte@Sun.COM  *	bp:	data pointer for DMA data.
27957836SJohn.Forte@Sun.COM  *	size:	size of data buffer.
27967836SJohn.Forte@Sun.COM  *	mr:	pointer for mailbox data.
27977836SJohn.Forte@Sun.COM  *
27987836SJohn.Forte@Sun.COM  * Returns:
27997836SJohn.Forte@Sun.COM  *	ql local function return status code.
28007836SJohn.Forte@Sun.COM  *
28017836SJohn.Forte@Sun.COM  * Context:
28027836SJohn.Forte@Sun.COM  *	Kernel context.
28037836SJohn.Forte@Sun.COM  */
28047836SJohn.Forte@Sun.COM int
ql_get_id_list(ql_adapter_state_t * ha,caddr_t bp,uint32_t size,ql_mbx_data_t * mr)28057836SJohn.Forte@Sun.COM ql_get_id_list(ql_adapter_state_t *ha, caddr_t bp, uint32_t size,
28067836SJohn.Forte@Sun.COM     ql_mbx_data_t *mr)
28077836SJohn.Forte@Sun.COM {
28087836SJohn.Forte@Sun.COM 	int		rval;
28097836SJohn.Forte@Sun.COM 	dma_mem_t	mem_desc;
28107836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
28117836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
28127836SJohn.Forte@Sun.COM 
28137836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
28147836SJohn.Forte@Sun.COM 
28157836SJohn.Forte@Sun.COM 	if ((rval = ql_setup_mbox_dma_resources(ha, &mem_desc,
28167836SJohn.Forte@Sun.COM 	    (uint32_t)size)) != QL_SUCCESS) {
28177836SJohn.Forte@Sun.COM 		EL(ha, "setup_mbox_dma_resources failed: %xh\n", rval);
28187836SJohn.Forte@Sun.COM 		return (QL_MEMORY_ALLOC_FAILED);
28197836SJohn.Forte@Sun.COM 	}
28207836SJohn.Forte@Sun.COM 
28217836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_GET_ID_LIST;
282211924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_24258081)) {
28237836SJohn.Forte@Sun.COM 		mcp->mb[2] = MSW(LSD(mem_desc.cookie.dmac_laddress));
28247836SJohn.Forte@Sun.COM 		mcp->mb[3] = LSW(LSD(mem_desc.cookie.dmac_laddress));
28257836SJohn.Forte@Sun.COM 		mcp->mb[6] = MSW(MSD(mem_desc.cookie.dmac_laddress));
28267836SJohn.Forte@Sun.COM 		mcp->mb[7] = LSW(MSD(mem_desc.cookie.dmac_laddress));
28277836SJohn.Forte@Sun.COM 		mcp->mb[8] = (uint16_t)size;
28287836SJohn.Forte@Sun.COM 		mcp->mb[9] = ha->vp_index;
28297836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
28307836SJohn.Forte@Sun.COM 	} else {
28317836SJohn.Forte@Sun.COM 		mcp->mb[1] = MSW(LSD(mem_desc.cookie.dmac_laddress));
28327836SJohn.Forte@Sun.COM 		mcp->mb[2] = LSW(LSD(mem_desc.cookie.dmac_laddress));
28337836SJohn.Forte@Sun.COM 		mcp->mb[3] = MSW(MSD(mem_desc.cookie.dmac_laddress));
28347836SJohn.Forte@Sun.COM 		mcp->mb[6] = LSW(MSD(mem_desc.cookie.dmac_laddress));
28357836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
28367836SJohn.Forte@Sun.COM 	}
28377836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_1|MBX_0;
28387836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
28397836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
28407836SJohn.Forte@Sun.COM 
28417836SJohn.Forte@Sun.COM 	if (rval == QL_SUCCESS) {
28427836SJohn.Forte@Sun.COM 		ql_get_mbox_dma_data(&mem_desc, bp);
28437836SJohn.Forte@Sun.COM 	}
28447836SJohn.Forte@Sun.COM 
28457836SJohn.Forte@Sun.COM 	ql_free_dma_resource(ha, &mem_desc);
28467836SJohn.Forte@Sun.COM 
28477836SJohn.Forte@Sun.COM 	/* Return mailbox data. */
28487836SJohn.Forte@Sun.COM 	if (mr != NULL) {
28497836SJohn.Forte@Sun.COM 		mr->mb[0] = mcp->mb[0];
28507836SJohn.Forte@Sun.COM 		mr->mb[1] = mcp->mb[1];
28517836SJohn.Forte@Sun.COM 	}
28527836SJohn.Forte@Sun.COM 
28537836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
28547836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
28557836SJohn.Forte@Sun.COM 	} else {
28567836SJohn.Forte@Sun.COM 		/*EMPTY*/
28577836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
28587836SJohn.Forte@Sun.COM 	}
28597836SJohn.Forte@Sun.COM 
28607836SJohn.Forte@Sun.COM 	return (rval);
28617836SJohn.Forte@Sun.COM }
28627836SJohn.Forte@Sun.COM 
28637836SJohn.Forte@Sun.COM /*
28647836SJohn.Forte@Sun.COM  * ql_wrt_risc_ram
28657836SJohn.Forte@Sun.COM  *	Load RISC RAM.
28667836SJohn.Forte@Sun.COM  *
28677836SJohn.Forte@Sun.COM  * Input:
28687836SJohn.Forte@Sun.COM  *	ha:		adapter state pointer.
28697836SJohn.Forte@Sun.COM  *	risc_address:	risc ram word address.
28707836SJohn.Forte@Sun.COM  *	bp:		DMA pointer.
28717836SJohn.Forte@Sun.COM  *	word_count:	16/32bit word count.
28727836SJohn.Forte@Sun.COM  *
28737836SJohn.Forte@Sun.COM  * Returns:
28747836SJohn.Forte@Sun.COM  *	ql local function return status code.
28757836SJohn.Forte@Sun.COM  *
28767836SJohn.Forte@Sun.COM  * Context:
28777836SJohn.Forte@Sun.COM  *	Kernel context.
28787836SJohn.Forte@Sun.COM  */
28797836SJohn.Forte@Sun.COM int
ql_wrt_risc_ram(ql_adapter_state_t * ha,uint32_t risc_address,uint64_t bp,uint32_t word_count)28807836SJohn.Forte@Sun.COM ql_wrt_risc_ram(ql_adapter_state_t *ha, uint32_t risc_address, uint64_t bp,
28817836SJohn.Forte@Sun.COM     uint32_t word_count)
28827836SJohn.Forte@Sun.COM {
28837836SJohn.Forte@Sun.COM 	int		rval;
28847836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
28857836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
28867836SJohn.Forte@Sun.COM 
28877836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
28887836SJohn.Forte@Sun.COM 
2889*12279SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_242581)) {
28907836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_LOAD_RAM_EXTENDED;
28917836SJohn.Forte@Sun.COM 		mcp->mb[4] = MSW(word_count);
28927836SJohn.Forte@Sun.COM 		mcp->mb[5] = LSW(word_count);
28937836SJohn.Forte@Sun.COM 		mcp->mb[6] = MSW(MSD(bp));
28947836SJohn.Forte@Sun.COM 		mcp->mb[7] = LSW(MSD(bp));
28957836SJohn.Forte@Sun.COM 		mcp->mb[8] = MSW(risc_address);
28967836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|
28977836SJohn.Forte@Sun.COM 		    MBX_0;
28987836SJohn.Forte@Sun.COM 	} else {
28997836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_LOAD_RAM;
29007836SJohn.Forte@Sun.COM 		mcp->mb[4] = LSW(word_count);
29017836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
29027836SJohn.Forte@Sun.COM 	}
29037836SJohn.Forte@Sun.COM 	mcp->mb[1] = LSW(risc_address);
29047836SJohn.Forte@Sun.COM 	mcp->mb[2] = MSW(LSD(bp));
29057836SJohn.Forte@Sun.COM 	mcp->mb[3] = LSW(LSD(bp));
29067836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0;
29077836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
29087836SJohn.Forte@Sun.COM 
29097836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
29107836SJohn.Forte@Sun.COM 
29117836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
29127836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
29137836SJohn.Forte@Sun.COM 	} else {
29147836SJohn.Forte@Sun.COM 		/*EMPTY*/
29157836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
29167836SJohn.Forte@Sun.COM 	}
29177836SJohn.Forte@Sun.COM 
29187836SJohn.Forte@Sun.COM 	return (rval);
29197836SJohn.Forte@Sun.COM }
29207836SJohn.Forte@Sun.COM 
29217836SJohn.Forte@Sun.COM /*
29227836SJohn.Forte@Sun.COM  * ql_rd_risc_ram
29237836SJohn.Forte@Sun.COM  *	Get RISC RAM.
29247836SJohn.Forte@Sun.COM  *
29257836SJohn.Forte@Sun.COM  * Input:
29267836SJohn.Forte@Sun.COM  *	ha:		adapter state pointer.
29277836SJohn.Forte@Sun.COM  *	risc_address:	risc ram word address.
29287836SJohn.Forte@Sun.COM  *	bp:		direct data pointer.
29297836SJohn.Forte@Sun.COM  *	word_count:	16/32bit word count.
29307836SJohn.Forte@Sun.COM  *
29317836SJohn.Forte@Sun.COM  * Returns:
29327836SJohn.Forte@Sun.COM  *	ql local function return status code.
29337836SJohn.Forte@Sun.COM  *
29347836SJohn.Forte@Sun.COM  * Context:
29357836SJohn.Forte@Sun.COM  *	Kernel context.
29367836SJohn.Forte@Sun.COM  */
29377836SJohn.Forte@Sun.COM int
ql_rd_risc_ram(ql_adapter_state_t * ha,uint32_t risc_address,uint64_t bp,uint32_t word_count)29387836SJohn.Forte@Sun.COM ql_rd_risc_ram(ql_adapter_state_t *ha, uint32_t risc_address, uint64_t bp,
29397836SJohn.Forte@Sun.COM     uint32_t word_count)
29407836SJohn.Forte@Sun.COM {
29417836SJohn.Forte@Sun.COM 	int		rval;
29427836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
29437836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
29447836SJohn.Forte@Sun.COM 
29457836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
29467836SJohn.Forte@Sun.COM 
2947*12279SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_242581)) {
29487836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_DUMP_RAM_EXTENDED;
29497836SJohn.Forte@Sun.COM 		mcp->mb[1] = LSW(risc_address);
29507836SJohn.Forte@Sun.COM 		mcp->mb[2] = MSW(LSD(bp));
29517836SJohn.Forte@Sun.COM 		mcp->mb[3] = LSW(LSD(bp));
29527836SJohn.Forte@Sun.COM 		mcp->mb[4] = MSW(word_count);
29537836SJohn.Forte@Sun.COM 		mcp->mb[5] = LSW(word_count);
29547836SJohn.Forte@Sun.COM 		mcp->mb[6] = MSW(MSD(bp));
29557836SJohn.Forte@Sun.COM 		mcp->mb[7] = LSW(MSD(bp));
29567836SJohn.Forte@Sun.COM 		mcp->mb[8] = MSW(risc_address);
29577836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|
29587836SJohn.Forte@Sun.COM 		    MBX_0;
29597836SJohn.Forte@Sun.COM 	} else {
29607836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_DUMP_RAM;	/* doesn't support 64bit addr */
29617836SJohn.Forte@Sun.COM 		mcp->mb[1] = LSW(risc_address);
29627836SJohn.Forte@Sun.COM 		mcp->mb[2] = MSW(LSD(bp));
29637836SJohn.Forte@Sun.COM 		mcp->mb[3] = LSW(LSD(bp));
29647836SJohn.Forte@Sun.COM 		mcp->mb[4] = LSW(word_count);
29657836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
29667836SJohn.Forte@Sun.COM 	}
29677836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0;
29687836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
29697836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
29707836SJohn.Forte@Sun.COM 
29717836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
29727836SJohn.Forte@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
29737836SJohn.Forte@Sun.COM 	} else {
29747836SJohn.Forte@Sun.COM 		/*EMPTY*/
29757836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
29767836SJohn.Forte@Sun.COM 	}
29777836SJohn.Forte@Sun.COM 
29787836SJohn.Forte@Sun.COM 	return (rval);
29797836SJohn.Forte@Sun.COM }
29807836SJohn.Forte@Sun.COM 
29817836SJohn.Forte@Sun.COM /*
298210736SDaniel.Beauregard@Sun.COM  * ql_wrt_risc_ram_word
298310736SDaniel.Beauregard@Sun.COM  *	Write RISC RAM word.
298410736SDaniel.Beauregard@Sun.COM  *
298510736SDaniel.Beauregard@Sun.COM  * Input:
298610736SDaniel.Beauregard@Sun.COM  *	ha:		adapter state pointer.
298710736SDaniel.Beauregard@Sun.COM  *	risc_address:	risc ram word address.
298810736SDaniel.Beauregard@Sun.COM  *	data:		data.
298910736SDaniel.Beauregard@Sun.COM  *
299010736SDaniel.Beauregard@Sun.COM  * Returns:
299110736SDaniel.Beauregard@Sun.COM  *	ql local function return status code.
299210736SDaniel.Beauregard@Sun.COM  *
299310736SDaniel.Beauregard@Sun.COM  * Context:
299410736SDaniel.Beauregard@Sun.COM  *	Kernel context.
299510736SDaniel.Beauregard@Sun.COM  */
299610736SDaniel.Beauregard@Sun.COM int
ql_wrt_risc_ram_word(ql_adapter_state_t * ha,uint32_t risc_address,uint32_t data)299710736SDaniel.Beauregard@Sun.COM ql_wrt_risc_ram_word(ql_adapter_state_t *ha, uint32_t risc_address,
299810736SDaniel.Beauregard@Sun.COM     uint32_t data)
299910736SDaniel.Beauregard@Sun.COM {
300010736SDaniel.Beauregard@Sun.COM 	int		rval;
300110736SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	mc = {0};
300210736SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	*mcp = &mc;
300310736SDaniel.Beauregard@Sun.COM 
300410736SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
300510736SDaniel.Beauregard@Sun.COM 
300610736SDaniel.Beauregard@Sun.COM 	mcp->mb[0] = MBC_WRITE_RAM_EXTENDED;
300710736SDaniel.Beauregard@Sun.COM 	mcp->mb[1] = LSW(risc_address);
300810736SDaniel.Beauregard@Sun.COM 	mcp->mb[2] = LSW(data);
300910736SDaniel.Beauregard@Sun.COM 	mcp->mb[3] = MSW(data);
301010736SDaniel.Beauregard@Sun.COM 	mcp->mb[8] = MSW(risc_address);
301110736SDaniel.Beauregard@Sun.COM 	mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
301210736SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_0;
301310736SDaniel.Beauregard@Sun.COM 	mcp->timeout = MAILBOX_TOV;
301410736SDaniel.Beauregard@Sun.COM 
301510736SDaniel.Beauregard@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
301610736SDaniel.Beauregard@Sun.COM 
301710736SDaniel.Beauregard@Sun.COM 	if (rval != QL_SUCCESS) {
301810736SDaniel.Beauregard@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
301910736SDaniel.Beauregard@Sun.COM 	} else {
302010736SDaniel.Beauregard@Sun.COM 		/*EMPTY*/
302110736SDaniel.Beauregard@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
302210736SDaniel.Beauregard@Sun.COM 	}
302310736SDaniel.Beauregard@Sun.COM 
302410736SDaniel.Beauregard@Sun.COM 	return (rval);
302510736SDaniel.Beauregard@Sun.COM }
302610736SDaniel.Beauregard@Sun.COM 
302710736SDaniel.Beauregard@Sun.COM /*
302810736SDaniel.Beauregard@Sun.COM  * ql_rd_risc_ram_word
302910736SDaniel.Beauregard@Sun.COM  *	Read RISC RAM word.
303010736SDaniel.Beauregard@Sun.COM  *
303110736SDaniel.Beauregard@Sun.COM  * Input:
303210736SDaniel.Beauregard@Sun.COM  *	ha:		adapter state pointer.
303310736SDaniel.Beauregard@Sun.COM  *	risc_address:	risc ram word address.
303410736SDaniel.Beauregard@Sun.COM  *	data:		data pointer.
303510736SDaniel.Beauregard@Sun.COM  *
303610736SDaniel.Beauregard@Sun.COM  * Returns:
303710736SDaniel.Beauregard@Sun.COM  *	ql local function return status code.
303810736SDaniel.Beauregard@Sun.COM  *
303910736SDaniel.Beauregard@Sun.COM  * Context:
304010736SDaniel.Beauregard@Sun.COM  *	Kernel context.
304110736SDaniel.Beauregard@Sun.COM  */
304210736SDaniel.Beauregard@Sun.COM int
ql_rd_risc_ram_word(ql_adapter_state_t * ha,uint32_t risc_address,uint32_t * data)304310736SDaniel.Beauregard@Sun.COM ql_rd_risc_ram_word(ql_adapter_state_t *ha, uint32_t risc_address,
304410736SDaniel.Beauregard@Sun.COM     uint32_t *data)
304510736SDaniel.Beauregard@Sun.COM {
304610736SDaniel.Beauregard@Sun.COM 	int		rval;
304710736SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	mc = {0};
304810736SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	*mcp = &mc;
304910736SDaniel.Beauregard@Sun.COM 
305010736SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
305110736SDaniel.Beauregard@Sun.COM 
305210736SDaniel.Beauregard@Sun.COM 	mcp->mb[0] = MBC_READ_RAM_EXTENDED;
305310736SDaniel.Beauregard@Sun.COM 	mcp->mb[1] = LSW(risc_address);
305410736SDaniel.Beauregard@Sun.COM 	mcp->mb[8] = MSW(risc_address);
305510736SDaniel.Beauregard@Sun.COM 	mcp->out_mb = MBX_8|MBX_1|MBX_0;
305610736SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_3|MBX_2|MBX_0;
305710736SDaniel.Beauregard@Sun.COM 	mcp->timeout = MAILBOX_TOV;
305810736SDaniel.Beauregard@Sun.COM 
305910736SDaniel.Beauregard@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
306010736SDaniel.Beauregard@Sun.COM 
306110736SDaniel.Beauregard@Sun.COM 	if (rval != QL_SUCCESS) {
306210736SDaniel.Beauregard@Sun.COM 		EL(ha, "failed, rval = %xh\n", rval);
306310736SDaniel.Beauregard@Sun.COM 	} else {
306410736SDaniel.Beauregard@Sun.COM 		*data = mcp->mb[2];
306511924SDaniel.Beauregard@Sun.COM 		if (CFG_IST(ha, CFG_CTRL_24258081)) {
306610736SDaniel.Beauregard@Sun.COM 			*data |= mcp->mb[3] << 16;
306710736SDaniel.Beauregard@Sun.COM 		}
306810736SDaniel.Beauregard@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
306910736SDaniel.Beauregard@Sun.COM 	}
307010736SDaniel.Beauregard@Sun.COM 
307110736SDaniel.Beauregard@Sun.COM 	return (rval);
307210736SDaniel.Beauregard@Sun.COM }
307310736SDaniel.Beauregard@Sun.COM 
307410736SDaniel.Beauregard@Sun.COM /*
30757836SJohn.Forte@Sun.COM  * ql_issue_mbx_iocb
30767836SJohn.Forte@Sun.COM  *	Issue IOCB using mailbox command
30777836SJohn.Forte@Sun.COM  *
30787836SJohn.Forte@Sun.COM  * Input:
30797836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
30807836SJohn.Forte@Sun.COM  *	bp:	buffer pointer.
30817836SJohn.Forte@Sun.COM  *	size:	buffer size.
30827836SJohn.Forte@Sun.COM  *
30837836SJohn.Forte@Sun.COM  * Returns:
30847836SJohn.Forte@Sun.COM  *	ql local function return status code.
30857836SJohn.Forte@Sun.COM  *
30867836SJohn.Forte@Sun.COM  * Context:
30877836SJohn.Forte@Sun.COM  *	Kernel context.
30887836SJohn.Forte@Sun.COM  */
30897836SJohn.Forte@Sun.COM int
ql_issue_mbx_iocb(ql_adapter_state_t * ha,caddr_t bp,uint32_t size)30907836SJohn.Forte@Sun.COM ql_issue_mbx_iocb(ql_adapter_state_t *ha, caddr_t bp, uint32_t size)
30917836SJohn.Forte@Sun.COM {
30927836SJohn.Forte@Sun.COM 	int		rval;
30937836SJohn.Forte@Sun.COM 	dma_mem_t	mem_desc;
30947836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
30957836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
30967836SJohn.Forte@Sun.COM 
30977836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
30987836SJohn.Forte@Sun.COM 
30997836SJohn.Forte@Sun.COM 	if ((rval = ql_setup_mbox_dma_transfer(ha, &mem_desc, bp, size)) !=
31007836SJohn.Forte@Sun.COM 	    QL_SUCCESS) {
31017836SJohn.Forte@Sun.COM 		EL(ha, "setup_mbox_dma_transfer failed: %x\n", rval);
31027836SJohn.Forte@Sun.COM 		return (rval);
31037836SJohn.Forte@Sun.COM 	}
31047836SJohn.Forte@Sun.COM 
31057836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_EXECUTE_IOCB;
31067836SJohn.Forte@Sun.COM 	mcp->mb[2] = MSW(LSD(mem_desc.cookie.dmac_laddress));
31077836SJohn.Forte@Sun.COM 	mcp->mb[3] = LSW(LSD(mem_desc.cookie.dmac_laddress));
31087836SJohn.Forte@Sun.COM 	mcp->mb[6] = MSW(MSD(mem_desc.cookie.dmac_laddress));
31097836SJohn.Forte@Sun.COM 	mcp->mb[7] = LSW(MSD(mem_desc.cookie.dmac_laddress));
31107836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
31117836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_1|MBX_0;
31127836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV + 5;
31137836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
31147836SJohn.Forte@Sun.COM 
31157836SJohn.Forte@Sun.COM 	if (rval == QL_SUCCESS) {
31167836SJohn.Forte@Sun.COM 		ql_get_mbox_dma_data(&mem_desc, bp);
31177836SJohn.Forte@Sun.COM 	}
31187836SJohn.Forte@Sun.COM 
31197836SJohn.Forte@Sun.COM 	ql_free_dma_resource(ha, &mem_desc);
31207836SJohn.Forte@Sun.COM 
31217836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
31227836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh, mbx1=%xh\n", rval, mcp->mb[1]);
31237836SJohn.Forte@Sun.COM 	} else {
31247836SJohn.Forte@Sun.COM 		/*EMPTY*/
31257836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
31267836SJohn.Forte@Sun.COM 	}
31277836SJohn.Forte@Sun.COM 
31287836SJohn.Forte@Sun.COM 	return (rval);
31297836SJohn.Forte@Sun.COM }
31307836SJohn.Forte@Sun.COM 
31317836SJohn.Forte@Sun.COM /*
31327836SJohn.Forte@Sun.COM  * ql_mbx_wrap_test
31337836SJohn.Forte@Sun.COM  *	Mailbox register wrap test.
31347836SJohn.Forte@Sun.COM  *
31357836SJohn.Forte@Sun.COM  * Input:
31367836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
31377836SJohn.Forte@Sun.COM  *	mr:	pointer for in/out mailbox data.
31387836SJohn.Forte@Sun.COM  *
31397836SJohn.Forte@Sun.COM  * Returns:
31407836SJohn.Forte@Sun.COM  *	ql local function return status code.
31417836SJohn.Forte@Sun.COM  *
31427836SJohn.Forte@Sun.COM  * Context:
31437836SJohn.Forte@Sun.COM  *	Kernel context.
31447836SJohn.Forte@Sun.COM  */
31457836SJohn.Forte@Sun.COM int
ql_mbx_wrap_test(ql_adapter_state_t * ha,ql_mbx_data_t * mr)31467836SJohn.Forte@Sun.COM ql_mbx_wrap_test(ql_adapter_state_t *ha, ql_mbx_data_t *mr)
31477836SJohn.Forte@Sun.COM {
31487836SJohn.Forte@Sun.COM 	int		rval;
31497836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
31507836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
31517836SJohn.Forte@Sun.COM 
31527836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
31537836SJohn.Forte@Sun.COM 
31547836SJohn.Forte@Sun.COM 	if (mr != NULL) {
31557836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
31567836SJohn.Forte@Sun.COM 		mcp->mb[1] = mr->mb[1];
31577836SJohn.Forte@Sun.COM 		mcp->mb[2] = mr->mb[2];
31587836SJohn.Forte@Sun.COM 		mcp->mb[3] = mr->mb[3];
31597836SJohn.Forte@Sun.COM 		mcp->mb[4] = mr->mb[4];
31607836SJohn.Forte@Sun.COM 		mcp->mb[5] = mr->mb[5];
31617836SJohn.Forte@Sun.COM 		mcp->mb[6] = mr->mb[6];
31627836SJohn.Forte@Sun.COM 		mcp->mb[7] = mr->mb[7];
31637836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
31647836SJohn.Forte@Sun.COM 		mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
31657836SJohn.Forte@Sun.COM 		mcp->timeout = MAILBOX_TOV;
31667836SJohn.Forte@Sun.COM 		rval = ql_mailbox_command(ha, mcp);
31677836SJohn.Forte@Sun.COM 		if (rval == QL_SUCCESS) {
31687836SJohn.Forte@Sun.COM 			mr->mb[1] = mcp->mb[1];
31697836SJohn.Forte@Sun.COM 			mr->mb[2] = mcp->mb[2];
31707836SJohn.Forte@Sun.COM 			mr->mb[3] = mcp->mb[3];
31717836SJohn.Forte@Sun.COM 			mr->mb[4] = mcp->mb[4];
31727836SJohn.Forte@Sun.COM 			mr->mb[5] = mcp->mb[5];
31737836SJohn.Forte@Sun.COM 			mr->mb[6] = mcp->mb[6];
31747836SJohn.Forte@Sun.COM 			mr->mb[7] = mcp->mb[7];
31757836SJohn.Forte@Sun.COM 		}
31767836SJohn.Forte@Sun.COM 	} else {
31777836SJohn.Forte@Sun.COM 		rval = QL_FUNCTION_PARAMETER_ERROR;
31787836SJohn.Forte@Sun.COM 	}
31797836SJohn.Forte@Sun.COM 
31807836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
31817836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
31827836SJohn.Forte@Sun.COM 	} else {
31837836SJohn.Forte@Sun.COM 		/*EMPTY*/
31847836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
31857836SJohn.Forte@Sun.COM 	}
31867836SJohn.Forte@Sun.COM 
31877836SJohn.Forte@Sun.COM 	return (rval);
31887836SJohn.Forte@Sun.COM }
31897836SJohn.Forte@Sun.COM 
31907836SJohn.Forte@Sun.COM /*
31917836SJohn.Forte@Sun.COM  * ql_execute_fw
31927836SJohn.Forte@Sun.COM  *	Start adapter firmware.
31937836SJohn.Forte@Sun.COM  *
31947836SJohn.Forte@Sun.COM  * Input:
31957836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
31967836SJohn.Forte@Sun.COM  *
31977836SJohn.Forte@Sun.COM  * Returns:
31989446SDaniel.Beauregard@Sun.COM  *	ql local function return status code.
31997836SJohn.Forte@Sun.COM  *
32007836SJohn.Forte@Sun.COM  * Context:
32017836SJohn.Forte@Sun.COM  *	Kernel context.
32027836SJohn.Forte@Sun.COM  */
32037836SJohn.Forte@Sun.COM int
ql_execute_fw(ql_adapter_state_t * ha)32047836SJohn.Forte@Sun.COM ql_execute_fw(ql_adapter_state_t *ha)
32057836SJohn.Forte@Sun.COM {
32067836SJohn.Forte@Sun.COM 	int		rval;
32077836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
32087836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
32097836SJohn.Forte@Sun.COM 
32107836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
32117836SJohn.Forte@Sun.COM 
321211924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_8021)) {
321311924SDaniel.Beauregard@Sun.COM 		return (QL_SUCCESS);
321411924SDaniel.Beauregard@Sun.COM 	}
321511924SDaniel.Beauregard@Sun.COM 
32167836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
32179446SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_242581)) {
32187836SJohn.Forte@Sun.COM 		mcp->mb[1] = MSW(ha->risc_fw[0].addr);
32197836SJohn.Forte@Sun.COM 		mcp->mb[2] = LSW(ha->risc_fw[0].addr);
32207836SJohn.Forte@Sun.COM 	} else {
32217836SJohn.Forte@Sun.COM 		mcp->mb[1] = LSW(ha->risc_fw[0].addr);
32227836SJohn.Forte@Sun.COM 	}
322311924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_LR_SUPPORT)) {
322411924SDaniel.Beauregard@Sun.COM 		mcp->mb[4] = BIT_0;
322511924SDaniel.Beauregard@Sun.COM 	}
32267836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
32277836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0;
32287836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
32297836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
32307836SJohn.Forte@Sun.COM 
32317836SJohn.Forte@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_2200)) {
32327836SJohn.Forte@Sun.COM 		rval = QL_SUCCESS;
32337836SJohn.Forte@Sun.COM 	}
32347836SJohn.Forte@Sun.COM 
32357836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
32367836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
32377836SJohn.Forte@Sun.COM 	} else {
32387836SJohn.Forte@Sun.COM 		/*EMPTY*/
32397836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
32407836SJohn.Forte@Sun.COM 	}
32417836SJohn.Forte@Sun.COM 
32427836SJohn.Forte@Sun.COM 	return (rval);
32437836SJohn.Forte@Sun.COM }
32447836SJohn.Forte@Sun.COM 
32457836SJohn.Forte@Sun.COM /*
32467836SJohn.Forte@Sun.COM  * ql_get_firmware_option
32477836SJohn.Forte@Sun.COM  *	 Get Firmware Options Mailbox Command.
32487836SJohn.Forte@Sun.COM  *
32497836SJohn.Forte@Sun.COM  * Input:
32507836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
32517836SJohn.Forte@Sun.COM  *	mr:	pointer for mailbox data.
32527836SJohn.Forte@Sun.COM  *
32537836SJohn.Forte@Sun.COM  * Returns:
32547836SJohn.Forte@Sun.COM  *	ql local function return status code.
32557836SJohn.Forte@Sun.COM  *
32567836SJohn.Forte@Sun.COM  * Context:
32577836SJohn.Forte@Sun.COM  *	Kernel context.
32587836SJohn.Forte@Sun.COM  */
32597836SJohn.Forte@Sun.COM int
ql_get_firmware_option(ql_adapter_state_t * ha,ql_mbx_data_t * mr)32607836SJohn.Forte@Sun.COM ql_get_firmware_option(ql_adapter_state_t *ha, ql_mbx_data_t *mr)
32617836SJohn.Forte@Sun.COM {
32627836SJohn.Forte@Sun.COM 	int		rval;
32637836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
32647836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
32657836SJohn.Forte@Sun.COM 
32667836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
32677836SJohn.Forte@Sun.COM 
32687836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_GET_FIRMWARE_OPTIONS;
32697836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_0;
32707836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
32717836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
32727836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
32737836SJohn.Forte@Sun.COM 
32747836SJohn.Forte@Sun.COM 	/* Return mailbox data. */
32757836SJohn.Forte@Sun.COM 	if (mr != NULL) {
32767836SJohn.Forte@Sun.COM 		mr->mb[0] = mcp->mb[0];
32777836SJohn.Forte@Sun.COM 		mr->mb[1] = mcp->mb[1];
32787836SJohn.Forte@Sun.COM 		mr->mb[2] = mcp->mb[2];
32797836SJohn.Forte@Sun.COM 		mr->mb[3] = mcp->mb[3];
32807836SJohn.Forte@Sun.COM 	}
32817836SJohn.Forte@Sun.COM 
32827836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
32837836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
32847836SJohn.Forte@Sun.COM 	} else {
32857836SJohn.Forte@Sun.COM 		/*EMPTY*/
32867836SJohn.Forte@Sun.COM 		QL_PRINT_9(CE_CONT, "(%d): done\n", ha->instance);
32877836SJohn.Forte@Sun.COM 	}
32887836SJohn.Forte@Sun.COM 
32897836SJohn.Forte@Sun.COM 	return (rval);
32907836SJohn.Forte@Sun.COM }
32917836SJohn.Forte@Sun.COM 
32927836SJohn.Forte@Sun.COM /*
32937836SJohn.Forte@Sun.COM  * ql_set_firmware_option
32947836SJohn.Forte@Sun.COM  *	 Set Firmware Options Mailbox Command.
32957836SJohn.Forte@Sun.COM  *
32967836SJohn.Forte@Sun.COM  * Input:
32977836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
32987836SJohn.Forte@Sun.COM  *	mr:	pointer for mailbox data.
32997836SJohn.Forte@Sun.COM  *
33007836SJohn.Forte@Sun.COM  * Returns:
33017836SJohn.Forte@Sun.COM  *	ql local function return status code.
33027836SJohn.Forte@Sun.COM  *
33037836SJohn.Forte@Sun.COM  * Context:
33047836SJohn.Forte@Sun.COM  *	Kernel context.
33057836SJohn.Forte@Sun.COM  */
33067836SJohn.Forte@Sun.COM int
ql_set_firmware_option(ql_adapter_state_t * ha,ql_mbx_data_t * mr)33077836SJohn.Forte@Sun.COM ql_set_firmware_option(ql_adapter_state_t *ha, ql_mbx_data_t *mr)
33087836SJohn.Forte@Sun.COM {
33097836SJohn.Forte@Sun.COM 	int		rval;
33107836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
33117836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
33127836SJohn.Forte@Sun.COM 
33137836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
33147836SJohn.Forte@Sun.COM 
33157836SJohn.Forte@Sun.COM 	if (mr != NULL) {
33167836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_SET_FIRMWARE_OPTIONS;
33177836SJohn.Forte@Sun.COM 		mcp->mb[1] = mr->mb[1];
33187836SJohn.Forte@Sun.COM 		mcp->mb[2] = mr->mb[2];
33197836SJohn.Forte@Sun.COM 		mcp->mb[3] = mr->mb[3];
33207836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
33217836SJohn.Forte@Sun.COM 		mcp->in_mb = MBX_0;
33227836SJohn.Forte@Sun.COM 		mcp->timeout = MAILBOX_TOV;
33237836SJohn.Forte@Sun.COM 		rval = ql_mailbox_command(ha, mcp);
33247836SJohn.Forte@Sun.COM 	} else {
33257836SJohn.Forte@Sun.COM 		rval = QL_FUNCTION_PARAMETER_ERROR;
33267836SJohn.Forte@Sun.COM 	}
33277836SJohn.Forte@Sun.COM 
33287836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
33297836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
33307836SJohn.Forte@Sun.COM 	} else {
33317836SJohn.Forte@Sun.COM 		/*EMPTY*/
33327836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
33337836SJohn.Forte@Sun.COM 	}
33347836SJohn.Forte@Sun.COM 
33357836SJohn.Forte@Sun.COM 	return (rval);
33367836SJohn.Forte@Sun.COM }
33377836SJohn.Forte@Sun.COM 
33387836SJohn.Forte@Sun.COM /*
33397836SJohn.Forte@Sun.COM  * ql_init_firmware
33407836SJohn.Forte@Sun.COM  *	 Initialize firmware mailbox command.
33417836SJohn.Forte@Sun.COM  *
33427836SJohn.Forte@Sun.COM  * Input:
33437836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
33447836SJohn.Forte@Sun.COM  *	ha->init_ctrl_blk = setup for transmit.
33457836SJohn.Forte@Sun.COM  *
33467836SJohn.Forte@Sun.COM  * Returns:
33477836SJohn.Forte@Sun.COM  *	ql local function return status code.
33487836SJohn.Forte@Sun.COM  *
33497836SJohn.Forte@Sun.COM  * Context:
33507836SJohn.Forte@Sun.COM  *	Kernel context.
33517836SJohn.Forte@Sun.COM  */
33527836SJohn.Forte@Sun.COM int
ql_init_firmware(ql_adapter_state_t * ha)33537836SJohn.Forte@Sun.COM ql_init_firmware(ql_adapter_state_t *ha)
33547836SJohn.Forte@Sun.COM {
33557836SJohn.Forte@Sun.COM 	int		rval;
33567836SJohn.Forte@Sun.COM 	dma_mem_t	mem_desc;
33577836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
33587836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
33597836SJohn.Forte@Sun.COM 
33607836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
33617836SJohn.Forte@Sun.COM 
336211924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_8021)) {
336311924SDaniel.Beauregard@Sun.COM 		WRT32_IO_REG(ha, req_out, 0);
336411924SDaniel.Beauregard@Sun.COM 		WRT32_IO_REG(ha, resp_in, 0);
336511924SDaniel.Beauregard@Sun.COM 		WRT32_IO_REG(ha, resp_out, 0);
336611924SDaniel.Beauregard@Sun.COM 	} else if (CFG_IST(ha, CFG_CTRL_242581)) {
33677836SJohn.Forte@Sun.COM 		WRT32_IO_REG(ha, req_in, 0);
33687836SJohn.Forte@Sun.COM 		WRT32_IO_REG(ha, resp_out, 0);
33697836SJohn.Forte@Sun.COM 		WRT32_IO_REG(ha, pri_req_in, 0);
33707836SJohn.Forte@Sun.COM 		WRT32_IO_REG(ha, atio_req_out, 0);
33717836SJohn.Forte@Sun.COM 	} else {
33727836SJohn.Forte@Sun.COM 		WRT16_IO_REG(ha, req_in, 0);
33737836SJohn.Forte@Sun.COM 		WRT16_IO_REG(ha, resp_out, 0);
33747836SJohn.Forte@Sun.COM 	}
33757836SJohn.Forte@Sun.COM 
33767836SJohn.Forte@Sun.COM 	if ((rval = ql_setup_mbox_dma_transfer(ha, &mem_desc,
33777836SJohn.Forte@Sun.COM 	    (caddr_t)&ha->init_ctrl_blk, sizeof (ql_comb_init_cb_t))) !=
33787836SJohn.Forte@Sun.COM 	    QL_SUCCESS) {
33797836SJohn.Forte@Sun.COM 		EL(ha, "dma setup failed=%xh\n", rval);
33807836SJohn.Forte@Sun.COM 		return (rval);
33817836SJohn.Forte@Sun.COM 	}
33827836SJohn.Forte@Sun.COM 
33837836SJohn.Forte@Sun.COM 	mcp->mb[0] = (uint16_t)(ha->flags & VP_ENABLED ?
33847836SJohn.Forte@Sun.COM 	    MBC_INITIALIZE_MULTI_ID_FW : MBC_INITIALIZE_FIRMWARE);
33857836SJohn.Forte@Sun.COM 
33867836SJohn.Forte@Sun.COM 	if (CFG_IST(ha, CFG_SBUS_CARD)) {
33877836SJohn.Forte@Sun.COM 		mcp->mb[1] = (uint16_t)(CFG_IST(ha, CFG_CTRL_2200) ?
33887836SJohn.Forte@Sun.COM 		    0x204c : 0x52);
33897836SJohn.Forte@Sun.COM 	}
33907836SJohn.Forte@Sun.COM 
33917836SJohn.Forte@Sun.COM 	mcp->mb[2] = MSW(LSD(mem_desc.cookie.dmac_laddress));
33927836SJohn.Forte@Sun.COM 	mcp->mb[3] = LSW(LSD(mem_desc.cookie.dmac_laddress));
33937836SJohn.Forte@Sun.COM 	mcp->mb[6] = MSW(MSD(mem_desc.cookie.dmac_laddress));
33947836SJohn.Forte@Sun.COM 	mcp->mb[7] = LSW(MSD(mem_desc.cookie.dmac_laddress));
339511924SDaniel.Beauregard@Sun.COM 	if (CFG_IST(ha, CFG_CTRL_8081)) {
33969446SDaniel.Beauregard@Sun.COM 		uint64_t		ofst, addr;
33979446SDaniel.Beauregard@Sun.COM 		ql_init_24xx_cb_t	*icb = (ql_init_24xx_cb_t *)
33989446SDaniel.Beauregard@Sun.COM 		    &ha->init_ctrl_blk.cb24;
33999446SDaniel.Beauregard@Sun.COM 
34009446SDaniel.Beauregard@Sun.COM 		mcp->mb[0] = MBC_INITIALIZE_MULTI_ID_FW;
34019446SDaniel.Beauregard@Sun.COM 		if (icb->ext_blk.version[0] | icb->ext_blk.version[1]) {
34029446SDaniel.Beauregard@Sun.COM 			ofst = (uintptr_t)&icb->ext_blk - (uintptr_t)icb;
34039446SDaniel.Beauregard@Sun.COM 			addr = mem_desc.cookie.dmac_laddress + ofst;
34049446SDaniel.Beauregard@Sun.COM 			mcp->mb[10] = MSW(LSD(addr));
34059446SDaniel.Beauregard@Sun.COM 			mcp->mb[11] = LSW(LSD(addr));
34069446SDaniel.Beauregard@Sun.COM 			mcp->mb[12] = MSW(MSD(addr));
34079446SDaniel.Beauregard@Sun.COM 			mcp->mb[13] = LSW(MSD(addr));
34089446SDaniel.Beauregard@Sun.COM 			mcp->mb[14] = sizeof (ql_ext_icb_8100_t);
34099611SDaniel.Beauregard@Sun.COM 			mcp->mb[1] = BIT_0;
34109446SDaniel.Beauregard@Sun.COM 		}
34119446SDaniel.Beauregard@Sun.COM 		mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_7|MBX_6|
34129446SDaniel.Beauregard@Sun.COM 		    MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
34139446SDaniel.Beauregard@Sun.COM 	} else {
34149446SDaniel.Beauregard@Sun.COM 		mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
34159446SDaniel.Beauregard@Sun.COM 	}
34169446SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_5|MBX_4|MBX_2|MBX_0;
34177836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
34187836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
34197836SJohn.Forte@Sun.COM 
34207836SJohn.Forte@Sun.COM 	if (rval == QL_SUCCESS) {
34217836SJohn.Forte@Sun.COM 		ha->sfp_stat = mcp->mb[2];
34227836SJohn.Forte@Sun.COM 	}
34237836SJohn.Forte@Sun.COM 	ql_free_dma_resource(ha, &mem_desc);
34247836SJohn.Forte@Sun.COM 
34257836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
34267836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
34277836SJohn.Forte@Sun.COM 	} else {
34287836SJohn.Forte@Sun.COM 		/*EMPTY*/
34297836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
34307836SJohn.Forte@Sun.COM 	}
34317836SJohn.Forte@Sun.COM 
34327836SJohn.Forte@Sun.COM 	return (rval);
34337836SJohn.Forte@Sun.COM }
34347836SJohn.Forte@Sun.COM 
34357836SJohn.Forte@Sun.COM /*
34367836SJohn.Forte@Sun.COM  * ql_get_firmware_state
34377836SJohn.Forte@Sun.COM  *	Get adapter firmware state.
34387836SJohn.Forte@Sun.COM  *
34397836SJohn.Forte@Sun.COM  * Input:
34407836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
34417836SJohn.Forte@Sun.COM  *	mr:	pointer for mailbox data.
34427836SJohn.Forte@Sun.COM  *
34437836SJohn.Forte@Sun.COM  * Returns:
34447836SJohn.Forte@Sun.COM  *	ql local function return status code.
34457836SJohn.Forte@Sun.COM  *
34467836SJohn.Forte@Sun.COM  * Context:
34477836SJohn.Forte@Sun.COM  *	Kernel context.
34487836SJohn.Forte@Sun.COM  */
34497836SJohn.Forte@Sun.COM int
ql_get_firmware_state(ql_adapter_state_t * ha,ql_mbx_data_t * mr)34507836SJohn.Forte@Sun.COM ql_get_firmware_state(ql_adapter_state_t *ha, ql_mbx_data_t *mr)
34517836SJohn.Forte@Sun.COM {
34527836SJohn.Forte@Sun.COM 	int		rval;
34537836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
34547836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
34557836SJohn.Forte@Sun.COM 
34567836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
34577836SJohn.Forte@Sun.COM 
34587836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
34597836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_0;
34609611SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
34617836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
34627836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
34637836SJohn.Forte@Sun.COM 
34647836SJohn.Forte@Sun.COM 	/* Return mailbox data. */
34657836SJohn.Forte@Sun.COM 	if (mr != NULL) {
34667836SJohn.Forte@Sun.COM 		mr->mb[1] = mcp->mb[1];
34677836SJohn.Forte@Sun.COM 		mr->mb[2] = mcp->mb[2];
34687836SJohn.Forte@Sun.COM 		mr->mb[3] = mcp->mb[3];
34699611SDaniel.Beauregard@Sun.COM 		mr->mb[4] = mcp->mb[4];
34709611SDaniel.Beauregard@Sun.COM 		mr->mb[5] = mcp->mb[5];
34717836SJohn.Forte@Sun.COM 	}
34727836SJohn.Forte@Sun.COM 
34737836SJohn.Forte@Sun.COM 	ha->sfp_stat = mcp->mb[2];
34747836SJohn.Forte@Sun.COM 
34757836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
34767836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
34777836SJohn.Forte@Sun.COM 	} else {
34787836SJohn.Forte@Sun.COM 		/*EMPTY*/
34797836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
34807836SJohn.Forte@Sun.COM 	}
34817836SJohn.Forte@Sun.COM 
34827836SJohn.Forte@Sun.COM 	return (rval);
34837836SJohn.Forte@Sun.COM }
34847836SJohn.Forte@Sun.COM 
34857836SJohn.Forte@Sun.COM /*
34867836SJohn.Forte@Sun.COM  * ql_get_adapter_id
34877836SJohn.Forte@Sun.COM  *	Get adapter ID and topology.
34887836SJohn.Forte@Sun.COM  *
34897836SJohn.Forte@Sun.COM  * Input:
34907836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
34917836SJohn.Forte@Sun.COM  *	mr:	pointer for mailbox data.
34927836SJohn.Forte@Sun.COM  *
34937836SJohn.Forte@Sun.COM  * Returns:
34947836SJohn.Forte@Sun.COM  *	ql local function return status code.
34957836SJohn.Forte@Sun.COM  *
34967836SJohn.Forte@Sun.COM  * Context:
34977836SJohn.Forte@Sun.COM  *	Kernel context.
34987836SJohn.Forte@Sun.COM  */
34997836SJohn.Forte@Sun.COM int
ql_get_adapter_id(ql_adapter_state_t * ha,ql_mbx_data_t * mr)35007836SJohn.Forte@Sun.COM ql_get_adapter_id(ql_adapter_state_t *ha, ql_mbx_data_t *mr)
35017836SJohn.Forte@Sun.COM {
35027836SJohn.Forte@Sun.COM 	int		rval;
35037836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
35047836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
35057836SJohn.Forte@Sun.COM 
35067836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
35077836SJohn.Forte@Sun.COM 
35087836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_GET_ID;
35097836SJohn.Forte@Sun.COM 	if (ha->flags & VP_ENABLED) {
35107836SJohn.Forte@Sun.COM 		mcp->mb[9] = ha->vp_index;
35117836SJohn.Forte@Sun.COM 	}
35129446SDaniel.Beauregard@Sun.COM 	mcp->out_mb = MBX_9|MBX_0;
35139446SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|
35149446SDaniel.Beauregard@Sun.COM 	    MBX_3|MBX_2|MBX_1|MBX_0;
35157836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
35169156SDaniel.Beauregard@Sun.COM 
35177836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
35187836SJohn.Forte@Sun.COM 
35197836SJohn.Forte@Sun.COM 	/* Return mailbox data. */
35207836SJohn.Forte@Sun.COM 	if (mr != NULL) {
35217836SJohn.Forte@Sun.COM 		mr->mb[1] = mcp->mb[1];
352211924SDaniel.Beauregard@Sun.COM 		mr->mb[1] = (uint16_t)(CFG_IST(ha, CFG_CTRL_24258081) ?
35237836SJohn.Forte@Sun.COM 		    0xffff : mcp->mb[1]);
35247836SJohn.Forte@Sun.COM 		mr->mb[2] = mcp->mb[2];
35257836SJohn.Forte@Sun.COM 		mr->mb[3] = mcp->mb[3];
35267836SJohn.Forte@Sun.COM 		mr->mb[6] = mcp->mb[6];
35277836SJohn.Forte@Sun.COM 		mr->mb[7] = mcp->mb[7];
35289446SDaniel.Beauregard@Sun.COM 		mr->mb[8] = mcp->mb[8];
35299446SDaniel.Beauregard@Sun.COM 		mr->mb[9] = mcp->mb[9];
35309446SDaniel.Beauregard@Sun.COM 		mr->mb[10] = mcp->mb[10];
35319446SDaniel.Beauregard@Sun.COM 		mr->mb[11] = mcp->mb[11];
35329446SDaniel.Beauregard@Sun.COM 		mr->mb[12] = mcp->mb[12];
35339446SDaniel.Beauregard@Sun.COM 		mr->mb[13] = mcp->mb[13];
35347836SJohn.Forte@Sun.COM 	}
35357836SJohn.Forte@Sun.COM 
35367836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
35377836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
35387836SJohn.Forte@Sun.COM 	} else {
35397836SJohn.Forte@Sun.COM 		/*EMPTY*/
35407836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
35417836SJohn.Forte@Sun.COM 	}
35427836SJohn.Forte@Sun.COM 
35437836SJohn.Forte@Sun.COM 	return (rval);
35447836SJohn.Forte@Sun.COM }
35457836SJohn.Forte@Sun.COM 
35467836SJohn.Forte@Sun.COM /*
35477836SJohn.Forte@Sun.COM  * ql_get_fw_version
35487836SJohn.Forte@Sun.COM  *	Get firmware version.
35497836SJohn.Forte@Sun.COM  *
35507836SJohn.Forte@Sun.COM  * Input:
35517836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
35527836SJohn.Forte@Sun.COM  *	mr:	pointer for mailbox data.
35537836SJohn.Forte@Sun.COM  *
35547836SJohn.Forte@Sun.COM  * Returns:
35557836SJohn.Forte@Sun.COM  *	ql local function return status code.
35567836SJohn.Forte@Sun.COM  *
35577836SJohn.Forte@Sun.COM  * Context:
35587836SJohn.Forte@Sun.COM  *	Kernel context.
35597836SJohn.Forte@Sun.COM  */
35607836SJohn.Forte@Sun.COM int
ql_get_fw_version(ql_adapter_state_t * ha,ql_mbx_data_t * mr,uint16_t timeout)356111924SDaniel.Beauregard@Sun.COM ql_get_fw_version(ql_adapter_state_t *ha, ql_mbx_data_t *mr, uint16_t timeout)
35627836SJohn.Forte@Sun.COM {
35637836SJohn.Forte@Sun.COM 	int		rval;
35647836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
35657836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
35667836SJohn.Forte@Sun.COM 
35677836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
35687836SJohn.Forte@Sun.COM 
35697836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_ABOUT_FIRMWARE;
35707836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_0;
35719446SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_6|MBX_5|
35729446SDaniel.Beauregard@Sun.COM 	    MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
357311924SDaniel.Beauregard@Sun.COM 	mcp->timeout = timeout;
35747836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
35757836SJohn.Forte@Sun.COM 
35767836SJohn.Forte@Sun.COM 	/* Return mailbox data. */
35777836SJohn.Forte@Sun.COM 	if (mr != NULL) {
35787836SJohn.Forte@Sun.COM 		mr->mb[1] = mcp->mb[1];
35797836SJohn.Forte@Sun.COM 		mr->mb[2] = mcp->mb[2];
35807836SJohn.Forte@Sun.COM 		mr->mb[3] = mcp->mb[3];
35817836SJohn.Forte@Sun.COM 		mr->mb[4] = mcp->mb[4];
35827836SJohn.Forte@Sun.COM 		mr->mb[5] = mcp->mb[5];
35837836SJohn.Forte@Sun.COM 		mr->mb[6] = mcp->mb[6];
35849446SDaniel.Beauregard@Sun.COM 		mr->mb[8] = mcp->mb[8];
35859446SDaniel.Beauregard@Sun.COM 		mr->mb[9] = mcp->mb[9];
35869446SDaniel.Beauregard@Sun.COM 		mr->mb[10] = mcp->mb[10];
35879446SDaniel.Beauregard@Sun.COM 		mr->mb[11] = mcp->mb[11];
35889446SDaniel.Beauregard@Sun.COM 		mr->mb[12] = mcp->mb[12];
35899446SDaniel.Beauregard@Sun.COM 		mr->mb[13] = mcp->mb[13];
35907836SJohn.Forte@Sun.COM 	}
35917836SJohn.Forte@Sun.COM 
35927836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
35937836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
35947836SJohn.Forte@Sun.COM 	} else {
35957836SJohn.Forte@Sun.COM 		/*EMPTY*/
35967836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
35977836SJohn.Forte@Sun.COM 	}
35987836SJohn.Forte@Sun.COM 
35997836SJohn.Forte@Sun.COM 	return (rval);
36007836SJohn.Forte@Sun.COM }
36017836SJohn.Forte@Sun.COM 
36027836SJohn.Forte@Sun.COM /*
36037836SJohn.Forte@Sun.COM  * ql_data_rate
36047836SJohn.Forte@Sun.COM  *	 Issue data rate Mailbox Command.
36057836SJohn.Forte@Sun.COM  *
36067836SJohn.Forte@Sun.COM  * Input:
36077836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
36087836SJohn.Forte@Sun.COM  *	mr:	pointer for mailbox data.
36097836SJohn.Forte@Sun.COM  *
36107836SJohn.Forte@Sun.COM  * Returns:
36117836SJohn.Forte@Sun.COM  *	ql local function return status code.
36127836SJohn.Forte@Sun.COM  *
36137836SJohn.Forte@Sun.COM  * Context:
36147836SJohn.Forte@Sun.COM  *	Kernel context.
36157836SJohn.Forte@Sun.COM  */
36167836SJohn.Forte@Sun.COM int
ql_data_rate(ql_adapter_state_t * ha,ql_mbx_data_t * mr)36177836SJohn.Forte@Sun.COM ql_data_rate(ql_adapter_state_t *ha, ql_mbx_data_t *mr)
36187836SJohn.Forte@Sun.COM {
36197836SJohn.Forte@Sun.COM 	int		rval;
36207836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
36217836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
36227836SJohn.Forte@Sun.COM 
36237836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
36247836SJohn.Forte@Sun.COM 
36257836SJohn.Forte@Sun.COM 	if (mr != NULL) {
36267836SJohn.Forte@Sun.COM 		mcp->mb[0] = MBC_DATA_RATE;
36277836SJohn.Forte@Sun.COM 		mcp->mb[1] = mr->mb[1];
36287836SJohn.Forte@Sun.COM 		mcp->mb[2] = mr->mb[2];
36297836SJohn.Forte@Sun.COM 		mcp->out_mb = MBX_2|MBX_1|MBX_0;
36307836SJohn.Forte@Sun.COM 		mcp->in_mb = MBX_2|MBX_1|MBX_0;
36317836SJohn.Forte@Sun.COM 		mcp->timeout = MAILBOX_TOV;
36327836SJohn.Forte@Sun.COM 		rval = ql_mailbox_command(ha, mcp);
36337836SJohn.Forte@Sun.COM 
36347836SJohn.Forte@Sun.COM 		/* Return mailbox data. */
36357836SJohn.Forte@Sun.COM 		mr->mb[1] = mcp->mb[1];
36367836SJohn.Forte@Sun.COM 		mr->mb[2] = mcp->mb[2];
36377836SJohn.Forte@Sun.COM 	} else {
36387836SJohn.Forte@Sun.COM 		rval = QL_FUNCTION_PARAMETER_ERROR;
36397836SJohn.Forte@Sun.COM 	}
36407836SJohn.Forte@Sun.COM 
36417836SJohn.Forte@Sun.COM 	ha->sfp_stat = mcp->mb[2];
36427836SJohn.Forte@Sun.COM 
36437836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
36447836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
36457836SJohn.Forte@Sun.COM 	} else {
36467836SJohn.Forte@Sun.COM 		/*EMPTY*/
36477836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
36487836SJohn.Forte@Sun.COM 	}
36497836SJohn.Forte@Sun.COM 
36507836SJohn.Forte@Sun.COM 	return (rval);
36517836SJohn.Forte@Sun.COM }
36527836SJohn.Forte@Sun.COM 
36537836SJohn.Forte@Sun.COM /*
36547836SJohn.Forte@Sun.COM  * ql_Diag_Loopback
36557836SJohn.Forte@Sun.COM  *	Issue Reset Link Status mailbox command
36567836SJohn.Forte@Sun.COM  *
36577836SJohn.Forte@Sun.COM  * Input:
36587836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
36599611SDaniel.Beauregard@Sun.COM  *	findex:	FCF index.
36607836SJohn.Forte@Sun.COM  *	bp:	buffer pointer.
36617836SJohn.Forte@Sun.COM  *	size:	buffer size.
36627836SJohn.Forte@Sun.COM  *	opt:	command options.
36637836SJohn.Forte@Sun.COM  *	it_cnt:	iteration count.
36647836SJohn.Forte@Sun.COM  *	mr:	pointer for mailbox data.
36657836SJohn.Forte@Sun.COM  *
36667836SJohn.Forte@Sun.COM  * Returns:
36677836SJohn.Forte@Sun.COM  *	ql local function return status code.
36687836SJohn.Forte@Sun.COM  *
36697836SJohn.Forte@Sun.COM  * Context:
36707836SJohn.Forte@Sun.COM  *	Kernel context.
36717836SJohn.Forte@Sun.COM  */
36727836SJohn.Forte@Sun.COM int
ql_diag_loopback(ql_adapter_state_t * ha,uint16_t findex,caddr_t bp,uint32_t size,uint16_t opt,uint32_t it_cnt,ql_mbx_data_t * mr)36739611SDaniel.Beauregard@Sun.COM ql_diag_loopback(ql_adapter_state_t *ha, uint16_t findex, caddr_t bp,
36749611SDaniel.Beauregard@Sun.COM     uint32_t size, uint16_t opt, uint32_t it_cnt, ql_mbx_data_t *mr)
36757836SJohn.Forte@Sun.COM {
36767836SJohn.Forte@Sun.COM 	int		rval;
36777836SJohn.Forte@Sun.COM 	dma_mem_t	mem_desc;
36787836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
36797836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
36807836SJohn.Forte@Sun.COM 
36817836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
36827836SJohn.Forte@Sun.COM 
36837836SJohn.Forte@Sun.COM 	if ((rval = ql_setup_mbox_dma_transfer(ha, &mem_desc, bp, size)) !=
36847836SJohn.Forte@Sun.COM 	    QL_SUCCESS) {
36857836SJohn.Forte@Sun.COM 		EL(ha, "setup_mbox_dma_transfer failed: %x\n", rval);
36867836SJohn.Forte@Sun.COM 		return (rval);
36877836SJohn.Forte@Sun.COM 	}
36887836SJohn.Forte@Sun.COM 
36897836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
36907836SJohn.Forte@Sun.COM 	mcp->mb[1] = opt;
36919611SDaniel.Beauregard@Sun.COM 	mcp->mb[2] = findex;
36927836SJohn.Forte@Sun.COM 	mcp->mb[6] = LSW(MSD(mem_desc.cookie.dmac_laddress));
36937836SJohn.Forte@Sun.COM 	mcp->mb[7] = MSW(MSD(mem_desc.cookie.dmac_laddress));
36947836SJohn.Forte@Sun.COM 	mcp->mb[10] = LSW(size);
36957836SJohn.Forte@Sun.COM 	mcp->mb[11] = MSW(size);
36967836SJohn.Forte@Sun.COM 	mcp->mb[14] = LSW(LSD(mem_desc.cookie.dmac_laddress));
36977836SJohn.Forte@Sun.COM 	mcp->mb[15] = MSW(LSD(mem_desc.cookie.dmac_laddress));
36987836SJohn.Forte@Sun.COM 	mcp->mb[16] = LSW(LSD(mem_desc.cookie.dmac_laddress));
36997836SJohn.Forte@Sun.COM 	mcp->mb[17] = MSW(LSD(mem_desc.cookie.dmac_laddress));
37007836SJohn.Forte@Sun.COM 	mcp->mb[18] = LSW(it_cnt);
37017836SJohn.Forte@Sun.COM 	mcp->mb[19] = MSW(it_cnt);
37027836SJohn.Forte@Sun.COM 	mcp->mb[20] = LSW(MSD(mem_desc.cookie.dmac_laddress));
37037836SJohn.Forte@Sun.COM 	mcp->mb[21] = MSW(MSD(mem_desc.cookie.dmac_laddress));
37047836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
37059611SDaniel.Beauregard@Sun.COM 	    MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
37067836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
37077836SJohn.Forte@Sun.COM 	mcp->timeout = it_cnt / 300;
37087836SJohn.Forte@Sun.COM 	if (mcp->timeout < MAILBOX_TOV) {
37097836SJohn.Forte@Sun.COM 		mcp->timeout = MAILBOX_TOV;
37107836SJohn.Forte@Sun.COM 	}
37117836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
37127836SJohn.Forte@Sun.COM 
37137836SJohn.Forte@Sun.COM 	if (rval == QL_SUCCESS) {
37147836SJohn.Forte@Sun.COM 		ql_get_mbox_dma_data(&mem_desc, bp);
37157836SJohn.Forte@Sun.COM 	}
37167836SJohn.Forte@Sun.COM 
37177836SJohn.Forte@Sun.COM 	ql_free_dma_resource(ha, &mem_desc);
37187836SJohn.Forte@Sun.COM 
37197836SJohn.Forte@Sun.COM 	/* Return mailbox data. */
37207836SJohn.Forte@Sun.COM 	if (mr != NULL) {
37217836SJohn.Forte@Sun.COM 		mr->mb[0] = mcp->mb[0];
37227836SJohn.Forte@Sun.COM 		mr->mb[1] = mcp->mb[1];
37237836SJohn.Forte@Sun.COM 		mr->mb[2] = mcp->mb[2];
37247836SJohn.Forte@Sun.COM 		mr->mb[3] = mcp->mb[3];
37257836SJohn.Forte@Sun.COM 		mr->mb[18] = mcp->mb[18];
37267836SJohn.Forte@Sun.COM 		mr->mb[19] = mcp->mb[19];
37277836SJohn.Forte@Sun.COM 	}
37287836SJohn.Forte@Sun.COM 
37297836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
373011924SDaniel.Beauregard@Sun.COM 		EL(ha, "failed=%xh, mb1=%xh\n", rval, mcp->mb[1]);
37317836SJohn.Forte@Sun.COM 	} else {
37327836SJohn.Forte@Sun.COM 		/*EMPTY*/
37337836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
37347836SJohn.Forte@Sun.COM 	}
37357836SJohn.Forte@Sun.COM 
37367836SJohn.Forte@Sun.COM 	return (rval);
37377836SJohn.Forte@Sun.COM }
37387836SJohn.Forte@Sun.COM 
37397836SJohn.Forte@Sun.COM /*
37407836SJohn.Forte@Sun.COM  * ql_diag_echo
37417836SJohn.Forte@Sun.COM  *	Issue Diag echo mailbox command.  Valid for qla23xx HBA's.
37427836SJohn.Forte@Sun.COM  *
37437836SJohn.Forte@Sun.COM  * Input:
37447836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
37459611SDaniel.Beauregard@Sun.COM  *	findex:	FCF index.
37467836SJohn.Forte@Sun.COM  *	bp:	buffer pointer.
37477836SJohn.Forte@Sun.COM  *	size:	buffer size.
37487836SJohn.Forte@Sun.COM  *	opt:	command options.
37497836SJohn.Forte@Sun.COM  *	mr:	pointer to mailbox status.
37507836SJohn.Forte@Sun.COM  *
37517836SJohn.Forte@Sun.COM  * Returns:
37527836SJohn.Forte@Sun.COM  *	ql local function return status code.
37537836SJohn.Forte@Sun.COM  *
37547836SJohn.Forte@Sun.COM  * Context:
37557836SJohn.Forte@Sun.COM  *	Kernel context.
37567836SJohn.Forte@Sun.COM  */
37577836SJohn.Forte@Sun.COM int
ql_diag_echo(ql_adapter_state_t * ha,uint16_t findex,caddr_t bp,uint32_t size,uint16_t opt,ql_mbx_data_t * mr)37589611SDaniel.Beauregard@Sun.COM ql_diag_echo(ql_adapter_state_t *ha, uint16_t findex, caddr_t bp,
37599611SDaniel.Beauregard@Sun.COM     uint32_t size, uint16_t opt, ql_mbx_data_t *mr)
37607836SJohn.Forte@Sun.COM {
37617836SJohn.Forte@Sun.COM 	int		rval;
37627836SJohn.Forte@Sun.COM 	dma_mem_t	mem_desc;
37637836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
37647836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
37657836SJohn.Forte@Sun.COM 
37667836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
37677836SJohn.Forte@Sun.COM 
37687836SJohn.Forte@Sun.COM 	if ((rval = ql_setup_mbox_dma_transfer(ha, &mem_desc, bp, size)) !=
37697836SJohn.Forte@Sun.COM 	    QL_SUCCESS) {
37707836SJohn.Forte@Sun.COM 		EL(ha, "setup_mbox_dma_transfer failed: %x\n", rval);
37717836SJohn.Forte@Sun.COM 		return (rval);
37727836SJohn.Forte@Sun.COM 	}
37737836SJohn.Forte@Sun.COM 
37747836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_ECHO;
377510736SDaniel.Beauregard@Sun.COM 	mcp->mb[1] = opt;
37769611SDaniel.Beauregard@Sun.COM 	mcp->mb[2] = findex;
37777836SJohn.Forte@Sun.COM 	mcp->mb[6] = LSW(MSD(mem_desc.cookie.dmac_laddress));
37787836SJohn.Forte@Sun.COM 	mcp->mb[7] = MSW(MSD(mem_desc.cookie.dmac_laddress));
37797836SJohn.Forte@Sun.COM 	mcp->mb[10] = LSW(size);
37807836SJohn.Forte@Sun.COM 	mcp->mb[14] = LSW(LSD(mem_desc.cookie.dmac_laddress));
37817836SJohn.Forte@Sun.COM 	mcp->mb[15] = MSW(LSD(mem_desc.cookie.dmac_laddress));
37827836SJohn.Forte@Sun.COM 	mcp->mb[16] = LSW(LSD(mem_desc.cookie.dmac_laddress));
37837836SJohn.Forte@Sun.COM 	mcp->mb[17] = MSW(LSD(mem_desc.cookie.dmac_laddress));
37847836SJohn.Forte@Sun.COM 	mcp->mb[20] = LSW(MSD(mem_desc.cookie.dmac_laddress));
37857836SJohn.Forte@Sun.COM 	mcp->mb[21] = MSW(MSD(mem_desc.cookie.dmac_laddress));
37867836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
37879611SDaniel.Beauregard@Sun.COM 	    MBX_14|MBX_10|MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
37887836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_1|MBX_0;
37897836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
37907836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
37917836SJohn.Forte@Sun.COM 
37927836SJohn.Forte@Sun.COM 	if (rval == QL_SUCCESS) {
37937836SJohn.Forte@Sun.COM 		ql_get_mbox_dma_data(&mem_desc, bp);
37947836SJohn.Forte@Sun.COM 	}
37957836SJohn.Forte@Sun.COM 
37967836SJohn.Forte@Sun.COM 	ql_free_dma_resource(ha, &mem_desc);
37977836SJohn.Forte@Sun.COM 
37987836SJohn.Forte@Sun.COM 	if (mr != NULL) {
37997836SJohn.Forte@Sun.COM 		mr->mb[0] = mcp->mb[0];
38007836SJohn.Forte@Sun.COM 	}
38017836SJohn.Forte@Sun.COM 
38027836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
38037836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh, mb1=%xh\n", rval,
38047836SJohn.Forte@Sun.COM 		    mcp->mb[1]);
38057836SJohn.Forte@Sun.COM 	} else {
38067836SJohn.Forte@Sun.COM 		/*EMPTY*/
38077836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
38087836SJohn.Forte@Sun.COM 	}
38097836SJohn.Forte@Sun.COM 
38107836SJohn.Forte@Sun.COM 	return (rval);
38117836SJohn.Forte@Sun.COM }
38127836SJohn.Forte@Sun.COM 
38137836SJohn.Forte@Sun.COM /*
38147836SJohn.Forte@Sun.COM  * ql_serdes_param
38157836SJohn.Forte@Sun.COM  *	Set/Get serdes transmit parameters mailbox command.
38167836SJohn.Forte@Sun.COM  *
38177836SJohn.Forte@Sun.COM  * Input:
38187836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
38197836SJohn.Forte@Sun.COM  *	mr:	pointer to mailbox in/out parameters.
38207836SJohn.Forte@Sun.COM  *
38217836SJohn.Forte@Sun.COM  * Returns:
38227836SJohn.Forte@Sun.COM  *	ql local function return status code.
38237836SJohn.Forte@Sun.COM  *
38247836SJohn.Forte@Sun.COM  * Context:
38257836SJohn.Forte@Sun.COM  *	Kernel context.
38267836SJohn.Forte@Sun.COM  */
38277836SJohn.Forte@Sun.COM int
ql_serdes_param(ql_adapter_state_t * ha,ql_mbx_data_t * mr)38287836SJohn.Forte@Sun.COM ql_serdes_param(ql_adapter_state_t *ha, ql_mbx_data_t *mr)
38297836SJohn.Forte@Sun.COM {
38307836SJohn.Forte@Sun.COM 	int		rval;
38317836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
38327836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
38337836SJohn.Forte@Sun.COM 
38347836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
38357836SJohn.Forte@Sun.COM 
38367836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_SERDES_TRANSMIT_PARAMETERS;
38377836SJohn.Forte@Sun.COM 	mcp->mb[1] = mr->mb[1];
38387836SJohn.Forte@Sun.COM 	mcp->mb[2] = mr->mb[2];
38397836SJohn.Forte@Sun.COM 	mcp->mb[3] = mr->mb[3];
38407836SJohn.Forte@Sun.COM 	mcp->mb[4] = mr->mb[4];
38417836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
38427836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_0;
38437836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
38447836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
38457836SJohn.Forte@Sun.COM 
38467836SJohn.Forte@Sun.COM 	/* Return mailbox data. */
38477836SJohn.Forte@Sun.COM 	if (mr != NULL) {
38487836SJohn.Forte@Sun.COM 		mr->mb[0] = mcp->mb[0];
38497836SJohn.Forte@Sun.COM 		mr->mb[2] = mcp->mb[2];
38507836SJohn.Forte@Sun.COM 		mr->mb[3] = mcp->mb[3];
38517836SJohn.Forte@Sun.COM 		mr->mb[4] = mcp->mb[4];
38527836SJohn.Forte@Sun.COM 	}
38537836SJohn.Forte@Sun.COM 
38547836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
38557836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
38567836SJohn.Forte@Sun.COM 	} else {
38577836SJohn.Forte@Sun.COM 		/*EMPTY*/
38587836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
38597836SJohn.Forte@Sun.COM 	}
38607836SJohn.Forte@Sun.COM 
38617836SJohn.Forte@Sun.COM 	return (rval);
38627836SJohn.Forte@Sun.COM }
38637836SJohn.Forte@Sun.COM 
38647836SJohn.Forte@Sun.COM /*
38657836SJohn.Forte@Sun.COM  * ql_get_timeout_parameters
38667836SJohn.Forte@Sun.COM  *	Issue get timeout parameters mailbox command.
38677836SJohn.Forte@Sun.COM  *
38687836SJohn.Forte@Sun.COM  * Input:
38697836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
38707836SJohn.Forte@Sun.COM  *	mr:	pointer to mailbox in/out parameters.
38717836SJohn.Forte@Sun.COM  *
38727836SJohn.Forte@Sun.COM  * Returns:
38737836SJohn.Forte@Sun.COM  *	ql local function return status code.
38747836SJohn.Forte@Sun.COM  *
38757836SJohn.Forte@Sun.COM  * Context:
38767836SJohn.Forte@Sun.COM  *	Kernel context.
38777836SJohn.Forte@Sun.COM  */
38787836SJohn.Forte@Sun.COM int
ql_get_timeout_parameters(ql_adapter_state_t * ha,uint16_t * tov)38797836SJohn.Forte@Sun.COM ql_get_timeout_parameters(ql_adapter_state_t *ha, uint16_t *tov)
38807836SJohn.Forte@Sun.COM {
38817836SJohn.Forte@Sun.COM 	int		rval;
38827836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
38837836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
38847836SJohn.Forte@Sun.COM 
38857836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
38867836SJohn.Forte@Sun.COM 
38877836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_GET_TIMEOUT_PARAMETERS;
38887836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_0;
38897836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_3|MBX_0;
38907836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
38917836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
38927836SJohn.Forte@Sun.COM 	if (rval == QL_SUCCESS) {
38937836SJohn.Forte@Sun.COM 		/* Get 2 * R_A_TOV in seconds */
38947836SJohn.Forte@Sun.COM 		if (CFG_IST(ha, CFG_CTRL_2200) || mcp->mb[3] == 0) {
38957836SJohn.Forte@Sun.COM 			*tov = R_A_TOV_DEFAULT;
38967836SJohn.Forte@Sun.COM 		} else {
38977836SJohn.Forte@Sun.COM 			*tov = (uint16_t)(mcp->mb[3] / 10);
38987836SJohn.Forte@Sun.COM 			if (mcp->mb[3] % 10 != 0) {
38997836SJohn.Forte@Sun.COM 				*tov = (uint16_t)(*tov + 1);
39007836SJohn.Forte@Sun.COM 			}
39017836SJohn.Forte@Sun.COM 			/*
39027836SJohn.Forte@Sun.COM 			 * Adjust value to prevent driver timeout at the same
39037836SJohn.Forte@Sun.COM 			 * time as device.
39047836SJohn.Forte@Sun.COM 			 */
39057836SJohn.Forte@Sun.COM 			*tov = (uint16_t)(*tov + 5);
39067836SJohn.Forte@Sun.COM 		}
39077836SJohn.Forte@Sun.COM 	} else {
39087836SJohn.Forte@Sun.COM 		*tov = R_A_TOV_DEFAULT;
39097836SJohn.Forte@Sun.COM 	}
39107836SJohn.Forte@Sun.COM 
39117836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
39127836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
39137836SJohn.Forte@Sun.COM 	} else {
39147836SJohn.Forte@Sun.COM 		/*EMPTY*/
39157836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
39167836SJohn.Forte@Sun.COM 	}
39177836SJohn.Forte@Sun.COM 
39187836SJohn.Forte@Sun.COM 	return (rval);
39197836SJohn.Forte@Sun.COM }
39207836SJohn.Forte@Sun.COM 
39217836SJohn.Forte@Sun.COM /*
39227836SJohn.Forte@Sun.COM  * ql_stop_firmware
39237836SJohn.Forte@Sun.COM  *	 Issue stop firmware Mailbox Command.
39247836SJohn.Forte@Sun.COM  *
39257836SJohn.Forte@Sun.COM  * Input:
39267836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
39277836SJohn.Forte@Sun.COM  *
39287836SJohn.Forte@Sun.COM  * Returns:
39297836SJohn.Forte@Sun.COM  *	ql local function return status code.
39307836SJohn.Forte@Sun.COM  *
39317836SJohn.Forte@Sun.COM  * Context:
39327836SJohn.Forte@Sun.COM  *	Kernel context.
39337836SJohn.Forte@Sun.COM  */
39347836SJohn.Forte@Sun.COM int
ql_stop_firmware(ql_adapter_state_t * ha)39357836SJohn.Forte@Sun.COM ql_stop_firmware(ql_adapter_state_t *ha)
39367836SJohn.Forte@Sun.COM {
39377836SJohn.Forte@Sun.COM 	int		rval;
39387836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
39397836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
39407836SJohn.Forte@Sun.COM 
39417836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
39427836SJohn.Forte@Sun.COM 
39437836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_STOP_FIRMWARE;
394411924SDaniel.Beauregard@Sun.COM 	mcp->out_mb = MBX_1|MBX_0;
39457836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0;
3946*12279SDaniel.Beauregard@Sun.COM 	mcp->timeout = 2;
39477836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
39487836SJohn.Forte@Sun.COM 
39497836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
39507836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
39517836SJohn.Forte@Sun.COM 	} else {
39527836SJohn.Forte@Sun.COM 		/*EMPTY*/
39537836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
39547836SJohn.Forte@Sun.COM 	}
39557836SJohn.Forte@Sun.COM 
39567836SJohn.Forte@Sun.COM 	return (rval);
39577836SJohn.Forte@Sun.COM }
39587836SJohn.Forte@Sun.COM 
39597836SJohn.Forte@Sun.COM /*
39607836SJohn.Forte@Sun.COM  * ql_read_sfp
39617836SJohn.Forte@Sun.COM  *	Issue Read SFP Mailbox command
39627836SJohn.Forte@Sun.COM  *
39637836SJohn.Forte@Sun.COM  * Input:
39647836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
39657836SJohn.Forte@Sun.COM  *	mem:	pointer to dma memory object for command.
39667836SJohn.Forte@Sun.COM  *	dev:	Device address (A0h or A2h).
396711924SDaniel.Beauregard@Sun.COM  *	addr:	Data address on SFP EEPROM (0�255).
39687836SJohn.Forte@Sun.COM  *
39697836SJohn.Forte@Sun.COM  * Returns:
39707836SJohn.Forte@Sun.COM  *	ql local function return status code.
39717836SJohn.Forte@Sun.COM  *
39727836SJohn.Forte@Sun.COM  * Context:
39737836SJohn.Forte@Sun.COM  *	Kernel context.
39747836SJohn.Forte@Sun.COM  */
39757836SJohn.Forte@Sun.COM int
ql_read_sfp(ql_adapter_state_t * ha,dma_mem_t * mem,uint16_t dev,uint16_t addr)39767836SJohn.Forte@Sun.COM ql_read_sfp(ql_adapter_state_t *ha, dma_mem_t *mem, uint16_t dev,
39777836SJohn.Forte@Sun.COM     uint16_t addr)
39787836SJohn.Forte@Sun.COM {
39797836SJohn.Forte@Sun.COM 	int		rval;
39807836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
39817836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
39827836SJohn.Forte@Sun.COM 
39839446SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
39847836SJohn.Forte@Sun.COM 
39857836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_READ_SFP;
39867836SJohn.Forte@Sun.COM 	mcp->mb[1] = dev;
39877836SJohn.Forte@Sun.COM 	mcp->mb[2] = MSW(mem->cookies->dmac_address);
39887836SJohn.Forte@Sun.COM 	mcp->mb[3] = LSW(mem->cookies->dmac_address);
39897836SJohn.Forte@Sun.COM 	mcp->mb[6] = MSW(mem->cookies->dmac_notused);
39907836SJohn.Forte@Sun.COM 	mcp->mb[7] = LSW(mem->cookies->dmac_notused);
39917836SJohn.Forte@Sun.COM 	mcp->mb[8] = LSW(mem->size);
39927836SJohn.Forte@Sun.COM 	mcp->mb[9] = addr;
39937836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
39947836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_1|MBX_0;
39957836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
39967836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
39977836SJohn.Forte@Sun.COM 
39987836SJohn.Forte@Sun.COM 	(void) ddi_dma_sync(mem->dma_handle, 0, mem->size,
39997836SJohn.Forte@Sun.COM 	    DDI_DMA_SYNC_FORKERNEL);
40007836SJohn.Forte@Sun.COM 
40017836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
40027836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
40037836SJohn.Forte@Sun.COM 	} else {
40047836SJohn.Forte@Sun.COM 		/*EMPTY*/
40059446SDaniel.Beauregard@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
40067836SJohn.Forte@Sun.COM 	}
40077836SJohn.Forte@Sun.COM 
40087836SJohn.Forte@Sun.COM 	return (rval);
40097836SJohn.Forte@Sun.COM }
40107836SJohn.Forte@Sun.COM 
40117836SJohn.Forte@Sun.COM /*
40127836SJohn.Forte@Sun.COM  * ql_iidma_rate
40137836SJohn.Forte@Sun.COM  *	Issue get/set iidma rate command
40147836SJohn.Forte@Sun.COM  *
40157836SJohn.Forte@Sun.COM  * Input:
40167836SJohn.Forte@Sun.COM  *	ha:		adapter state pointer.
40177836SJohn.Forte@Sun.COM  *	loop_id:	n-port handle to set/get iidma rate.
40187836SJohn.Forte@Sun.COM  *	idma_rate:	Pointer to iidma rate.
40197836SJohn.Forte@Sun.COM  *	option:		iidma firmware option (set or get data).
40207836SJohn.Forte@Sun.COM  *				0 --> Get iidma rate
40217836SJohn.Forte@Sun.COM  *				1 --> Set iidma rate
40227836SJohn.Forte@Sun.COM  *
40237836SJohn.Forte@Sun.COM  * Returns:
40247836SJohn.Forte@Sun.COM  *	ql local function return status code.
40257836SJohn.Forte@Sun.COM  *
40267836SJohn.Forte@Sun.COM  * Context:
40277836SJohn.Forte@Sun.COM  *	Kernel context.
40287836SJohn.Forte@Sun.COM  */
40297836SJohn.Forte@Sun.COM int
ql_iidma_rate(ql_adapter_state_t * ha,uint16_t loop_id,uint32_t * idma_rate,uint32_t option)40307836SJohn.Forte@Sun.COM ql_iidma_rate(ql_adapter_state_t *ha, uint16_t loop_id, uint32_t *idma_rate,
40317836SJohn.Forte@Sun.COM     uint32_t option)
40327836SJohn.Forte@Sun.COM {
40337836SJohn.Forte@Sun.COM 	int		rval;
40347836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
40357836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
40367836SJohn.Forte@Sun.COM 
40377836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
40387836SJohn.Forte@Sun.COM 
40397836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_PORT_PARAM;
40407836SJohn.Forte@Sun.COM 	mcp->mb[1] = loop_id;
40417836SJohn.Forte@Sun.COM 	mcp->mb[2] = (uint16_t)option;
40427836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_0|MBX_1|MBX_2;
40437836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0|MBX_1;
40447836SJohn.Forte@Sun.COM 
40457836SJohn.Forte@Sun.COM 	if (option & BIT_0) {
40467836SJohn.Forte@Sun.COM 		mcp->mb[3] = (uint16_t)*idma_rate;
40477836SJohn.Forte@Sun.COM 		mcp->out_mb |= MBX_3;
40487836SJohn.Forte@Sun.COM 	} else {
40497836SJohn.Forte@Sun.COM 		mcp->in_mb |= MBX_3;
40507836SJohn.Forte@Sun.COM 	}
40517836SJohn.Forte@Sun.COM 
40527836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
40537836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
40547836SJohn.Forte@Sun.COM 
40557836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
40567836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh, mb1=%xh\n", rval, mcp->mb[1]);
40577836SJohn.Forte@Sun.COM 	} else {
40587836SJohn.Forte@Sun.COM 		if (option == 0) {
40597836SJohn.Forte@Sun.COM 			*idma_rate = mcp->mb[3];
40607836SJohn.Forte@Sun.COM 		}
40617836SJohn.Forte@Sun.COM 
40627836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
40637836SJohn.Forte@Sun.COM 	}
40647836SJohn.Forte@Sun.COM 
40657836SJohn.Forte@Sun.COM 	return (rval);
40667836SJohn.Forte@Sun.COM }
40677836SJohn.Forte@Sun.COM 
40687836SJohn.Forte@Sun.COM /*
40697836SJohn.Forte@Sun.COM  * ql_set_xmit_parms
40707836SJohn.Forte@Sun.COM  *	Set transmit parameters
40717836SJohn.Forte@Sun.COM  *
40727836SJohn.Forte@Sun.COM  * Input:
40737836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
40747836SJohn.Forte@Sun.COM  *
40757836SJohn.Forte@Sun.COM  * Returns:
40767836SJohn.Forte@Sun.COM  *	ql local function return status code.
40777836SJohn.Forte@Sun.COM  *
40787836SJohn.Forte@Sun.COM  * Context:
40797836SJohn.Forte@Sun.COM  *	Kernel context.
40807836SJohn.Forte@Sun.COM  */
40817836SJohn.Forte@Sun.COM int
ql_set_xmit_parms(ql_adapter_state_t * ha)40827836SJohn.Forte@Sun.COM ql_set_xmit_parms(ql_adapter_state_t *ha)
40837836SJohn.Forte@Sun.COM {
40847836SJohn.Forte@Sun.COM 	int		rval;
40857836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
40867836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
40877836SJohn.Forte@Sun.COM 
40887836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
40897836SJohn.Forte@Sun.COM 
40907836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_XMIT_PARM;
40917836SJohn.Forte@Sun.COM 	mcp->mb[1] = BIT_1;
40927836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_1|MBX_0;
40937836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0;
40947836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
40957836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
40967836SJohn.Forte@Sun.COM 
40977836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
40987836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
40997836SJohn.Forte@Sun.COM 	} else {
41007836SJohn.Forte@Sun.COM 		/*EMPTY*/
41017836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
41027836SJohn.Forte@Sun.COM 	}
41037836SJohn.Forte@Sun.COM 	return (rval);
41047836SJohn.Forte@Sun.COM }
41057836SJohn.Forte@Sun.COM 
41067836SJohn.Forte@Sun.COM /*
41077836SJohn.Forte@Sun.COM  * ql_fw_etrace
41087836SJohn.Forte@Sun.COM  *	Firmware extended tracing.
41097836SJohn.Forte@Sun.COM  *
41107836SJohn.Forte@Sun.COM  * Input:
41117836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
41127836SJohn.Forte@Sun.COM  *	mem:	pointer to dma memory object for command.
41139156SDaniel.Beauregard@Sun.COM  *	opt:	options and opcode.
41147836SJohn.Forte@Sun.COM  *
41157836SJohn.Forte@Sun.COM  * Returns:
41167836SJohn.Forte@Sun.COM  *	ql local function return status code.
41177836SJohn.Forte@Sun.COM  *
41187836SJohn.Forte@Sun.COM  * Context:
41197836SJohn.Forte@Sun.COM  *	Kernel context.
41207836SJohn.Forte@Sun.COM  */
41217836SJohn.Forte@Sun.COM int
ql_fw_etrace(ql_adapter_state_t * ha,dma_mem_t * mem,uint16_t opt)41227836SJohn.Forte@Sun.COM ql_fw_etrace(ql_adapter_state_t *ha, dma_mem_t *mem, uint16_t opt)
41237836SJohn.Forte@Sun.COM {
41247836SJohn.Forte@Sun.COM 	int		rval = QL_SUCCESS;
41257836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
41267836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
41279156SDaniel.Beauregard@Sun.COM 	uint16_t	op_code;
41289156SDaniel.Beauregard@Sun.COM 	uint64_t	time;
41297836SJohn.Forte@Sun.COM 
41309446SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
41317836SJohn.Forte@Sun.COM 
41329156SDaniel.Beauregard@Sun.COM 	/* currently no supported options */
41339156SDaniel.Beauregard@Sun.COM 	op_code = (uint16_t)(opt & ~0xFF00);
41349156SDaniel.Beauregard@Sun.COM 
41357836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_TRACE_CONTROL;
41369156SDaniel.Beauregard@Sun.COM 	mcp->mb[1] = op_code;
41377836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_0;
41387836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
41397836SJohn.Forte@Sun.COM 
41409156SDaniel.Beauregard@Sun.COM 	switch (op_code) {
41419156SDaniel.Beauregard@Sun.COM 	case FTO_INSERT_TIME_STAMP:
41429156SDaniel.Beauregard@Sun.COM 
41439156SDaniel.Beauregard@Sun.COM 		(void) drv_getparm(TIME, &time);
41449156SDaniel.Beauregard@Sun.COM 
41459156SDaniel.Beauregard@Sun.COM 		EL(ha, "insert time: %x %xh\n", MSD(time), LSD(time));
41469156SDaniel.Beauregard@Sun.COM 
41479156SDaniel.Beauregard@Sun.COM 		mcp->mb[2] = LSW(LSD(time));
41489156SDaniel.Beauregard@Sun.COM 		mcp->mb[3] = MSW(LSD(time));
41499156SDaniel.Beauregard@Sun.COM 		mcp->mb[4] = LSW(MSD(time));
41509156SDaniel.Beauregard@Sun.COM 		mcp->mb[5] = MSW(MSD(time));
41519156SDaniel.Beauregard@Sun.COM 		mcp->out_mb = MBX_0_THRU_5;
41529156SDaniel.Beauregard@Sun.COM 		break;
41539156SDaniel.Beauregard@Sun.COM 
41549156SDaniel.Beauregard@Sun.COM 	case FTO_FCE_TRACE_ENABLE:
41559156SDaniel.Beauregard@Sun.COM 		/* Firmware Fibre Channel Event Trace Buffer */
41567836SJohn.Forte@Sun.COM 		mcp->mb[2] = LSW(mem->cookies->dmac_address);
41577836SJohn.Forte@Sun.COM 		mcp->mb[3] = MSW(mem->cookies->dmac_address);
41587836SJohn.Forte@Sun.COM 		mcp->mb[4] = LSW(mem->cookies->dmac_notused);
41597836SJohn.Forte@Sun.COM 		mcp->mb[5] = MSW(mem->cookies->dmac_notused);
41607836SJohn.Forte@Sun.COM 		mcp->mb[6] = (uint16_t)(mem->size / 0x4000);	/* 16kb blks */
41619156SDaniel.Beauregard@Sun.COM 		mcp->mb[8] = (uint16_t)ha->fwfcetraceopt;
41629156SDaniel.Beauregard@Sun.COM 		mcp->mb[9] = FTO_FCEMAXTRACEBUF;
41639156SDaniel.Beauregard@Sun.COM 		mcp->mb[10] = FTO_FCEMAXTRACEBUF;
41649156SDaniel.Beauregard@Sun.COM 		mcp->out_mb = MBX_0_THRU_10;
41657836SJohn.Forte@Sun.COM 		break;
41667836SJohn.Forte@Sun.COM 
41679156SDaniel.Beauregard@Sun.COM 	case FTO_EXT_TRACE_ENABLE:
41689156SDaniel.Beauregard@Sun.COM 		/* Firmware Extended Trace Buffer */
41699156SDaniel.Beauregard@Sun.COM 		mcp->mb[2] = LSW(mem->cookies->dmac_address);
41709156SDaniel.Beauregard@Sun.COM 		mcp->mb[3] = MSW(mem->cookies->dmac_address);
41719156SDaniel.Beauregard@Sun.COM 		mcp->mb[4] = LSW(mem->cookies->dmac_notused);
41729156SDaniel.Beauregard@Sun.COM 		mcp->mb[5] = MSW(mem->cookies->dmac_notused);
41739156SDaniel.Beauregard@Sun.COM 		mcp->mb[6] = (uint16_t)(mem->size / 0x4000);	/* 16kb blks */
41749156SDaniel.Beauregard@Sun.COM 		mcp->out_mb = MBX_0_THRU_7;
41759156SDaniel.Beauregard@Sun.COM 		break;
41769156SDaniel.Beauregard@Sun.COM 
41779156SDaniel.Beauregard@Sun.COM 	case FTO_FCE_TRACE_DISABLE:
41789156SDaniel.Beauregard@Sun.COM 		/* also causes ISP25xx to flush its internal FCE buffer. */
41797836SJohn.Forte@Sun.COM 		mcp->mb[2] = BIT_0;
41809156SDaniel.Beauregard@Sun.COM 		mcp->out_mb = MBX_0_THRU_2;
41817836SJohn.Forte@Sun.COM 		break;
41827836SJohn.Forte@Sun.COM 
41839156SDaniel.Beauregard@Sun.COM 	case FTO_EXT_TRACE_DISABLE:
41849156SDaniel.Beauregard@Sun.COM 		/* just sending the opcode disables it */
41857836SJohn.Forte@Sun.COM 		break;
41867836SJohn.Forte@Sun.COM 
41877836SJohn.Forte@Sun.COM 	default:
41887836SJohn.Forte@Sun.COM 		EL(ha, "invalid option: %xh\n", opt);
41897836SJohn.Forte@Sun.COM 		rval = QL_PARAMETER_ERROR;
41907836SJohn.Forte@Sun.COM 		break;
41917836SJohn.Forte@Sun.COM 	}
41927836SJohn.Forte@Sun.COM 
41937836SJohn.Forte@Sun.COM 	if (rval == QL_SUCCESS) {
41947836SJohn.Forte@Sun.COM 		rval = ql_mailbox_command(ha, mcp);
41957836SJohn.Forte@Sun.COM 	}
41967836SJohn.Forte@Sun.COM 
41977836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
41987836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
41997836SJohn.Forte@Sun.COM 	} else {
42007836SJohn.Forte@Sun.COM 		/*EMPTY*/
42017836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
42027836SJohn.Forte@Sun.COM 	}
42037836SJohn.Forte@Sun.COM 
42047836SJohn.Forte@Sun.COM 	return (rval);
42057836SJohn.Forte@Sun.COM }
42067836SJohn.Forte@Sun.COM 
42077836SJohn.Forte@Sun.COM /*
42087836SJohn.Forte@Sun.COM  * ql_reset_menlo
42097836SJohn.Forte@Sun.COM  *	 Reset Menlo Mailbox Command.
42107836SJohn.Forte@Sun.COM  *
42117836SJohn.Forte@Sun.COM  * Input:
42127836SJohn.Forte@Sun.COM  *	ha:	adapter state pointer.
42137836SJohn.Forte@Sun.COM  *	mr:	pointer to mailbox in/out parameters.
42147836SJohn.Forte@Sun.COM  *	opt:	options.
42157836SJohn.Forte@Sun.COM  *
42167836SJohn.Forte@Sun.COM  * Returns:
42177836SJohn.Forte@Sun.COM  *	ql local function return status code.
42187836SJohn.Forte@Sun.COM  *
42197836SJohn.Forte@Sun.COM  * Context:
42207836SJohn.Forte@Sun.COM  *	Kernel context.
42217836SJohn.Forte@Sun.COM  */
42227836SJohn.Forte@Sun.COM int
ql_reset_menlo(ql_adapter_state_t * ha,ql_mbx_data_t * mr,uint16_t opt)42237836SJohn.Forte@Sun.COM ql_reset_menlo(ql_adapter_state_t *ha, ql_mbx_data_t *mr, uint16_t opt)
42247836SJohn.Forte@Sun.COM {
42257836SJohn.Forte@Sun.COM 	int		rval;
42267836SJohn.Forte@Sun.COM 	mbx_cmd_t	mc = {0};
42277836SJohn.Forte@Sun.COM 	mbx_cmd_t	*mcp = &mc;
42287836SJohn.Forte@Sun.COM 
42297836SJohn.Forte@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
42307836SJohn.Forte@Sun.COM 
42317836SJohn.Forte@Sun.COM 	mcp->mb[0] = MBC_RESET_MENLO;
42327836SJohn.Forte@Sun.COM 	mcp->mb[1] = opt;
42337836SJohn.Forte@Sun.COM 	mcp->out_mb = MBX_1|MBX_0;
42347836SJohn.Forte@Sun.COM 	mcp->in_mb = MBX_1|MBX_0;
42357836SJohn.Forte@Sun.COM 	mcp->timeout = MAILBOX_TOV;
42367836SJohn.Forte@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
42377836SJohn.Forte@Sun.COM 
42387836SJohn.Forte@Sun.COM 	/* Return mailbox data. */
42397836SJohn.Forte@Sun.COM 	if (mr != NULL) {
42407836SJohn.Forte@Sun.COM 		mr->mb[0] = mcp->mb[0];
42417836SJohn.Forte@Sun.COM 		mr->mb[1] = mcp->mb[1];
42427836SJohn.Forte@Sun.COM 	}
42437836SJohn.Forte@Sun.COM 
42447836SJohn.Forte@Sun.COM 	if (rval != QL_SUCCESS) {
42457836SJohn.Forte@Sun.COM 		EL(ha, "failed=%xh\n", rval);
42467836SJohn.Forte@Sun.COM 	} else {
42477836SJohn.Forte@Sun.COM 		/*EMPTY*/
42487836SJohn.Forte@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
42497836SJohn.Forte@Sun.COM 	}
42507836SJohn.Forte@Sun.COM 
42517836SJohn.Forte@Sun.COM 	return (rval);
42527836SJohn.Forte@Sun.COM }
42539446SDaniel.Beauregard@Sun.COM 
42549446SDaniel.Beauregard@Sun.COM /*
42559446SDaniel.Beauregard@Sun.COM  * ql_restart_mpi
42569446SDaniel.Beauregard@Sun.COM  *	The Restart MPI Firmware Mailbox Command will reset the MPI RISC,
42579446SDaniel.Beauregard@Sun.COM  *	reload MPI firmware from Flash, and execute the firmware.
42589446SDaniel.Beauregard@Sun.COM  *
42599446SDaniel.Beauregard@Sun.COM  * Input:
42609446SDaniel.Beauregard@Sun.COM  *	ha:	adapter state pointer.
42619446SDaniel.Beauregard@Sun.COM  *
42629446SDaniel.Beauregard@Sun.COM  * Returns:
42639446SDaniel.Beauregard@Sun.COM  *	ql local function return status code.
42649446SDaniel.Beauregard@Sun.COM  *
42659446SDaniel.Beauregard@Sun.COM  * Context:
42669446SDaniel.Beauregard@Sun.COM  *	Kernel context.
42679446SDaniel.Beauregard@Sun.COM  */
42689446SDaniel.Beauregard@Sun.COM int
ql_restart_mpi(ql_adapter_state_t * ha)42699446SDaniel.Beauregard@Sun.COM ql_restart_mpi(ql_adapter_state_t *ha)
42709446SDaniel.Beauregard@Sun.COM {
42719446SDaniel.Beauregard@Sun.COM 	int		rval;
42729446SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	mc = {0};
42739446SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	*mcp = &mc;
42749446SDaniel.Beauregard@Sun.COM 
42759446SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
42769446SDaniel.Beauregard@Sun.COM 
42779446SDaniel.Beauregard@Sun.COM 	mcp->mb[0] = MBC_RESTART_MPI;
42789446SDaniel.Beauregard@Sun.COM 	mcp->out_mb = MBX_0;
42799446SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_1|MBX_0;
42809446SDaniel.Beauregard@Sun.COM 	mcp->timeout = MAILBOX_TOV;
42819446SDaniel.Beauregard@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
42829446SDaniel.Beauregard@Sun.COM 
42839446SDaniel.Beauregard@Sun.COM 	/* Return mailbox data. */
42849446SDaniel.Beauregard@Sun.COM 	if (rval != QL_SUCCESS) {
42859446SDaniel.Beauregard@Sun.COM 		EL(ha, "status=%xh, mbx1=%xh\n", rval, mcp->mb[1]);
42869446SDaniel.Beauregard@Sun.COM 	} else {
42879446SDaniel.Beauregard@Sun.COM 		/*EMPTY*/
42889446SDaniel.Beauregard@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
42899446SDaniel.Beauregard@Sun.COM 	}
42909446SDaniel.Beauregard@Sun.COM 
42919446SDaniel.Beauregard@Sun.COM 	return (rval);
42929446SDaniel.Beauregard@Sun.COM }
42939446SDaniel.Beauregard@Sun.COM 
42949446SDaniel.Beauregard@Sun.COM /*
42959446SDaniel.Beauregard@Sun.COM  * ql_idc_request
42969446SDaniel.Beauregard@Sun.COM  *	Inter-Driver Communication Request.
42979446SDaniel.Beauregard@Sun.COM  *
42989446SDaniel.Beauregard@Sun.COM  * Input:
42999446SDaniel.Beauregard@Sun.COM  *	ha:	adapter state pointer.
43009446SDaniel.Beauregard@Sun.COM  *	mr:	pointer for mailbox data.
43019446SDaniel.Beauregard@Sun.COM  *
43029446SDaniel.Beauregard@Sun.COM  * Returns:
43039446SDaniel.Beauregard@Sun.COM  *	ql local function return status code.
43049446SDaniel.Beauregard@Sun.COM  *
43059446SDaniel.Beauregard@Sun.COM  * Context:
43069446SDaniel.Beauregard@Sun.COM  *	Kernel context.
43079446SDaniel.Beauregard@Sun.COM  */
43089446SDaniel.Beauregard@Sun.COM int
ql_idc_request(ql_adapter_state_t * ha,ql_mbx_data_t * mr)43099446SDaniel.Beauregard@Sun.COM ql_idc_request(ql_adapter_state_t *ha, ql_mbx_data_t *mr)
43109446SDaniel.Beauregard@Sun.COM {
43119446SDaniel.Beauregard@Sun.COM 	int		rval;
43129446SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	mc = {0};
43139446SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	*mcp = &mc;
43149446SDaniel.Beauregard@Sun.COM 
43159446SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
43169446SDaniel.Beauregard@Sun.COM 
43179446SDaniel.Beauregard@Sun.COM 	mcp->mb[0] = MBC_IDC_REQUEST;
43189446SDaniel.Beauregard@Sun.COM 	mcp->mb[1] = mr->mb[1];
43199446SDaniel.Beauregard@Sun.COM 	mcp->mb[2] = mr->mb[2];
43209446SDaniel.Beauregard@Sun.COM 	mcp->mb[3] = mr->mb[3];
43219446SDaniel.Beauregard@Sun.COM 	mcp->mb[4] = mr->mb[4];
43229446SDaniel.Beauregard@Sun.COM 	mcp->mb[5] = mr->mb[5];
43239446SDaniel.Beauregard@Sun.COM 	mcp->mb[6] = mr->mb[6];
43249446SDaniel.Beauregard@Sun.COM 	mcp->mb[7] = mr->mb[7];
43259446SDaniel.Beauregard@Sun.COM 	mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
43269446SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_2|MBX_0;
43279446SDaniel.Beauregard@Sun.COM 	mcp->timeout = MAILBOX_TOV;
43289446SDaniel.Beauregard@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
43299446SDaniel.Beauregard@Sun.COM 
43309446SDaniel.Beauregard@Sun.COM 	if (rval == QL_SUCCESS) {
43319446SDaniel.Beauregard@Sun.COM 		if (mr != NULL) {
43329446SDaniel.Beauregard@Sun.COM 			mr->mb[2] = mcp->mb[2];
43339446SDaniel.Beauregard@Sun.COM 		}
43349446SDaniel.Beauregard@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
43359446SDaniel.Beauregard@Sun.COM 	} else {
43369446SDaniel.Beauregard@Sun.COM 		EL(ha, "status=%xh, mbx2=%xh\n", rval, mcp->mb[2]);
43379446SDaniel.Beauregard@Sun.COM 	}
43389446SDaniel.Beauregard@Sun.COM 
43399446SDaniel.Beauregard@Sun.COM 	return (rval);
43409446SDaniel.Beauregard@Sun.COM }
43419446SDaniel.Beauregard@Sun.COM 
43429446SDaniel.Beauregard@Sun.COM /*
43439446SDaniel.Beauregard@Sun.COM  * ql_idc_ack
43449446SDaniel.Beauregard@Sun.COM  *	Inter-Driver Communication Acknowledgement.
43459446SDaniel.Beauregard@Sun.COM  *
43469446SDaniel.Beauregard@Sun.COM  * Input:
43479446SDaniel.Beauregard@Sun.COM  *	ha:	adapter state pointer.
43489446SDaniel.Beauregard@Sun.COM  *
43499446SDaniel.Beauregard@Sun.COM  * Returns:
43509446SDaniel.Beauregard@Sun.COM  *	ql local function return status code.
43519446SDaniel.Beauregard@Sun.COM  *
43529446SDaniel.Beauregard@Sun.COM  * Context:
43539446SDaniel.Beauregard@Sun.COM  *	Kernel context.
43549446SDaniel.Beauregard@Sun.COM  */
43559446SDaniel.Beauregard@Sun.COM int
ql_idc_ack(ql_adapter_state_t * ha)43569446SDaniel.Beauregard@Sun.COM ql_idc_ack(ql_adapter_state_t *ha)
43579446SDaniel.Beauregard@Sun.COM {
43589446SDaniel.Beauregard@Sun.COM 	int		rval;
43599446SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	mc = {0};
43609446SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	*mcp = &mc;
43619446SDaniel.Beauregard@Sun.COM 
43629446SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
43639446SDaniel.Beauregard@Sun.COM 
43649446SDaniel.Beauregard@Sun.COM 	mcp->mb[0] = MBC_IDC_ACK;
43659446SDaniel.Beauregard@Sun.COM 	mcp->mb[1] = ha->idc_mb[1];
43669446SDaniel.Beauregard@Sun.COM 	mcp->mb[2] = ha->idc_mb[2];
43679446SDaniel.Beauregard@Sun.COM 	mcp->mb[3] = ha->idc_mb[3];
43689446SDaniel.Beauregard@Sun.COM 	mcp->mb[4] = ha->idc_mb[4];
43699446SDaniel.Beauregard@Sun.COM 	mcp->mb[5] = ha->idc_mb[5];
43709446SDaniel.Beauregard@Sun.COM 	mcp->mb[6] = ha->idc_mb[6];
43719446SDaniel.Beauregard@Sun.COM 	mcp->mb[7] = ha->idc_mb[7];
43729446SDaniel.Beauregard@Sun.COM 	mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
43739446SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_0;
43749446SDaniel.Beauregard@Sun.COM 	mcp->timeout = MAILBOX_TOV;
43759446SDaniel.Beauregard@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
43769446SDaniel.Beauregard@Sun.COM 
43779446SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
43789446SDaniel.Beauregard@Sun.COM 
43799446SDaniel.Beauregard@Sun.COM 	return (rval);
43809446SDaniel.Beauregard@Sun.COM }
43819446SDaniel.Beauregard@Sun.COM 
43829446SDaniel.Beauregard@Sun.COM /*
43839446SDaniel.Beauregard@Sun.COM  * ql_idc_time_extend
43849446SDaniel.Beauregard@Sun.COM  *	Inter-Driver Communication Time Extend
43859446SDaniel.Beauregard@Sun.COM  *
43869446SDaniel.Beauregard@Sun.COM  * Input:
43879446SDaniel.Beauregard@Sun.COM  *	ha:	adapter state pointer.
43889446SDaniel.Beauregard@Sun.COM  *	mr:	pointer for mailbox data.
43899446SDaniel.Beauregard@Sun.COM  *
43909446SDaniel.Beauregard@Sun.COM  * Returns:
43919446SDaniel.Beauregard@Sun.COM  *	ql local function return status code.
43929446SDaniel.Beauregard@Sun.COM  *
43939446SDaniel.Beauregard@Sun.COM  * Context:
43949446SDaniel.Beauregard@Sun.COM  *	Kernel context.
43959446SDaniel.Beauregard@Sun.COM  */
43969446SDaniel.Beauregard@Sun.COM int
ql_idc_time_extend(ql_adapter_state_t * ha,ql_mbx_data_t * mr)43979446SDaniel.Beauregard@Sun.COM ql_idc_time_extend(ql_adapter_state_t *ha, ql_mbx_data_t *mr)
43989446SDaniel.Beauregard@Sun.COM {
43999446SDaniel.Beauregard@Sun.COM 	int		rval;
44009446SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	mc = {0};
44019446SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	*mcp = &mc;
44029446SDaniel.Beauregard@Sun.COM 
44039446SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
44049446SDaniel.Beauregard@Sun.COM 
44059446SDaniel.Beauregard@Sun.COM 	mcp->mb[0] = MBC_IDC_TIME_EXTEND;
44069446SDaniel.Beauregard@Sun.COM 	mcp->mb[1] = mr->mb[1];
44079446SDaniel.Beauregard@Sun.COM 	mcp->mb[2] = mr->mb[2];
44089446SDaniel.Beauregard@Sun.COM 	mcp->out_mb = MBX_2|MBX_1|MBX_0;
44099446SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_0;
44109446SDaniel.Beauregard@Sun.COM 	mcp->timeout = MAILBOX_TOV;
44119446SDaniel.Beauregard@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
44129446SDaniel.Beauregard@Sun.COM 
44139446SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
44149446SDaniel.Beauregard@Sun.COM 
44159446SDaniel.Beauregard@Sun.COM 	return (rval);
44169446SDaniel.Beauregard@Sun.COM }
44179446SDaniel.Beauregard@Sun.COM 
44189446SDaniel.Beauregard@Sun.COM /*
44199611SDaniel.Beauregard@Sun.COM  * ql_port_reset
442011924SDaniel.Beauregard@Sun.COM  *	The Port Reset for the external 10G port associated with this function.
44219611SDaniel.Beauregard@Sun.COM  *
44229611SDaniel.Beauregard@Sun.COM  * Input:
44239611SDaniel.Beauregard@Sun.COM  *	ha:	adapter state pointer.
44249611SDaniel.Beauregard@Sun.COM  *
44259611SDaniel.Beauregard@Sun.COM  * Returns:
44269611SDaniel.Beauregard@Sun.COM  *	ql local function return status code.
44279611SDaniel.Beauregard@Sun.COM  *
44289611SDaniel.Beauregard@Sun.COM  * Context:
44299611SDaniel.Beauregard@Sun.COM  *	Kernel context.
44309611SDaniel.Beauregard@Sun.COM  */
44319611SDaniel.Beauregard@Sun.COM int
ql_port_reset(ql_adapter_state_t * ha)44329611SDaniel.Beauregard@Sun.COM ql_port_reset(ql_adapter_state_t *ha)
44339611SDaniel.Beauregard@Sun.COM {
44349611SDaniel.Beauregard@Sun.COM 	int		rval;
44359611SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	mc = {0};
44369611SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	*mcp = &mc;
44379611SDaniel.Beauregard@Sun.COM 
44389611SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
44399611SDaniel.Beauregard@Sun.COM 
44409611SDaniel.Beauregard@Sun.COM 	mcp->mb[0] = MBC_PORT_RESET;
44419611SDaniel.Beauregard@Sun.COM 	mcp->out_mb = MBX_0;
44429611SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_0;
44439611SDaniel.Beauregard@Sun.COM 	mcp->timeout = MAILBOX_TOV;
44449611SDaniel.Beauregard@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
44459611SDaniel.Beauregard@Sun.COM 
44469611SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
44479611SDaniel.Beauregard@Sun.COM 
44489611SDaniel.Beauregard@Sun.COM 	return (rval);
44499611SDaniel.Beauregard@Sun.COM }
44509611SDaniel.Beauregard@Sun.COM 
44519611SDaniel.Beauregard@Sun.COM /*
44529446SDaniel.Beauregard@Sun.COM  * ql_set_port_config
44539446SDaniel.Beauregard@Sun.COM  *	The Set Port Configuration command sets the configuration for the
445411924SDaniel.Beauregard@Sun.COM  *	external 10G port associated with this function.
44559446SDaniel.Beauregard@Sun.COM  *
44569446SDaniel.Beauregard@Sun.COM  * Input:
44579446SDaniel.Beauregard@Sun.COM  *	ha:	adapter state pointer.
44589446SDaniel.Beauregard@Sun.COM  *	mr:	pointer for mailbox data.
44599446SDaniel.Beauregard@Sun.COM  *
44609446SDaniel.Beauregard@Sun.COM  * Returns:
44619446SDaniel.Beauregard@Sun.COM  *	ql local function return status code.
44629446SDaniel.Beauregard@Sun.COM  *
44639446SDaniel.Beauregard@Sun.COM  * Context:
44649446SDaniel.Beauregard@Sun.COM  *	Kernel context.
44659446SDaniel.Beauregard@Sun.COM  */
44669446SDaniel.Beauregard@Sun.COM int
ql_set_port_config(ql_adapter_state_t * ha,ql_mbx_data_t * mrp)446711924SDaniel.Beauregard@Sun.COM ql_set_port_config(ql_adapter_state_t *ha, ql_mbx_data_t *mrp)
44689446SDaniel.Beauregard@Sun.COM {
44699446SDaniel.Beauregard@Sun.COM 	int		rval;
44709446SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	mc = {0};
44719446SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	*mcp = &mc;
44729446SDaniel.Beauregard@Sun.COM 
44739446SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
44749446SDaniel.Beauregard@Sun.COM 
44759446SDaniel.Beauregard@Sun.COM 	mcp->mb[0] = MBC_SET_PORT_CONFIG;
447611924SDaniel.Beauregard@Sun.COM 	mcp->mb[1] = mrp->mb[1];
447711924SDaniel.Beauregard@Sun.COM 	mcp->mb[2] = mrp->mb[2];
447811924SDaniel.Beauregard@Sun.COM 	mcp->mb[3] = mrp->mb[3];
447911924SDaniel.Beauregard@Sun.COM 	mcp->mb[4] = mrp->mb[4];
44809611SDaniel.Beauregard@Sun.COM 	mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
44819446SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_0;
44829446SDaniel.Beauregard@Sun.COM 	mcp->timeout = MAILBOX_TOV;
44839446SDaniel.Beauregard@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
44849446SDaniel.Beauregard@Sun.COM 
44859446SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
44869446SDaniel.Beauregard@Sun.COM 
44879446SDaniel.Beauregard@Sun.COM 	return (rval);
44889446SDaniel.Beauregard@Sun.COM }
44899446SDaniel.Beauregard@Sun.COM 
44909446SDaniel.Beauregard@Sun.COM /*
44919446SDaniel.Beauregard@Sun.COM  * ql_get_port_config
44929446SDaniel.Beauregard@Sun.COM  *	The Get Port Configuration command retrieves the current configuration
449311924SDaniel.Beauregard@Sun.COM  *	for the external 10G port associated with this function.
44949446SDaniel.Beauregard@Sun.COM  *
44959446SDaniel.Beauregard@Sun.COM  * Input:
44969446SDaniel.Beauregard@Sun.COM  *	ha:	adapter state pointer.
44979446SDaniel.Beauregard@Sun.COM  *	mr:	pointer for mailbox data.
44989446SDaniel.Beauregard@Sun.COM  *
44999446SDaniel.Beauregard@Sun.COM  * Returns:
45009446SDaniel.Beauregard@Sun.COM  *	ql local function return status code.
45019446SDaniel.Beauregard@Sun.COM  *
45029446SDaniel.Beauregard@Sun.COM  * Context:
45039446SDaniel.Beauregard@Sun.COM  *	Kernel context.
45049446SDaniel.Beauregard@Sun.COM  */
45059446SDaniel.Beauregard@Sun.COM int
ql_get_port_config(ql_adapter_state_t * ha,ql_mbx_data_t * mrp)450611924SDaniel.Beauregard@Sun.COM ql_get_port_config(ql_adapter_state_t *ha, ql_mbx_data_t *mrp)
45079446SDaniel.Beauregard@Sun.COM {
45089446SDaniel.Beauregard@Sun.COM 	int		rval;
45099446SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	mc = {0};
45109446SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	*mcp = &mc;
45119446SDaniel.Beauregard@Sun.COM 
45129446SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
45139446SDaniel.Beauregard@Sun.COM 
45149446SDaniel.Beauregard@Sun.COM 	mcp->mb[0] = MBC_GET_PORT_CONFIG;
45159446SDaniel.Beauregard@Sun.COM 	mcp->out_mb = MBX_0;
45169611SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
45179446SDaniel.Beauregard@Sun.COM 	mcp->timeout = MAILBOX_TOV;
45189446SDaniel.Beauregard@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
45199446SDaniel.Beauregard@Sun.COM 
45209446SDaniel.Beauregard@Sun.COM 	if (rval == QL_SUCCESS) {
452111924SDaniel.Beauregard@Sun.COM 		if (mrp != NULL) {
452211924SDaniel.Beauregard@Sun.COM 			mrp->mb[1] = mcp->mb[1];
452311924SDaniel.Beauregard@Sun.COM 			mrp->mb[2] = mcp->mb[2];
452411924SDaniel.Beauregard@Sun.COM 			mrp->mb[3] = mcp->mb[3];
452511924SDaniel.Beauregard@Sun.COM 			mrp->mb[4] = mcp->mb[4];
45269446SDaniel.Beauregard@Sun.COM 		}
45279446SDaniel.Beauregard@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
45289446SDaniel.Beauregard@Sun.COM 	} else {
45299611SDaniel.Beauregard@Sun.COM 		EL(ha, "status=%xh, mbx1=%xh, mbx2=%xh, mbx3=%xh, mbx4=%xh\n",
45309611SDaniel.Beauregard@Sun.COM 		    rval, mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[4]);
45319446SDaniel.Beauregard@Sun.COM 	}
45329446SDaniel.Beauregard@Sun.COM 
45339446SDaniel.Beauregard@Sun.COM 	return (rval);
45349446SDaniel.Beauregard@Sun.COM }
45359446SDaniel.Beauregard@Sun.COM 
45369446SDaniel.Beauregard@Sun.COM /*
45379446SDaniel.Beauregard@Sun.COM  * ql_flash_access
45389446SDaniel.Beauregard@Sun.COM  *	The Get Port Configuration command retrieves the current configuration
4539*12279SDaniel.Beauregard@Sun.COM  *	for the external 10G port associated with this function
45409446SDaniel.Beauregard@Sun.COM  *
45419446SDaniel.Beauregard@Sun.COM  * Input:
45429446SDaniel.Beauregard@Sun.COM  *	ha:	adapter state pointer.
45439446SDaniel.Beauregard@Sun.COM  *	cmd:	command.
45449446SDaniel.Beauregard@Sun.COM  *	start:	32bit word address.
45459446SDaniel.Beauregard@Sun.COM  *	end:	32bit word address.
45469446SDaniel.Beauregard@Sun.COM  *	dp:	32bit word pointer.
45479446SDaniel.Beauregard@Sun.COM  *
45489446SDaniel.Beauregard@Sun.COM  * Returns:
45499446SDaniel.Beauregard@Sun.COM  *	ql local function return status code.
45509446SDaniel.Beauregard@Sun.COM  *
45519446SDaniel.Beauregard@Sun.COM  * Context:
45529446SDaniel.Beauregard@Sun.COM  *	Kernel context.
45539446SDaniel.Beauregard@Sun.COM  */
45549446SDaniel.Beauregard@Sun.COM int
ql_flash_access(ql_adapter_state_t * ha,uint16_t cmd,uint32_t start,uint32_t end,uint32_t * dp)45559446SDaniel.Beauregard@Sun.COM ql_flash_access(ql_adapter_state_t *ha, uint16_t cmd, uint32_t start,
45569446SDaniel.Beauregard@Sun.COM     uint32_t end, uint32_t *dp)
45579446SDaniel.Beauregard@Sun.COM {
45589446SDaniel.Beauregard@Sun.COM 	int		rval;
45599446SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	mc = {0};
45609446SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	*mcp = &mc;
45619446SDaniel.Beauregard@Sun.COM 
45629446SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
45639446SDaniel.Beauregard@Sun.COM 
45649446SDaniel.Beauregard@Sun.COM 	mcp->mb[0] = MBC_FLASH_ACCESS;
45659446SDaniel.Beauregard@Sun.COM 	if (cmd > 0 && cmd < 4) {
45669446SDaniel.Beauregard@Sun.COM 		mcp->mb[1] = (uint16_t)(FAC_FORCE_SEMA_LOCK | cmd);
45679446SDaniel.Beauregard@Sun.COM 	} else {
45689446SDaniel.Beauregard@Sun.COM 		mcp->mb[1] = cmd;
45699446SDaniel.Beauregard@Sun.COM 	}
45709446SDaniel.Beauregard@Sun.COM 	mcp->mb[2] = LSW(start);
45719446SDaniel.Beauregard@Sun.COM 	mcp->mb[3] = MSW(start);
45729446SDaniel.Beauregard@Sun.COM 	mcp->mb[4] = LSW(end);
45739446SDaniel.Beauregard@Sun.COM 	mcp->mb[5] = MSW(end);
45749446SDaniel.Beauregard@Sun.COM 
45759446SDaniel.Beauregard@Sun.COM 	mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
45769446SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_2|MBX_1|MBX_0;
45779446SDaniel.Beauregard@Sun.COM 	mcp->timeout = MAILBOX_TOV;
45789446SDaniel.Beauregard@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
45799446SDaniel.Beauregard@Sun.COM 
45809446SDaniel.Beauregard@Sun.COM 	if (rval != QL_SUCCESS) {
45819446SDaniel.Beauregard@Sun.COM 		EL(ha, "status=%xh, mbx1=%xh, mbx2=%xh\n", rval, mcp->mb[1],
45829446SDaniel.Beauregard@Sun.COM 		    mcp->mb[2]);
45839446SDaniel.Beauregard@Sun.COM 	} else {
45849446SDaniel.Beauregard@Sun.COM 		if (dp != NULL) {
45859446SDaniel.Beauregard@Sun.COM 			*dp = (uint32_t)mcp->mb[1];
45869446SDaniel.Beauregard@Sun.COM 		}
45879446SDaniel.Beauregard@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
45889446SDaniel.Beauregard@Sun.COM 	}
45899446SDaniel.Beauregard@Sun.COM 
45909446SDaniel.Beauregard@Sun.COM 	return (rval);
45919446SDaniel.Beauregard@Sun.COM }
45929446SDaniel.Beauregard@Sun.COM 
45939446SDaniel.Beauregard@Sun.COM /*
45949446SDaniel.Beauregard@Sun.COM  * ql_get_xgmac_stats
45959446SDaniel.Beauregard@Sun.COM  *	Issue et XGMAC Statistics Mailbox command
45969446SDaniel.Beauregard@Sun.COM  *
45979446SDaniel.Beauregard@Sun.COM  * Input:
45989446SDaniel.Beauregard@Sun.COM  *	ha:	adapter state pointer.
45999446SDaniel.Beauregard@Sun.COM  *	size:	size of data buffer.
46009446SDaniel.Beauregard@Sun.COM  *	bufp:	data pointer for DMA data.
46019446SDaniel.Beauregard@Sun.COM  *
46029446SDaniel.Beauregard@Sun.COM  * Returns:
46039446SDaniel.Beauregard@Sun.COM  *	ql local function return status code.
46049446SDaniel.Beauregard@Sun.COM  *
46059446SDaniel.Beauregard@Sun.COM  * Context:
46069446SDaniel.Beauregard@Sun.COM  *	Kernel context.
46079446SDaniel.Beauregard@Sun.COM  */
46089446SDaniel.Beauregard@Sun.COM int
ql_get_xgmac_stats(ql_adapter_state_t * ha,size_t size,caddr_t bufp)46099446SDaniel.Beauregard@Sun.COM ql_get_xgmac_stats(ql_adapter_state_t *ha, size_t size, caddr_t bufp)
46109446SDaniel.Beauregard@Sun.COM {
46119446SDaniel.Beauregard@Sun.COM 	int		rval;
46129446SDaniel.Beauregard@Sun.COM 	dma_mem_t	mem_desc;
46139446SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	mc = {0};
46149446SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	*mcp = &mc;
46159446SDaniel.Beauregard@Sun.COM 
46169446SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
46179446SDaniel.Beauregard@Sun.COM 
46189446SDaniel.Beauregard@Sun.COM 	if ((rval = ql_setup_mbox_dma_resources(ha, &mem_desc,
46199446SDaniel.Beauregard@Sun.COM 	    (uint32_t)size)) != QL_SUCCESS) {
46209446SDaniel.Beauregard@Sun.COM 		EL(ha, "setup_mbox_dma_resources failed: %xh\n", rval);
46219446SDaniel.Beauregard@Sun.COM 		return (QL_MEMORY_ALLOC_FAILED);
46229446SDaniel.Beauregard@Sun.COM 	}
46239446SDaniel.Beauregard@Sun.COM 
46249446SDaniel.Beauregard@Sun.COM 	mcp->mb[0] = MBC_GET_XGMAC_STATS;
46259446SDaniel.Beauregard@Sun.COM 	mcp->mb[2] = MSW(mem_desc.cookie.dmac_address);
46269446SDaniel.Beauregard@Sun.COM 	mcp->mb[3] = LSW(mem_desc.cookie.dmac_address);
46279446SDaniel.Beauregard@Sun.COM 	mcp->mb[6] = MSW(mem_desc.cookie.dmac_notused);
46289446SDaniel.Beauregard@Sun.COM 	mcp->mb[7] = LSW(mem_desc.cookie.dmac_notused);
46299446SDaniel.Beauregard@Sun.COM 	mcp->mb[8] = (uint16_t)(size >> 2);
46309446SDaniel.Beauregard@Sun.COM 	mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
46319446SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_2|MBX_1|MBX_0;
46329446SDaniel.Beauregard@Sun.COM 	mcp->timeout = MAILBOX_TOV;
46339446SDaniel.Beauregard@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
46349446SDaniel.Beauregard@Sun.COM 
46359446SDaniel.Beauregard@Sun.COM 	if (rval == QL_SUCCESS) {
46369446SDaniel.Beauregard@Sun.COM 		ql_get_mbox_dma_data(&mem_desc, bufp);
46379446SDaniel.Beauregard@Sun.COM 	}
46389446SDaniel.Beauregard@Sun.COM 	ql_free_dma_resource(ha, &mem_desc);
46399446SDaniel.Beauregard@Sun.COM 
46409446SDaniel.Beauregard@Sun.COM 	if (rval != QL_SUCCESS) {
46419446SDaniel.Beauregard@Sun.COM 		EL(ha, "status=%xh, mbx1=%xh, mbx2=%xh\n", rval, mcp->mb[1],
46429446SDaniel.Beauregard@Sun.COM 		    mcp->mb[2]);
46439446SDaniel.Beauregard@Sun.COM 	} else {
46449446SDaniel.Beauregard@Sun.COM 		/*EMPTY*/
46459446SDaniel.Beauregard@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
46469446SDaniel.Beauregard@Sun.COM 	}
46479446SDaniel.Beauregard@Sun.COM 
46489446SDaniel.Beauregard@Sun.COM 	return (rval);
46499446SDaniel.Beauregard@Sun.COM }
46509611SDaniel.Beauregard@Sun.COM 
46519611SDaniel.Beauregard@Sun.COM /*
46529611SDaniel.Beauregard@Sun.COM  * ql_get_dcbx_params
46539611SDaniel.Beauregard@Sun.COM  *	Issue get DCBX parameters mailbox command.
46549611SDaniel.Beauregard@Sun.COM  *
46559611SDaniel.Beauregard@Sun.COM  * Input:
46569611SDaniel.Beauregard@Sun.COM  *	ha:	adapter state pointer.
46579611SDaniel.Beauregard@Sun.COM  *	size:	size of data buffer.
46589611SDaniel.Beauregard@Sun.COM  *	bufp:	data pointer for DMA data.
46599611SDaniel.Beauregard@Sun.COM  *
46609611SDaniel.Beauregard@Sun.COM  * Returns:
46619611SDaniel.Beauregard@Sun.COM  *	ql local function return status code.
46629611SDaniel.Beauregard@Sun.COM  *
46639611SDaniel.Beauregard@Sun.COM  * Context:
46649611SDaniel.Beauregard@Sun.COM  *	Kernel context.
46659611SDaniel.Beauregard@Sun.COM  */
46669611SDaniel.Beauregard@Sun.COM int
ql_get_dcbx_params(ql_adapter_state_t * ha,uint32_t size,caddr_t bufp)46679611SDaniel.Beauregard@Sun.COM ql_get_dcbx_params(ql_adapter_state_t *ha, uint32_t size, caddr_t bufp)
46689611SDaniel.Beauregard@Sun.COM {
46699611SDaniel.Beauregard@Sun.COM 	int		rval;
46709611SDaniel.Beauregard@Sun.COM 	dma_mem_t	mem_desc;
46719611SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	mc = {0};
46729611SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	*mcp = &mc;
46739611SDaniel.Beauregard@Sun.COM 
46749611SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
46759611SDaniel.Beauregard@Sun.COM 
46769611SDaniel.Beauregard@Sun.COM 	if ((rval = ql_setup_mbox_dma_resources(ha, &mem_desc, size)) !=
46779611SDaniel.Beauregard@Sun.COM 	    QL_SUCCESS) {
46789611SDaniel.Beauregard@Sun.COM 		EL(ha, "failed=%xh\n", QL_MEMORY_ALLOC_FAILED);
46799611SDaniel.Beauregard@Sun.COM 		return (QL_MEMORY_ALLOC_FAILED);
46809611SDaniel.Beauregard@Sun.COM 	}
46819611SDaniel.Beauregard@Sun.COM 
46829611SDaniel.Beauregard@Sun.COM 	mcp->mb[0] = MBC_GET_DCBX_PARAMS;
46839611SDaniel.Beauregard@Sun.COM 	mcp->mb[1] = 0;	/* Return all DCBX paramters */
46849611SDaniel.Beauregard@Sun.COM 	mcp->mb[2] = MSW(LSD(mem_desc.cookie.dmac_laddress));
46859611SDaniel.Beauregard@Sun.COM 	mcp->mb[3] = LSW(LSD(mem_desc.cookie.dmac_laddress));
46869611SDaniel.Beauregard@Sun.COM 	mcp->mb[6] = MSW(MSD(mem_desc.cookie.dmac_laddress));
46879611SDaniel.Beauregard@Sun.COM 	mcp->mb[7] = LSW(MSD(mem_desc.cookie.dmac_laddress));
46889611SDaniel.Beauregard@Sun.COM 	mcp->mb[8] = (uint16_t)size;
46899611SDaniel.Beauregard@Sun.COM 	mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
46909611SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_2|MBX_1|MBX_0;
46919611SDaniel.Beauregard@Sun.COM 	mcp->timeout = MAILBOX_TOV;
46929611SDaniel.Beauregard@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
46939611SDaniel.Beauregard@Sun.COM 
46949611SDaniel.Beauregard@Sun.COM 	if (rval == QL_SUCCESS) {
46959611SDaniel.Beauregard@Sun.COM 		ql_get_mbox_dma_data(&mem_desc, bufp);
46969611SDaniel.Beauregard@Sun.COM 	}
46979611SDaniel.Beauregard@Sun.COM 
46989611SDaniel.Beauregard@Sun.COM 	ql_free_dma_resource(ha, &mem_desc);
46999611SDaniel.Beauregard@Sun.COM 
47009611SDaniel.Beauregard@Sun.COM 	if (rval != QL_SUCCESS) {
47019611SDaniel.Beauregard@Sun.COM 		EL(ha, "failed=%xh\n", rval);
47029611SDaniel.Beauregard@Sun.COM 	} else {
47039611SDaniel.Beauregard@Sun.COM 		/*EMPTY*/
47049611SDaniel.Beauregard@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
47059611SDaniel.Beauregard@Sun.COM 	}
47069611SDaniel.Beauregard@Sun.COM 
47079611SDaniel.Beauregard@Sun.COM 	return (rval);
47089611SDaniel.Beauregard@Sun.COM }
470911924SDaniel.Beauregard@Sun.COM /*
471011924SDaniel.Beauregard@Sun.COM  * ql_get_fcf_list
471111924SDaniel.Beauregard@Sun.COM  *	Issue get FCF list mailbox command.
471211924SDaniel.Beauregard@Sun.COM  *
471311924SDaniel.Beauregard@Sun.COM  * Input:
471411924SDaniel.Beauregard@Sun.COM  *	ha:		adapter state pointer.
471511924SDaniel.Beauregard@Sun.COM  *	fcf_list:	pointer to ql_fcf_list_desc_t
471611924SDaniel.Beauregard@Sun.COM  *	bufp:		data pointer for DMA data.
471711924SDaniel.Beauregard@Sun.COM  *
471811924SDaniel.Beauregard@Sun.COM  * Returns:
471911924SDaniel.Beauregard@Sun.COM  *	ql local function return status code.
472011924SDaniel.Beauregard@Sun.COM  *
472111924SDaniel.Beauregard@Sun.COM  * Context:
472211924SDaniel.Beauregard@Sun.COM  *	Kernel context.
472311924SDaniel.Beauregard@Sun.COM  */
472411924SDaniel.Beauregard@Sun.COM 
472511924SDaniel.Beauregard@Sun.COM int
ql_get_fcf_list_mbx(ql_adapter_state_t * ha,ql_fcf_list_desc_t * fcf_list,caddr_t bufp)472611924SDaniel.Beauregard@Sun.COM ql_get_fcf_list_mbx(ql_adapter_state_t *ha, ql_fcf_list_desc_t *fcf_list,
472711924SDaniel.Beauregard@Sun.COM     caddr_t bufp)
472811924SDaniel.Beauregard@Sun.COM {
472911924SDaniel.Beauregard@Sun.COM 	int		rval;
473011924SDaniel.Beauregard@Sun.COM 	dma_mem_t	mem_desc;
473111924SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	mc = {0};
473211924SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	*mcp = &mc;
473311924SDaniel.Beauregard@Sun.COM 
473411924SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
473511924SDaniel.Beauregard@Sun.COM 
473611924SDaniel.Beauregard@Sun.COM 	if ((rval = ql_setup_mbox_dma_resources(ha, &mem_desc,
473711924SDaniel.Beauregard@Sun.COM 	    fcf_list->buffer_size)) !=
473811924SDaniel.Beauregard@Sun.COM 	    QL_SUCCESS) {
473911924SDaniel.Beauregard@Sun.COM 		EL(ha, "failed=%xh\n", QL_MEMORY_ALLOC_FAILED);
474011924SDaniel.Beauregard@Sun.COM 		return (QL_MEMORY_ALLOC_FAILED);
474111924SDaniel.Beauregard@Sun.COM 	}
474211924SDaniel.Beauregard@Sun.COM 
474311924SDaniel.Beauregard@Sun.COM 	mcp->mb[0] = MBC_GET_FCF_LIST;
474411924SDaniel.Beauregard@Sun.COM 	mcp->mb[1] = fcf_list->options;
474511924SDaniel.Beauregard@Sun.COM 	mcp->mb[2] = MSW(LSD(mem_desc.cookie.dmac_laddress));
474611924SDaniel.Beauregard@Sun.COM 	mcp->mb[3] = LSW(LSD(mem_desc.cookie.dmac_laddress));
474711924SDaniel.Beauregard@Sun.COM 	mcp->mb[6] = MSW(MSD(mem_desc.cookie.dmac_laddress));
474811924SDaniel.Beauregard@Sun.COM 	mcp->mb[7] = LSW(MSD(mem_desc.cookie.dmac_laddress));
474911924SDaniel.Beauregard@Sun.COM 	mcp->mb[8] = (uint16_t)fcf_list->buffer_size;
475011924SDaniel.Beauregard@Sun.COM 	mcp->mb[9] = fcf_list->fcf_index;
475111924SDaniel.Beauregard@Sun.COM 	mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
475211924SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_2|MBX_1|MBX_0;
475311924SDaniel.Beauregard@Sun.COM 	mcp->timeout = MAILBOX_TOV;
475411924SDaniel.Beauregard@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
475511924SDaniel.Beauregard@Sun.COM 
475611924SDaniel.Beauregard@Sun.COM 	if (rval == QL_SUCCESS) {
475711924SDaniel.Beauregard@Sun.COM 		ql_get_mbox_dma_data(&mem_desc, bufp);
475811924SDaniel.Beauregard@Sun.COM 		fcf_list->buffer_size = (uint16_t)mcp->mb[1];
475911924SDaniel.Beauregard@Sun.COM 	}
476011924SDaniel.Beauregard@Sun.COM 
476111924SDaniel.Beauregard@Sun.COM 	ql_free_dma_resource(ha, &mem_desc);
476211924SDaniel.Beauregard@Sun.COM 
476311924SDaniel.Beauregard@Sun.COM 	if (rval != QL_SUCCESS) {
476411924SDaniel.Beauregard@Sun.COM 		EL(ha, "status=%xh, mbx1=%xh, mbx2=%xh\n", rval, mcp->mb[1],
476511924SDaniel.Beauregard@Sun.COM 		    mcp->mb[2]);
476611924SDaniel.Beauregard@Sun.COM 	} else {
476711924SDaniel.Beauregard@Sun.COM 		/*EMPTY*/
476811924SDaniel.Beauregard@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
476911924SDaniel.Beauregard@Sun.COM 	}
477011924SDaniel.Beauregard@Sun.COM 
477111924SDaniel.Beauregard@Sun.COM 	return (rval);
477211924SDaniel.Beauregard@Sun.COM }
477311924SDaniel.Beauregard@Sun.COM 
477411924SDaniel.Beauregard@Sun.COM /*
477511924SDaniel.Beauregard@Sun.COM  * ql_get_resource_cnts
477611924SDaniel.Beauregard@Sun.COM  *	Issue get Resourse Count mailbox command.
477711924SDaniel.Beauregard@Sun.COM  *
477811924SDaniel.Beauregard@Sun.COM  * Input:
477911924SDaniel.Beauregard@Sun.COM  *	ha:	adapter state pointer.
478011924SDaniel.Beauregard@Sun.COM  *	mr:	pointer for mailbox data.
478111924SDaniel.Beauregard@Sun.COM  *
478211924SDaniel.Beauregard@Sun.COM  * Returns:
478311924SDaniel.Beauregard@Sun.COM  *	ql local function return status code.
478411924SDaniel.Beauregard@Sun.COM  *
478511924SDaniel.Beauregard@Sun.COM  * Context:
478611924SDaniel.Beauregard@Sun.COM  *	Kernel context.
478711924SDaniel.Beauregard@Sun.COM  */
478811924SDaniel.Beauregard@Sun.COM 
478911924SDaniel.Beauregard@Sun.COM int
ql_get_resource_cnts(ql_adapter_state_t * ha,ql_mbx_data_t * mr)479011924SDaniel.Beauregard@Sun.COM ql_get_resource_cnts(ql_adapter_state_t *ha, ql_mbx_data_t *mr)
479111924SDaniel.Beauregard@Sun.COM {
479211924SDaniel.Beauregard@Sun.COM 	int		rval;
479311924SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	mc = {0};
479411924SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	*mcp = &mc;
479511924SDaniel.Beauregard@Sun.COM 
479611924SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
479711924SDaniel.Beauregard@Sun.COM 
479811924SDaniel.Beauregard@Sun.COM 	mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
479911924SDaniel.Beauregard@Sun.COM 	mcp->out_mb = MBX_0;
480011924SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_12|MBX_11|MBX_10|MBX_7|MBX_6|
480111924SDaniel.Beauregard@Sun.COM 	    MBX_3|MBX_2|MBX_1|MBX_0;
480211924SDaniel.Beauregard@Sun.COM 	mcp->timeout = MAILBOX_TOV;
480311924SDaniel.Beauregard@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
480411924SDaniel.Beauregard@Sun.COM 
480511924SDaniel.Beauregard@Sun.COM 	/* Return mailbox data. */
480611924SDaniel.Beauregard@Sun.COM 	if (mr != NULL) {
480711924SDaniel.Beauregard@Sun.COM 		mr->mb[1] = mcp->mb[1];
480811924SDaniel.Beauregard@Sun.COM 		mr->mb[2] = mcp->mb[2];
480911924SDaniel.Beauregard@Sun.COM 		mr->mb[3] = mcp->mb[3];
481011924SDaniel.Beauregard@Sun.COM 		mr->mb[6] = mcp->mb[6];
481111924SDaniel.Beauregard@Sun.COM 		mr->mb[7] = mcp->mb[7];
481211924SDaniel.Beauregard@Sun.COM 		mr->mb[10] = mcp->mb[10];
481311924SDaniel.Beauregard@Sun.COM 		mr->mb[11] = mcp->mb[11];
481411924SDaniel.Beauregard@Sun.COM 		mr->mb[12] = mcp->mb[12];
481511924SDaniel.Beauregard@Sun.COM 	}
481611924SDaniel.Beauregard@Sun.COM 
481711924SDaniel.Beauregard@Sun.COM 	if (rval != QL_SUCCESS) {
481811924SDaniel.Beauregard@Sun.COM 		EL(ha, "failed=%xh\n", rval);
481911924SDaniel.Beauregard@Sun.COM 	} else {
482011924SDaniel.Beauregard@Sun.COM 		/*EMPTY*/
482111924SDaniel.Beauregard@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
482211924SDaniel.Beauregard@Sun.COM 	}
482311924SDaniel.Beauregard@Sun.COM 
482411924SDaniel.Beauregard@Sun.COM 	return (rval);
482511924SDaniel.Beauregard@Sun.COM }
482611924SDaniel.Beauregard@Sun.COM 
482711924SDaniel.Beauregard@Sun.COM /*
482811924SDaniel.Beauregard@Sun.COM  * ql_toggle_interrupt
482911924SDaniel.Beauregard@Sun.COM  *	 Issue Toggle Interrupt Mailbox Command.
483011924SDaniel.Beauregard@Sun.COM  *
483111924SDaniel.Beauregard@Sun.COM  * Input:
483211924SDaniel.Beauregard@Sun.COM  *	ha:	adapter state pointer.
483311924SDaniel.Beauregard@Sun.COM  *	opt:	0 = disable, 1 = enable.
483411924SDaniel.Beauregard@Sun.COM  *
483511924SDaniel.Beauregard@Sun.COM  * Returns:
483611924SDaniel.Beauregard@Sun.COM  *	ql local function return status code.
483711924SDaniel.Beauregard@Sun.COM  *
483811924SDaniel.Beauregard@Sun.COM  * Context:
483911924SDaniel.Beauregard@Sun.COM  *	Kernel context.
484011924SDaniel.Beauregard@Sun.COM  */
484111924SDaniel.Beauregard@Sun.COM int
ql_toggle_interrupt(ql_adapter_state_t * ha,uint16_t opt)484211924SDaniel.Beauregard@Sun.COM ql_toggle_interrupt(ql_adapter_state_t *ha, uint16_t opt)
484311924SDaniel.Beauregard@Sun.COM {
484411924SDaniel.Beauregard@Sun.COM 	int		rval;
484511924SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	mc = {0};
484611924SDaniel.Beauregard@Sun.COM 	mbx_cmd_t	*mcp = &mc;
484711924SDaniel.Beauregard@Sun.COM 
484811924SDaniel.Beauregard@Sun.COM 	QL_PRINT_3(CE_CONT, "(%d): started\n", ha->instance);
484911924SDaniel.Beauregard@Sun.COM 
485011924SDaniel.Beauregard@Sun.COM 	mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
485111924SDaniel.Beauregard@Sun.COM 	mcp->mb[1] = opt;
485211924SDaniel.Beauregard@Sun.COM 	mcp->out_mb = MBX_1|MBX_0;
485311924SDaniel.Beauregard@Sun.COM 	mcp->in_mb = MBX_0;
4854*12279SDaniel.Beauregard@Sun.COM 	mcp->timeout = 2;
485511924SDaniel.Beauregard@Sun.COM 	rval = ql_mailbox_command(ha, mcp);
485611924SDaniel.Beauregard@Sun.COM 
485711924SDaniel.Beauregard@Sun.COM 	if (rval != QL_SUCCESS) {
485811924SDaniel.Beauregard@Sun.COM 		EL(ha, "failed=%xh\n", rval);
485911924SDaniel.Beauregard@Sun.COM 	} else {
486011924SDaniel.Beauregard@Sun.COM 		/*EMPTY*/
486111924SDaniel.Beauregard@Sun.COM 		QL_PRINT_3(CE_CONT, "(%d): done\n", ha->instance);
486211924SDaniel.Beauregard@Sun.COM 	}
486311924SDaniel.Beauregard@Sun.COM 
486411924SDaniel.Beauregard@Sun.COM 	return (rval);
486511924SDaniel.Beauregard@Sun.COM }
4866