xref: /freebsd/sys/dev/isp/ispvar.h (revision 31354813f3c6e87532189be77c2f10a017c55472)
1098ca2bdSWarner Losh /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
41b760be4SAlexander Motin  *  Copyright (c) 2009-2020 Alexander Motin <mav@FreeBSD.org>
52df76c16SMatt Jacob  *  Copyright (c) 1997-2009 by Matthew Jacob
66054c3f6SMatt Jacob  *  All rights reserved.
77e90346eSMatt Jacob  *
86054c3f6SMatt Jacob  *  Redistribution and use in source and binary forms, with or without
96054c3f6SMatt Jacob  *  modification, are permitted provided that the following conditions
106054c3f6SMatt Jacob  *  are met:
116054c3f6SMatt Jacob  *
12e48b2487SMatt Jacob  *  1. Redistributions of source code must retain the above copyright
13e48b2487SMatt Jacob  *     notice, this list of conditions and the following disclaimer.
14e48b2487SMatt Jacob  *  2. Redistributions in binary form must reproduce the above copyright
15e48b2487SMatt Jacob  *     notice, this list of conditions and the following disclaimer in the
16e48b2487SMatt Jacob  *     documentation and/or other materials provided with the distribution.
17e48b2487SMatt Jacob  *
18e48b2487SMatt Jacob  *  THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
196054c3f6SMatt Jacob  *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
206054c3f6SMatt Jacob  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21e48b2487SMatt Jacob  *  ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
22e48b2487SMatt Jacob  *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
236054c3f6SMatt Jacob  *  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
246054c3f6SMatt Jacob  *  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
256054c3f6SMatt Jacob  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
266054c3f6SMatt Jacob  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
276054c3f6SMatt Jacob  *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
286054c3f6SMatt Jacob  *  SUCH DAMAGE.
292df76c16SMatt Jacob  *
306054c3f6SMatt Jacob  */
31e48b2487SMatt Jacob /*
32bafe4ceeSGordon Bergling  * Soft Definitions for Qlogic ISP SCSI adapters.
33e48b2487SMatt Jacob  */
346054c3f6SMatt Jacob 
356054c3f6SMatt Jacob #ifndef	_ISPVAR_H
366054c3f6SMatt Jacob #define	_ISPVAR_H
376054c3f6SMatt Jacob 
3857c801f5SMatt Jacob #if defined(__NetBSD__) || defined(__OpenBSD__)
3910365e5aSMatt Jacob #include <dev/ic/isp_stds.h>
406054c3f6SMatt Jacob #include <dev/ic/ispmbox.h>
416054c3f6SMatt Jacob #endif
426054c3f6SMatt Jacob #ifdef	__FreeBSD__
4310365e5aSMatt Jacob #include <dev/isp/isp_stds.h>
446054c3f6SMatt Jacob #include <dev/isp/ispmbox.h>
456054c3f6SMatt Jacob #endif
466054c3f6SMatt Jacob #ifdef	__linux__
4710365e5aSMatt Jacob #include "isp_stds.h"
48c3055363SMatt Jacob #include "ispmbox.h"
4980ae5655SMatt Jacob #endif
501dae40ebSMatt Jacob #ifdef	__svr4__
5110365e5aSMatt Jacob #include "isp_stds.h"
521dae40ebSMatt Jacob #include "ispmbox.h"
536054c3f6SMatt Jacob #endif
546054c3f6SMatt Jacob 
55c8b8a2c4SMatt Jacob #define	ISP_CORE_VERSION_MAJOR	7
5610365e5aSMatt Jacob #define	ISP_CORE_VERSION_MINOR	0
57478f8a96SJustin T. Gibbs 
586054c3f6SMatt Jacob /*
59cbf57b47SMatt Jacob  * Vector for bus specific code to provide specific services.
606054c3f6SMatt Jacob  */
611dae40ebSMatt Jacob typedef struct ispsoftc ispsoftc_t;
626054c3f6SMatt Jacob struct ispmdvec {
630e6bc811SAlexander Motin 	void		(*dv_run_isr) (ispsoftc_t *);
6410365e5aSMatt Jacob 	uint32_t	(*dv_rd_reg) (ispsoftc_t *, int);
6510365e5aSMatt Jacob 	void		(*dv_wr_reg) (ispsoftc_t *, int, uint32_t);
661dae40ebSMatt Jacob 	int		(*dv_mbxdma) (ispsoftc_t *);
67f6854a0cSAlexander Motin 	int		(*dv_send_cmd) (ispsoftc_t *, void *, void *, uint32_t);
68a1fa0267SAlexander Motin 	int		(*dv_irqsetup) (ispsoftc_t *);
691dae40ebSMatt Jacob 	void		(*dv_dregs) (ispsoftc_t *, const char *);
7010ed63fcSJoerg Pulz 	const void *	dv_ispfw;	/* ptr to f/w of ispfw(4)*/
716054c3f6SMatt Jacob };
726054c3f6SMatt Jacob 
7353cff3bbSMatt Jacob /*
7453cff3bbSMatt Jacob  * Overall parameters
7553cff3bbSMatt Jacob  */
766054c3f6SMatt Jacob #define	MAX_TARGETS		16
772df76c16SMatt Jacob #ifndef	MAX_FC_TARG
785d084976SAlexander Motin #define	MAX_FC_TARG		1024
792df76c16SMatt Jacob #endif
801b760be4SAlexander Motin #define	ISP_MAX_TARGETS(isp)	MAX_FC_TARG
8108826086SAlexander Motin #define	ISP_MAX_IRQS		3
820f747d72SMatt Jacob 
83126ec864SMatt Jacob /*
8453cff3bbSMatt Jacob  * Macros to access ISP registers through bus specific layers-
8553cff3bbSMatt Jacob  * mostly wrappers to vector through the mdvec structure.
8680ae5655SMatt Jacob  */
870e6bc811SAlexander Motin #define	ISP_RUN_ISR(isp)	\
880e6bc811SAlexander Motin 	(*(isp)->isp_mdvec->dv_run_isr)(isp)
8980ae5655SMatt Jacob 
9080ae5655SMatt Jacob #define	ISP_READ(isp, reg)	\
9180ae5655SMatt Jacob 	(*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg))
9280ae5655SMatt Jacob 
9380ae5655SMatt Jacob #define	ISP_WRITE(isp, reg, val)	\
9480ae5655SMatt Jacob 	(*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val))
9580ae5655SMatt Jacob 
9680ae5655SMatt Jacob #define	ISP_MBOXDMASETUP(isp)	\
9780ae5655SMatt Jacob 	(*(isp)->isp_mdvec->dv_mbxdma)((isp))
9880ae5655SMatt Jacob 
99f6854a0cSAlexander Motin #define	ISP_SEND_CMD(isp, qe, segp, nseg)	\
100f6854a0cSAlexander Motin 	(*(isp)->isp_mdvec->dv_send_cmd)((isp), (qe), (segp), (nseg))
10180ae5655SMatt Jacob 
102a1fa0267SAlexander Motin #define	ISP_IRQSETUP(isp)	\
103a1fa0267SAlexander Motin 	(((isp)->isp_mdvec->dv_irqsetup) ? (*(isp)->isp_mdvec->dv_irqsetup)(isp) : 0)
10453cff3bbSMatt Jacob #define	ISP_DUMPREGS(isp, m)	\
10553cff3bbSMatt Jacob 	if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp),(m))
10680ae5655SMatt Jacob 
10780ae5655SMatt Jacob #define	ISP_SETBITS(isp, reg, val)	\
10880ae5655SMatt Jacob  (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val))
10980ae5655SMatt Jacob 
11080ae5655SMatt Jacob #define	ISP_CLRBITS(isp, reg, val)	\
11180ae5655SMatt Jacob  (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val))
11280ae5655SMatt Jacob 
11353cff3bbSMatt Jacob /*
11453cff3bbSMatt Jacob  * The MEMORYBARRIER macro is defined per platform (to provide synchronization
11553cff3bbSMatt Jacob  * on Request and Response Queues, Scratch DMA areas, and Registers)
11653cff3bbSMatt Jacob  *
11753cff3bbSMatt Jacob  * Defined Memory Barrier Synchronization Types
11853cff3bbSMatt Jacob  */
11953cff3bbSMatt Jacob #define	SYNC_REQUEST	0	/* request queue synchronization */
12053cff3bbSMatt Jacob #define	SYNC_RESULT	1	/* result queue synchronization */
12153cff3bbSMatt Jacob #define	SYNC_SFORDEV	2	/* scratch, sync for ISP */
12253cff3bbSMatt Jacob #define	SYNC_SFORCPU	3	/* scratch, sync for CPU */
12353cff3bbSMatt Jacob #define	SYNC_REG	4	/* for registers */
12410365e5aSMatt Jacob #define	SYNC_ATIOQ	5	/* atio result queue (24xx) */
1254ff970c4SAlexander Motin #define	SYNC_IFORDEV	6	/* synchrounous IOCB, sync for ISP */
1264ff970c4SAlexander Motin #define	SYNC_IFORCPU	7	/* synchrounous IOCB, sync for CPU */
12753cff3bbSMatt Jacob 
12853cff3bbSMatt Jacob /*
12953cff3bbSMatt Jacob  * Request/Response Queue defines and macros.
13053cff3bbSMatt Jacob  */
13153cff3bbSMatt Jacob /* This is the size of a queue entry (request and response) */
1326054c3f6SMatt Jacob #define	QENTRY_LEN			64
1330f99cb55SAlexander Motin /*
1340f99cb55SAlexander Motin  * Hardware requires queue lengths of at least 8 elements.  Driver requires
1350f99cb55SAlexander Motin  * lengths to be a power of two, and request queue of at least 256 elements.
1360f99cb55SAlexander Motin  */
137b8e2395eSAlexander Motin #define	RQUEST_QUEUE_LEN(x)		8192
138b8e2395eSAlexander Motin #define	RESULT_QUEUE_LEN(x)		1024
139b8e2395eSAlexander Motin #define	ATIO_QUEUE_LEN(x)		1024
140b8e2395eSAlexander Motin #define	ISP_QUEUE_ENTRY(q, idx)		(((uint8_t *)q) + ((size_t)(idx) * QENTRY_LEN))
141b8e2395eSAlexander Motin #define	ISP_QUEUE_SIZE(n)		((size_t)(n) * QENTRY_LEN)
142478f8a96SJustin T. Gibbs #define	ISP_NXT_QENTRY(idx, qlen)	(((idx) + 1) & ((qlen)-1))
1430f99cb55SAlexander Motin #define	ISP_QFREE(in, out, qlen)	((out - in - 1) & ((qlen) - 1))
144b6b6ad2fSMatt Jacob #define	ISP_QAVAIL(isp)	\
145b6b6ad2fSMatt Jacob 	ISP_QFREE(isp->isp_reqidx, isp->isp_reqodx, RQUEST_QUEUE_LEN(isp))
14680ae5655SMatt Jacob 
1474fd13c1bSMatt Jacob #define	ISP_ADD_REQUEST(isp, nxti)						\
14837bb79f1SMarius Strobl 	MEMORYBARRIER(isp, SYNC_REQUEST, isp->isp_reqidx, QENTRY_LEN, -1);	\
1491b760be4SAlexander Motin 	ISP_WRITE(isp, BIU2400_REQINP, nxti);					\
1504fd13c1bSMatt Jacob 	isp->isp_reqidx = nxti
15180ae5655SMatt Jacob 
1522df76c16SMatt Jacob #define	ISP_SYNC_REQUEST(isp)								\
15337bb79f1SMarius Strobl 	MEMORYBARRIER(isp, SYNC_REQUEST, isp->isp_reqidx, QENTRY_LEN, -1);		\
1542df76c16SMatt Jacob 	isp->isp_reqidx = ISP_NXT_QENTRY(isp->isp_reqidx, RQUEST_QUEUE_LEN(isp));	\
1551b760be4SAlexander Motin 	ISP_WRITE(isp, BIU2400_REQINP, isp->isp_reqidx)
1566054c3f6SMatt Jacob 
1576054c3f6SMatt Jacob /*
1586054c3f6SMatt Jacob  * Fibre Channel Specifics
1596054c3f6SMatt Jacob  */
16010365e5aSMatt Jacob #define	NPH_RESERVED		0x7F0	/* begin of reserved N-port handles */
16110365e5aSMatt Jacob #define	NPH_MGT_ID		0x7FA	/* Management Server Special ID */
16210365e5aSMatt Jacob #define	NPH_SNS_ID		0x7FC	/* SNS Server Special ID */
1632df76c16SMatt Jacob #define	NPH_FABRIC_CTLR		0x7FD	/* Fabric Controller (0xFFFFFD) */
1642df76c16SMatt Jacob #define	NPH_FL_ID		0x7FE	/* F Port Special ID (0xFFFFFE) */
1655b355b12SAlexander Motin #define	NPH_IP_BCST		0x7FF	/* IP Broadcast Special ID (0xFFFFFF) */
166dd9fc7c3SMatt Jacob #define	NPH_MAX_2K		0x800
167dd9fc7c3SMatt Jacob 
168dd9fc7c3SMatt Jacob /*
169dd9fc7c3SMatt Jacob  * "Unassigned" handle to be used internally
170dd9fc7c3SMatt Jacob  */
171dd9fc7c3SMatt Jacob #define	NIL_HANDLE		0xffff
172029f13c6SMatt Jacob 
17310365e5aSMatt Jacob /*
17410365e5aSMatt Jacob  * Limit for devices on an arbitrated loop.
17510365e5aSMatt Jacob  */
17610365e5aSMatt Jacob #define	LOCAL_LOOP_LIM		126
17710365e5aSMatt Jacob 
17810365e5aSMatt Jacob /*
1792df76c16SMatt Jacob  * Limit for (2K login) N-port handle amounts
1802df76c16SMatt Jacob  */
1812df76c16SMatt Jacob #define	MAX_NPORT_HANDLE	2048
1822df76c16SMatt Jacob 
1832df76c16SMatt Jacob /*
1842df76c16SMatt Jacob  * Special Constants
1852df76c16SMatt Jacob  */
1862df76c16SMatt Jacob #define	INI_NONE    		((uint64_t) 0)
1872df76c16SMatt Jacob #define	ISP_NOCHAN		0xff
1882df76c16SMatt Jacob 
1892df76c16SMatt Jacob /*
19010365e5aSMatt Jacob  * Special Port IDs
19110365e5aSMatt Jacob  */
19210365e5aSMatt Jacob #define	MANAGEMENT_PORT_ID	0xFFFFFA
19310365e5aSMatt Jacob #define	SNS_PORT_ID		0xFFFFFC
19410365e5aSMatt Jacob #define	FABRIC_PORT_ID		0xFFFFFE
1952df76c16SMatt Jacob #define	PORT_ANY		0xFFFFFF
1962df76c16SMatt Jacob #define	PORT_NONE		0
1974187a965SAlexander Motin #define	VALID_PORT(port)	(port != PORT_NONE && port != PORT_ANY)
1982df76c16SMatt Jacob #define	DOMAIN_CONTROLLER_BASE	0xFFFC00
1992df76c16SMatt Jacob #define	DOMAIN_CONTROLLER_END	0xFFFCFF
20010365e5aSMatt Jacob 
201c8b8a2c4SMatt Jacob /*
202c8b8a2c4SMatt Jacob  * Command Handles
203c8b8a2c4SMatt Jacob  *
204c8b8a2c4SMatt Jacob  * Most QLogic initiator or target have 32 bit handles associated with them.
205c8b8a2c4SMatt Jacob  * We want to have a quick way to index back and forth between a local SCSI
206c8b8a2c4SMatt Jacob  * command context and what the firmware is passing back to us. We also
207c8b8a2c4SMatt Jacob  * want to avoid working on stale information. This structure handles both
208c8b8a2c4SMatt Jacob  * at the expense of some local memory.
209c8b8a2c4SMatt Jacob  *
210c8b8a2c4SMatt Jacob  * The handle is architected thusly:
211c8b8a2c4SMatt Jacob  *
212c8b8a2c4SMatt Jacob  *	0 means "free handle"
213c8b8a2c4SMatt Jacob  *	bits  0..12 index commands
214c8b8a2c4SMatt Jacob  *	bits 13..15 bits index usage
215c8b8a2c4SMatt Jacob  *	bits 16..31 contain a rolling sequence
216c8b8a2c4SMatt Jacob  *
217c8b8a2c4SMatt Jacob  *
218c8b8a2c4SMatt Jacob  */
219c8b8a2c4SMatt Jacob typedef struct {
220c8b8a2c4SMatt Jacob 	void *		cmd;	/* associated command context */
221c8b8a2c4SMatt Jacob 	uint32_t	handle;	/* handle associated with this command */
222c8b8a2c4SMatt Jacob } isp_hdl_t;
223c8b8a2c4SMatt Jacob #define	ISP_HANDLE_FREE		0x00000000
2240b19f90aSAlexander Motin #define	ISP_HANDLE_CMD_MASK	0x00003fff
2250b19f90aSAlexander Motin #define	ISP_HANDLE_USAGE_MASK	0x0000c000
2260b19f90aSAlexander Motin #define	ISP_HANDLE_USAGE_SHIFT	14
227c8b8a2c4SMatt Jacob #define	ISP_H2HT(hdl)	((hdl & ISP_HANDLE_USAGE_MASK) >> ISP_HANDLE_USAGE_SHIFT)
228c8b8a2c4SMatt Jacob #	define	ISP_HANDLE_NONE		0
229c8b8a2c4SMatt Jacob #	define	ISP_HANDLE_INITIATOR	1
230c8b8a2c4SMatt Jacob #	define	ISP_HANDLE_TARGET	2
23166e979f1SAlexander Motin #	define	ISP_HANDLE_CTRL		3
232c8b8a2c4SMatt Jacob #define	ISP_HANDLE_SEQ_MASK	0xffff0000
233c8b8a2c4SMatt Jacob #define	ISP_HANDLE_SEQ_SHIFT	16
234c8b8a2c4SMatt Jacob #define	ISP_H2SEQ(hdl)	((hdl & ISP_HANDLE_SEQ_MASK) >> ISP_HANDLE_SEQ_SHIFT)
2350b19f90aSAlexander Motin #define	ISP_HANDLE_MAX		(ISP_HANDLE_CMD_MASK + 1)
2360b19f90aSAlexander Motin #define	ISP_HANDLE_RESERVE	256
2370b19f90aSAlexander Motin #define	ISP_HANDLE_NUM(isp)	((isp)->isp_maxcmds + ISP_HANDLE_RESERVE)
2380b19f90aSAlexander Motin #define	ISP_VALID_HANDLE(isp, hdl)	\
239970ceb2fSAlexander Motin 	((ISP_H2HT(hdl) == ISP_HANDLE_INITIATOR || \
24066e979f1SAlexander Motin 	  ISP_H2HT(hdl) == ISP_HANDLE_TARGET || \
24166e979f1SAlexander Motin 	  ISP_H2HT(hdl) == ISP_HANDLE_CTRL) && \
2420b19f90aSAlexander Motin 	 ((hdl) & ISP_HANDLE_CMD_MASK) < ISP_HANDLE_NUM(isp) && \
2430b19f90aSAlexander Motin 	 (hdl) == ((isp)->isp_xflist[(hdl) & ISP_HANDLE_CMD_MASK].handle))
244c8b8a2c4SMatt Jacob 
24510365e5aSMatt Jacob 
24610365e5aSMatt Jacob /*
24710365e5aSMatt Jacob  * FC Port Database entry.
24810365e5aSMatt Jacob  *
24910365e5aSMatt Jacob  * It has a handle that the f/w uses to address commands to a device.
25010365e5aSMatt Jacob  * This handle's value may be assigned by the firmware (e.g., for local loop
25110365e5aSMatt Jacob  * devices) or by the driver (e.g., for fabric devices).
25210365e5aSMatt Jacob  *
25310365e5aSMatt Jacob  * It has a state. If the state if VALID, that means that we've logged into
254766a65a5SAlexander Motin  * the device.
25510365e5aSMatt Jacob  *
25610365e5aSMatt Jacob  * Local loop devices the firmware automatically performs PLOGI on for us
25710365e5aSMatt Jacob  * (which is why that handle is imposed upon us). Fabric devices we assign
25810365e5aSMatt Jacob  * a handle to and perform the PLOGI on.
25910365e5aSMatt Jacob  *
26010365e5aSMatt Jacob  * When a PORT DATABASE CHANGED asynchronous event occurs, we mark all VALID
26110365e5aSMatt Jacob  * entries as PROBATIONAL. This allows us, if policy says to, just keep track
26210365e5aSMatt Jacob  * of devices whose handles change but are otherwise the same device (and
26310365e5aSMatt Jacob  * thus keep 'target' constant).
26410365e5aSMatt Jacob  *
26510365e5aSMatt Jacob  * In any case, we search all possible local loop handles. For each one that
26610365e5aSMatt Jacob  * has a port database entity returned, we search for any PROBATIONAL entry
26710365e5aSMatt Jacob  * that matches it and update as appropriate. Otherwise, as a new entry, we
26810365e5aSMatt Jacob  * find room for it in the Port Database. We *try* and use the handle as the
26910365e5aSMatt Jacob  * index to put it into the Database, but that's just an optimization. We mark
27010365e5aSMatt Jacob  * the entry VALID and make sure that the target index is updated and correct.
27110365e5aSMatt Jacob  *
272453130d9SPedro F. Giffuni  * When we get done searching the local loop, we then search similarly for
27310365e5aSMatt Jacob  * a list of devices we've gotten from the fabric name controller (if we're
274453130d9SPedro F. Giffuni  * on a fabric). VALID marking is also done similarly.
27510365e5aSMatt Jacob  *
27610365e5aSMatt Jacob  * When all of this is done, we can march through the database and clean up
27710365e5aSMatt Jacob  * any entry that is still PROBATIONAL (these represent devices which have
27810365e5aSMatt Jacob  * departed). Then we're done and can resume normal operations.
27910365e5aSMatt Jacob  *
28010365e5aSMatt Jacob  * Negative invariants that we try and test for are:
28110365e5aSMatt Jacob  *
28210365e5aSMatt Jacob  *  + There can never be two non-NIL entries with the same { Port, Node } WWN
28310365e5aSMatt Jacob  *    duples.
28410365e5aSMatt Jacob  *
28510365e5aSMatt Jacob  *  + There can never be two non-NIL entries with the same handle.
28610365e5aSMatt Jacob  */
2876054c3f6SMatt Jacob typedef struct {
288f7c631bcSMatt Jacob 	/*
289f7c631bcSMatt Jacob 	 * This is the handle that the firmware needs in order for us to
290f7c631bcSMatt Jacob 	 * send commands to the device. For pre-24XX cards, this would be
291f7c631bcSMatt Jacob 	 * the 'loopid'.
292f7c631bcSMatt Jacob 	 */
29310365e5aSMatt Jacob 	uint16_t	handle;
2942df76c16SMatt Jacob 
295f7c631bcSMatt Jacob 	/*
2966f9dbc0eSKenneth D. Merry 	 * PRLI word 0 contains the Establish Image Pair bit, which is
2976f9dbc0eSKenneth D. Merry 	 * important for knowing when to reset the CRN.
2986f9dbc0eSKenneth D. Merry 	 *
299387d8239SMatt Jacob 	 * PRLI word 3 parameters contains role as well as other things.
300f7c631bcSMatt Jacob 	 *
301387d8239SMatt Jacob 	 * The state is the current state of this entry.
302f7c631bcSMatt Jacob 	 *
303e68eef14SAlexander Motin 	 * The is_target is the current state of target on this port.
304e68eef14SAlexander Motin 	 *
305e68eef14SAlexander Motin 	 * The is_initiator is the current state of initiator on this port.
306e68eef14SAlexander Motin 	 *
3072df76c16SMatt Jacob 	 * Portid is obvious, as are node && port WWNs. The new_role and
308f7c631bcSMatt Jacob 	 * new_portid is for when we are pending a change.
309f7c631bcSMatt Jacob 	 */
3106f9dbc0eSKenneth D. Merry 	uint16_t	prli_word0;		/* PRLI parameters */
311387d8239SMatt Jacob 	uint16_t	prli_word3;		/* PRLI parameters */
3126f9dbc0eSKenneth D. Merry 	uint16_t	new_prli_word0;		/* Incoming new PRLI parameters */
313387d8239SMatt Jacob 	uint16_t	new_prli_word3;		/* Incoming new PRLI parameters */
3145fa351edSAlexander Motin 	uint16_t			: 12,
315eea52482SAlexander Motin 			probational	: 1,
31610365e5aSMatt Jacob 			state		: 3;
317e68eef14SAlexander Motin 	uint32_t			: 6,
318e68eef14SAlexander Motin 			is_target	: 1,
319e68eef14SAlexander Motin 			is_initiator	: 1,
32010365e5aSMatt Jacob 			portid		: 24;
3212df76c16SMatt Jacob 	uint32_t
322e68eef14SAlexander Motin 					: 8,
32310365e5aSMatt Jacob 			new_portid	: 24;
32410365e5aSMatt Jacob 	uint64_t	node_wwn;
32510365e5aSMatt Jacob 	uint64_t	port_wwn;
326427fa8f9SMatt Jacob 	uint32_t	gone_timer;
32710365e5aSMatt Jacob } fcportdb_t;
32810365e5aSMatt Jacob 
329eea52482SAlexander Motin #define	FC_PORTDB_STATE_NIL		0	/* Empty DB slot */
330eea52482SAlexander Motin #define	FC_PORTDB_STATE_DEAD		1	/* Was valid, but no more. */
331eea52482SAlexander Motin #define	FC_PORTDB_STATE_CHANGED		2	/* Was valid, but changed. */
332eea52482SAlexander Motin #define	FC_PORTDB_STATE_NEW		3	/* Logged in, not announced. */
333eea52482SAlexander Motin #define	FC_PORTDB_STATE_ZOMBIE		4	/* Invalid, but announced. */
334eea52482SAlexander Motin #define	FC_PORTDB_STATE_VALID		5	/* Valid */
33510365e5aSMatt Jacob 
336e68eef14SAlexander Motin #define	FC_PORTDB_TGT(isp, bus, pdb)		(int)(lp - FCPARAM(isp, bus)->portdb)
337e68eef14SAlexander Motin 
33810365e5aSMatt Jacob /*
33910365e5aSMatt Jacob  * FC card specific information
3402df76c16SMatt Jacob  *
3412df76c16SMatt Jacob  * This structure is replicated across multiple channels for multi-id
3422df76c16SMatt Jacob  * capapble chipsets, with some entities different on a per-channel basis.
34310365e5aSMatt Jacob  */
3442df76c16SMatt Jacob 
34510365e5aSMatt Jacob typedef struct {
346e596ff7aSAlexander Motin 	int			isp_gbspeed;		/* Connection speed */
347e596ff7aSAlexander Motin 	int			isp_linkstate;		/* Link state */
348e596ff7aSAlexander Motin 	int			isp_fwstate;		/* ISP F/W state */
349e596ff7aSAlexander Motin 	int			isp_loopstate;		/* Loop State */
350e596ff7aSAlexander Motin 	int			isp_topo;		/* Connection Type */
351e596ff7aSAlexander Motin 
352e561aa79SAlexander Motin 	uint32_t				: 4,
353387d8239SMatt Jacob 				fctape_enabled	: 1,
3542df76c16SMatt Jacob 				sendmarker	: 1,
3552df76c16SMatt Jacob 				role		: 2,
356e5265237SMatt Jacob 				isp_portid	: 24;	/* S_ID */
3572df76c16SMatt Jacob 
3581dae40ebSMatt Jacob 	uint16_t		isp_fwoptions;
3598a97c03aSMatt Jacob 	uint16_t		isp_xfwoptions;
3608a97c03aSMatt Jacob 	uint16_t		isp_zfwoptions;
3611dae40ebSMatt Jacob 	uint16_t		isp_loopid;		/* hard loop id */
3622df76c16SMatt Jacob 	uint16_t		isp_sns_hdl;		/* N-port handle for SNS */
3632df76c16SMatt Jacob 	uint16_t		isp_lasthdl;		/* only valid for channel 0 */
364ad0ab753SMatt Jacob 	uint16_t		isp_fabric_params;
365ace7039eSAlexander Motin 	uint16_t		isp_login_hdl;		/* Logging in handle */
3661dae40ebSMatt Jacob 	uint8_t			isp_retry_delay;
3671dae40ebSMatt Jacob 	uint8_t			isp_retry_count;
368a94fab67SAlexander Motin 	int			isp_use_gft_id;		/* Use GFT_ID */
369a94fab67SAlexander Motin 	int			isp_use_gff_id;		/* Use GFF_ID */
3702df76c16SMatt Jacob 
37127b4a1b7SJoerg Pulz 	uint32_t		flash_data_addr;
37210ed63fcSJoerg Pulz 	uint32_t		fw_flashrev[4]; /* Flash F/W revision */
37310ed63fcSJoerg Pulz 	uint32_t		fw_ispfwrev[4]; /* ispfw(4) F/W revision */
37410ed63fcSJoerg Pulz 	char			fw_version_flash[12];
37510ed63fcSJoerg Pulz 	char			fw_version_ispfw[12];
37610ed63fcSJoerg Pulz 	char			fw_version_run[12];
37710ed63fcSJoerg Pulz 	uint32_t		fw_ability_mask;
37810ed63fcSJoerg Pulz 	uint16_t		max_supported_speed;
37910ed63fcSJoerg Pulz 
38027b4a1b7SJoerg Pulz 	/*
38127b4a1b7SJoerg Pulz 	 * FLT
38227b4a1b7SJoerg Pulz 	 */
38327b4a1b7SJoerg Pulz 	uint16_t		flt_length;
38427b4a1b7SJoerg Pulz 	uint32_t		flt_region_entries;
38527b4a1b7SJoerg Pulz 	uint32_t		flt_region_flt;
38610ed63fcSJoerg Pulz 	uint32_t		flt_region_fdt;
38710ed63fcSJoerg Pulz 	uint32_t		flt_region_boot;
388707e4d1bSJoerg Pulz 	uint32_t		flt_region_boot_sec;
38910ed63fcSJoerg Pulz 	uint32_t		flt_region_fw;
39010ed63fcSJoerg Pulz 	uint32_t		flt_region_fw_sec;
39127b4a1b7SJoerg Pulz 	uint32_t		flt_region_vpd_nvram;
39227b4a1b7SJoerg Pulz 	uint32_t		flt_region_vpd_nvram_sec;
39310ed63fcSJoerg Pulz 	uint32_t		flt_region_vpd;
39427b4a1b7SJoerg Pulz 	uint32_t		flt_region_vpd_sec;
39510ed63fcSJoerg Pulz 	uint32_t		flt_region_nvram;
39610ed63fcSJoerg Pulz 	uint32_t		flt_region_nvram_sec;
39710ed63fcSJoerg Pulz 	uint32_t		flt_region_npiv_conf;
39810ed63fcSJoerg Pulz 	uint32_t		flt_region_gold_fw;
39910ed63fcSJoerg Pulz 	uint32_t		flt_region_fcp_prio;
40010ed63fcSJoerg Pulz 	uint32_t		flt_region_bootload;
40110ed63fcSJoerg Pulz 	uint32_t		flt_region_img_status_pri;
40210ed63fcSJoerg Pulz 	uint32_t		flt_region_img_status_sec;
40310ed63fcSJoerg Pulz 	uint32_t		flt_region_aux_img_status_pri;
40410ed63fcSJoerg Pulz 	uint32_t		flt_region_aux_img_status_sec;
40527b4a1b7SJoerg Pulz 
4062df76c16SMatt Jacob 	/*
4072df76c16SMatt Jacob 	 * Current active WWNN/WWPN
4082df76c16SMatt Jacob 	 */
4092df76c16SMatt Jacob 	uint64_t		isp_wwnn;
4102df76c16SMatt Jacob 	uint64_t		isp_wwpn;
4112df76c16SMatt Jacob 
4122df76c16SMatt Jacob 	/*
4132df76c16SMatt Jacob 	 * NVRAM WWNN/WWPN
4142df76c16SMatt Jacob 	 */
4156c81a0aeSMatt Jacob 	uint64_t		isp_wwnn_nvram;
4166c81a0aeSMatt Jacob 	uint64_t		isp_wwpn_nvram;
417f7c631bcSMatt Jacob 
418f7c631bcSMatt Jacob 	/*
419f7c631bcSMatt Jacob 	 * Our Port Data Base
420f7c631bcSMatt Jacob 	 */
42110365e5aSMatt Jacob 	fcportdb_t		portdb[MAX_FC_TARG];
422f7c631bcSMatt Jacob 
42357c801f5SMatt Jacob 	/*
4246054c3f6SMatt Jacob 	 * Scratch DMA mapped in area to fetch Port Database stuff, etc.
4256054c3f6SMatt Jacob 	 */
4261dae40ebSMatt Jacob 	void *			isp_scratch;
4271dae40ebSMatt Jacob 	XS_DMA_ADDR_T		isp_scdma;
4285d084976SAlexander Motin 
4295d084976SAlexander Motin 	uint8_t			isp_scanscratch[ISP_FC_SCRLEN];
4306054c3f6SMatt Jacob } fcparam;
4316054c3f6SMatt Jacob 
43210ed63fcSJoerg Pulz /*
43310ed63fcSJoerg Pulz  * Image status
43410ed63fcSJoerg Pulz  */
43510ed63fcSJoerg Pulz struct isp_image_status{
43610ed63fcSJoerg Pulz 	uint8_t		image_status_mask;
43710ed63fcSJoerg Pulz 	uint16_t	generation;
43810ed63fcSJoerg Pulz 	uint8_t		ver_major;
43910ed63fcSJoerg Pulz 	uint8_t		ver_minor;
44010ed63fcSJoerg Pulz 	uint8_t		bitmap;		/* 28xx only */
44110ed63fcSJoerg Pulz 	uint8_t		reserved[2];
44210ed63fcSJoerg Pulz 	uint32_t	checksum;
44310ed63fcSJoerg Pulz 	uint32_t	signature;
44410ed63fcSJoerg Pulz } __packed;
44510ed63fcSJoerg Pulz 
44610ed63fcSJoerg Pulz /* 28xx aux image status bitmap values */
44710ed63fcSJoerg Pulz #define ISP28XX_AUX_IMG_BOARD_CONFIG		0x1
44810ed63fcSJoerg Pulz #define ISP28XX_AUX_IMG_VPD_NVRAM		0x2
44910ed63fcSJoerg Pulz #define ISP28XX_AUX_IMG_NPIV_CONFIG_0_1		0x4
45010ed63fcSJoerg Pulz #define ISP28XX_AUX_IMG_NPIV_CONFIG_2_3		0x8
45110ed63fcSJoerg Pulz #define ISP28XX_AUX_IMG_NVME_PARAMS		0x10
45210ed63fcSJoerg Pulz 
45310ed63fcSJoerg Pulz /*
45410ed63fcSJoerg Pulz  * Active regions
45510ed63fcSJoerg Pulz  */
45610ed63fcSJoerg Pulz struct active_regions {
45710ed63fcSJoerg Pulz 	uint8_t global;
45810ed63fcSJoerg Pulz 	struct {
45910ed63fcSJoerg Pulz 		uint8_t	board_config;
46010ed63fcSJoerg Pulz 		uint8_t	vpd_nvram;
46110ed63fcSJoerg Pulz 		uint8_t	npiv_config_0_1;
46210ed63fcSJoerg Pulz 		uint8_t	npiv_config_2_3;
46310ed63fcSJoerg Pulz 		uint8_t	nvme_params;
46410ed63fcSJoerg Pulz 	} aux;
46510ed63fcSJoerg Pulz };
46610ed63fcSJoerg Pulz 
46777d4e836SMatt Jacob #define	FW_CONFIG_WAIT		0
468b6bd5f7fSAlexander Motin #define	FW_WAIT_LINK		1
46977d4e836SMatt Jacob #define	FW_WAIT_LOGIN		2
47077d4e836SMatt Jacob #define	FW_READY		3
47177d4e836SMatt Jacob #define	FW_LOSS_OF_SYNC		4
47277d4e836SMatt Jacob #define	FW_ERROR		5
47377d4e836SMatt Jacob #define	FW_REINIT		6
47477d4e836SMatt Jacob #define	FW_NON_PART		7
4756054c3f6SMatt Jacob 
47677d4e836SMatt Jacob #define	LOOP_NIL		0
477e561aa79SAlexander Motin #define	LOOP_HAVE_LINK		1
478212fad74SAlexander Motin #define	LOOP_HAVE_ADDR		2
479212fad74SAlexander Motin #define	LOOP_TESTING_LINK	3
480212fad74SAlexander Motin #define	LOOP_LTEST_DONE		4
481212fad74SAlexander Motin #define	LOOP_SCANNING_LOOP	5
482212fad74SAlexander Motin #define	LOOP_LSCAN_DONE		6
483212fad74SAlexander Motin #define	LOOP_SCANNING_FABRIC	7
484212fad74SAlexander Motin #define	LOOP_FSCAN_DONE		8
485212fad74SAlexander Motin #define	LOOP_SYNCING_PDB	9
486212fad74SAlexander Motin #define	LOOP_READY		10
48777d4e836SMatt Jacob 
488d465588aSMatt Jacob #define	TOPO_NL_PORT		0
489d465588aSMatt Jacob #define	TOPO_FL_PORT		1
490d465588aSMatt Jacob #define	TOPO_N_PORT		2
491d465588aSMatt Jacob #define	TOPO_F_PORT		3
492d465588aSMatt Jacob #define	TOPO_PTP_STUB		4
493d465588aSMatt Jacob 
494eea52482SAlexander Motin #define TOPO_IS_FABRIC(x)	((x) == TOPO_FL_PORT || (x) == TOPO_F_PORT)
495eea52482SAlexander Motin 
49657b6261fSKenneth D. Merry #define FCP_AL_DA_ALL		0xFF
49757b6261fSKenneth D. Merry #define FCP_AL_PA(fcp) ((uint8_t)(fcp->isp_portid))
49857b6261fSKenneth D. Merry #define FCP_IS_DEST_ALPD(fcp, alpd) (FCP_AL_PA((fcp)) == FCP_AL_DA_ALL || FCP_AL_PA((fcp)) == alpd)
49957b6261fSKenneth D. Merry 
5006054c3f6SMatt Jacob /*
5016054c3f6SMatt Jacob  * Soft Structure per host adapter
5026054c3f6SMatt Jacob  */
5031dae40ebSMatt Jacob struct ispsoftc {
5046054c3f6SMatt Jacob 	/*
5056054c3f6SMatt Jacob 	 * Platform (OS) specific data
5066054c3f6SMatt Jacob 	 */
5076054c3f6SMatt Jacob 	struct isposinfo	isp_osinfo;
5086054c3f6SMatt Jacob 
5096054c3f6SMatt Jacob 	/*
51080ae5655SMatt Jacob 	 * Pointer to bus specific functions and data
5116054c3f6SMatt Jacob 	 */
5126054c3f6SMatt Jacob 	struct ispmdvec *	isp_mdvec;
5136054c3f6SMatt Jacob 
5146054c3f6SMatt Jacob 	/*
51580ae5655SMatt Jacob 	 * (Mostly) nonvolatile state. Board specific parameters
51680ae5655SMatt Jacob 	 * may contain some volatile state (e.g., current loop state).
5176054c3f6SMatt Jacob 	 */
5186054c3f6SMatt Jacob 
519a6222dd7SAlexander Motin 	fcparam			*isp_param;	/* Per-channel storage. */
52010ed63fcSJoerg Pulz 	uint16_t		isp_fwattr;	/* firmware attributes */
52110ed63fcSJoerg Pulz 	uint16_t		isp_fwattr_h;	/* firmware attributes */
52210ed63fcSJoerg Pulz 	uint16_t		isp_fwattr_ext[2]; /* firmware attributes */
5231dae40ebSMatt Jacob 	uint16_t		isp_fwrev[3];	/* Loaded F/W revision */
5241dae40ebSMatt Jacob 	uint16_t		isp_maxcmds;	/* max possible I/O cmds */
525a6222dd7SAlexander Motin 	uint16_t		isp_nchan;	/* number of channels */
526a6222dd7SAlexander Motin 	uint16_t		isp_dblev;	/* debug log mask */
52710ed63fcSJoerg Pulz 	uint32_t		isp_did;	/* DID */
5281dae40ebSMatt Jacob 	uint8_t			isp_type;	/* HBA Chip Type */
5291dae40ebSMatt Jacob 	uint8_t			isp_revision;	/* HBA Chip H/W Revision */
53008826086SAlexander Motin 	uint8_t			isp_nirq;	/* number of IRQs */
531a6222dd7SAlexander Motin 	uint8_t			isp_port;	/* physical port on a card */
5321dae40ebSMatt Jacob 	uint32_t		isp_confopts;	/* config options */
5337afb656fSMatt Jacob 
5346054c3f6SMatt Jacob 	/*
535478f8a96SJustin T. Gibbs 	 * Volatile state
5366054c3f6SMatt Jacob 	 */
537a1fa0267SAlexander Motin 	volatile u_int		isp_mboxbsy;	/* mailbox command active */
538a1fa0267SAlexander Motin 	volatile u_int		isp_state;
53910365e5aSMatt Jacob 	volatile uint32_t	isp_reqodx;	/* index of last ISP pickup */
54010365e5aSMatt Jacob 	volatile uint32_t	isp_reqidx;	/* index of next request */
54110365e5aSMatt Jacob 	volatile uint32_t	isp_resodx;	/* index of next result */
542523ea374SAlexander Motin 	volatile uint32_t	isp_atioodx;	/* index of next ATIO */
54310365e5aSMatt Jacob 	volatile uint32_t	isp_obits;	/* mailbox command output */
5442df76c16SMatt Jacob 	volatile uint32_t	isp_serno;	/* rolling serial number */
545ad0ab753SMatt Jacob 	volatile uint16_t	isp_mboxtmp[MAX_MAILBOX];
546c8b8a2c4SMatt Jacob 	volatile uint16_t	isp_seqno;	/* running sequence number */
5470f99cb55SAlexander Motin 	u_int			isp_rqovf;	/* request queue overflow */
548478f8a96SJustin T. Gibbs 
549478f8a96SJustin T. Gibbs 	/*
55080ae5655SMatt Jacob 	 * Active commands are stored here, indexed by handle functions.
551478f8a96SJustin T. Gibbs 	 */
552c8b8a2c4SMatt Jacob 	isp_hdl_t		*isp_xflist;
553c8b8a2c4SMatt Jacob 	isp_hdl_t		*isp_xffree;
5546054c3f6SMatt Jacob 
5556054c3f6SMatt Jacob 	/*
5564ff970c4SAlexander Motin 	 * DMA mapped in area for synchronous IOCB requests.
5574ff970c4SAlexander Motin 	 */
5584ff970c4SAlexander Motin 	void *			isp_iocb;
5594ff970c4SAlexander Motin 	XS_DMA_ADDR_T		isp_iocb_dma;
5604ff970c4SAlexander Motin 
5614ff970c4SAlexander Motin 	/*
5624b39f27dSMatt Jacob 	 * request/result queue pointers and DMA handles for them.
5636054c3f6SMatt Jacob 	 */
5641dae40ebSMatt Jacob 	void *			isp_rquest;
5651dae40ebSMatt Jacob 	void *			isp_result;
5661dae40ebSMatt Jacob 	XS_DMA_ADDR_T		isp_rquest_dma;
5671dae40ebSMatt Jacob 	XS_DMA_ADDR_T		isp_result_dma;
56810365e5aSMatt Jacob #ifdef	ISP_TARGET_MODE
56910365e5aSMatt Jacob 	/* for 24XX only */
57010365e5aSMatt Jacob 	void *			isp_atioq;
57110365e5aSMatt Jacob 	XS_DMA_ADDR_T		isp_atioq_dma;
57210365e5aSMatt Jacob #endif
5731dae40ebSMatt Jacob };
5746054c3f6SMatt Jacob 
575a6222dd7SAlexander Motin #define	FCPARAM(isp, chan)	(&(isp)->isp_param[(chan)])
5762df76c16SMatt Jacob 
5772df76c16SMatt Jacob #define	ISP_SET_SENDMARKER(isp, chan, val)	\
5781b760be4SAlexander Motin     FCPARAM(isp, chan)->sendmarker = val	\
5792df76c16SMatt Jacob 
5802df76c16SMatt Jacob #define	ISP_TST_SENDMARKER(isp, chan)		\
5811b760be4SAlexander Motin     (FCPARAM(isp, chan)->sendmarker != 0)
5820f747d72SMatt Jacob 
5836054c3f6SMatt Jacob /*
58453cff3bbSMatt Jacob  * ISP Driver Run States
5856054c3f6SMatt Jacob  */
5866054c3f6SMatt Jacob #define	ISP_NILSTATE	0
5878a97c03aSMatt Jacob #define	ISP_CRASHED	1
5888a97c03aSMatt Jacob #define	ISP_RESETSTATE	2
5898a97c03aSMatt Jacob #define	ISP_INITSTATE	3
5908a97c03aSMatt Jacob #define	ISP_RUNSTATE	4
5916054c3f6SMatt Jacob 
5926054c3f6SMatt Jacob /*
5939e7d423dSMatt Jacob  * ISP Runtime Configuration Options
5946054c3f6SMatt Jacob  */
59580ae5655SMatt Jacob #define	ISP_CFG_FULL_DUPLEX	0x01	/* Full Duplex (Fibre Channel only) */
5965f2638daSAlexander Motin #define	ISP_CFG_PORT_PREF	0x0e	/* Mask for Port Prefs (all FC except 2100) */
5975f2638daSAlexander Motin #define	ISP_CFG_PORT_DEF	0x00	/* prefer connection type from NVRAM */
5985f2638daSAlexander Motin #define	ISP_CFG_LPORT_ONLY	0x02	/* insist on {N/F}L-Port connection */
5995f2638daSAlexander Motin #define	ISP_CFG_NPORT_ONLY	0x04	/* insist on {N/F}-Port connection */
6005f2638daSAlexander Motin #define	ISP_CFG_LPORT		0x06	/* prefer {N/F}L-Port connection */
6015f2638daSAlexander Motin #define	ISP_CFG_NPORT		0x08	/* prefer {N/F}-Port connection */
60214e084adSAlexander Motin #define	ISP_CFG_1GB		0x10	/* force 1Gb connection (23XX only) */
60314e084adSAlexander Motin #define	ISP_CFG_2GB		0x20	/* force 2Gb connection (23XX only) */
604387d8239SMatt Jacob #define	ISP_CFG_NONVRAM		0x40	/* ignore NVRAM */
60510ed63fcSJoerg Pulz #define	ISP_CFG_NORELOAD	0x80	/* don't download f/w */
606387d8239SMatt Jacob #define	ISP_CFG_NOFCTAPE	0x100	/* disable FC-Tape */
607387d8239SMatt Jacob #define	ISP_CFG_FCTAPE		0x200	/* enable FC-Tape */
6080499ae00SMatt Jacob #define	ISP_CFG_OWNFSZ		0x400	/* override NVRAM frame size */
6090499ae00SMatt Jacob #define	ISP_CFG_OWNLOOPID	0x800	/* override NVRAM loopid */
61014e084adSAlexander Motin #define	ISP_CFG_4GB		0x2000	/* force 4Gb connection (24XX only) */
61114e084adSAlexander Motin #define	ISP_CFG_8GB		0x4000	/* force 8Gb connection (25XX only) */
61214e084adSAlexander Motin #define	ISP_CFG_16GB		0x8000	/* force 16Gb connection (26XX only) */
61314e084adSAlexander Motin #define	ISP_CFG_32GB		0x10000	/* force 32Gb connection (27XX only) */
614407abff6SJoerg Pulz #define	ISP_CFG_64GB		0x20000	/* force 64Gb connection (28XX only) */
615*31354813SKenneth D. Merry #define	ISP_CFG_FWLOAD_FORCE	0x40000 /* Prefer ispfw(4) even if older */
6166054c3f6SMatt Jacob 
61753cff3bbSMatt Jacob /*
6182df76c16SMatt Jacob  * For each channel, the outer layers should know what role that channel
6192df76c16SMatt Jacob  * will take: ISP_ROLE_NONE, ISP_ROLE_INITIATOR, ISP_ROLE_TARGET,
6202df76c16SMatt Jacob  * ISP_ROLE_BOTH.
6217afb656fSMatt Jacob  *
6227afb656fSMatt Jacob  * If you set ISP_ROLE_NONE, the cards will be reset, new firmware loaded,
6237afb656fSMatt Jacob  * NVRAM read, and defaults set, but any further initialization (e.g.
6247afb656fSMatt Jacob  * INITIALIZE CONTROL BLOCK commands for 2X00 cards) won't be done.
6257afb656fSMatt Jacob  *
6267afb656fSMatt Jacob  * If INITIATOR MODE isn't set, attempts to run commands will be stopped
6272df76c16SMatt Jacob  * at isp_start and completed with the equivalent of SELECTION TIMEOUT.
6287afb656fSMatt Jacob  *
6297afb656fSMatt Jacob  * If TARGET MODE is set, it doesn't mean that the rest of target mode support
6307afb656fSMatt Jacob  * needs to be enabled, or will even work. What happens with the 2X00 cards
6317afb656fSMatt Jacob  * here is that if you have enabled it with TARGET MODE as part of the ICB
6327afb656fSMatt Jacob  * options, but you haven't given the f/w any ram resources for ATIOs or
6337afb656fSMatt Jacob  * Immediate Notifies, the f/w just handles what it can and you never see
6347afb656fSMatt Jacob  * anything. Basically, it sends a single byte of data (the first byte,
6357afb656fSMatt Jacob  * which you can set as part of the INITIALIZE CONTROL BLOCK command) for
6367afb656fSMatt Jacob  * INQUIRY, and sends back QUEUE FULL status for any other command.
6377afb656fSMatt Jacob  *
6387afb656fSMatt Jacob  */
6397afb656fSMatt Jacob #define	ISP_ROLE_NONE		0x0
640e0d3cfb7SMatt Jacob #define	ISP_ROLE_TARGET		0x1
641e0d3cfb7SMatt Jacob #define	ISP_ROLE_INITIATOR	0x2
6427afb656fSMatt Jacob #define	ISP_ROLE_BOTH		(ISP_ROLE_TARGET|ISP_ROLE_INITIATOR)
6437afb656fSMatt Jacob #define	ISP_ROLE_EITHER		ISP_ROLE_BOTH
6447afb656fSMatt Jacob #ifndef	ISP_DEFAULT_ROLES
645e2873b76SMatt Jacob /*
646e2873b76SMatt Jacob  * Counterintuitively, we prefer to default to role 'none'
647e2873b76SMatt Jacob  * if we are enable target mode support. This gives us the
648e2873b76SMatt Jacob  * maximum flexibility as to which port will do what.
649e2873b76SMatt Jacob  */
650e2873b76SMatt Jacob #ifdef	ISP_TARGET_MODE
651e2873b76SMatt Jacob #define	ISP_DEFAULT_ROLES	ISP_ROLE_NONE
652e2873b76SMatt Jacob #else
6537afb656fSMatt Jacob #define	ISP_DEFAULT_ROLES	ISP_ROLE_INITIATOR
6547afb656fSMatt Jacob #endif
655e2873b76SMatt Jacob #endif
6567afb656fSMatt Jacob 
6577afb656fSMatt Jacob 
6587afb656fSMatt Jacob /*
65953cff3bbSMatt Jacob  * Firmware related defines
66053cff3bbSMatt Jacob  */
66153cff3bbSMatt Jacob #define	ISP_CODE_ORG			0x1000	/* default f/w code start */
662126ec864SMatt Jacob #define	ISP_CODE_ORG_2300		0x0800	/* ..except for 2300s */
66310365e5aSMatt Jacob #define	ISP_CODE_ORG_2400		0x100000 /* ..and 2400s */
66410ed63fcSJoerg Pulz #define	ISP_FW_REV(maj, min, mic)	(((maj) << 16) | ((min) << 8) | (mic))
66510ed63fcSJoerg Pulz #define	ISP_FW_MAJOR(code)		(((code) >> 16) & 0xff)
66610ed63fcSJoerg Pulz #define	ISP_FW_MINOR(code)		(((code) >> 8) & 0xff)
66710ed63fcSJoerg Pulz #define	ISP_FW_MICRO(code)		((code) & 0xff)
66810ed63fcSJoerg Pulz #define	ISP_FW_REVX(xp)			(((xp)[0] << 16) | ((xp)[1] << 8) | (xp)[2])
669f8597b62SMatt Jacob #define	ISP_FW_MAJORX(xp)		(xp[0])
670f8597b62SMatt Jacob #define	ISP_FW_MINORX(xp)		(xp[1])
671f8597b62SMatt Jacob #define	ISP_FW_MICROX(xp)		(xp[2])
672e347e2c9SMatt Jacob #define	ISP_FW_NEWER_THAN(i, major, minor, micro)		\
67310ed63fcSJoerg Pulz 	(ISP_FW_REVX(i) > ISP_FW_REV(major, minor, micro))
67410365e5aSMatt Jacob #define	ISP_FW_OLDER_THAN(i, major, minor, micro)		\
67510ed63fcSJoerg Pulz 	(ISP_FW_REVX(i) < ISP_FW_REV(major, minor, micro))
67610ed63fcSJoerg Pulz #define	ISP_FW_NEWER_THANX(i, j)		\
67710ed63fcSJoerg Pulz 	(ISP_FW_REVX(i) > ISP_FW_REVX(j))
67810ed63fcSJoerg Pulz #define	ISP_FW_OLDER_THANX(i, j)		\
67910ed63fcSJoerg Pulz 	(ISP_FW_REVX(i) < ISP_FW_REVX(j))
68012b36e2dSMatt Jacob 
6816054c3f6SMatt Jacob /*
682478f8a96SJustin T. Gibbs  * Chip Types
6836054c3f6SMatt Jacob  */
6841b760be4SAlexander Motin #define	ISP_HA_FC_2400		0x04
6851b760be4SAlexander Motin #define	ISP_HA_FC_2500		0x05
6861b760be4SAlexander Motin #define	ISP_HA_FC_2600		0x06
6871b760be4SAlexander Motin #define	ISP_HA_FC_2700		0x07
688407abff6SJoerg Pulz #define	ISP_HA_FC_2800		0x08
6896054c3f6SMatt Jacob 
6902df76c16SMatt Jacob #define	IS_25XX(isp)	((isp)->isp_type >= ISP_HA_FC_2500)
691218be0b2SAlexander Motin #define	IS_26XX(isp)	((isp)->isp_type >= ISP_HA_FC_2600)
69214e084adSAlexander Motin #define	IS_27XX(isp)	((isp)->isp_type >= ISP_HA_FC_2700)
693407abff6SJoerg Pulz #define	IS_28XX(isp)	((isp)->isp_type >= ISP_HA_FC_2800)
69483fbc566SMatt Jacob 
69553cff3bbSMatt Jacob /*
6961dae40ebSMatt Jacob  * DMA related macros
69753cff3bbSMatt Jacob  */
69810365e5aSMatt Jacob #define	DMA_WD3(x)	(((uint16_t)(((uint64_t)x) >> 48)) & 0xffff)
69910365e5aSMatt Jacob #define	DMA_WD2(x)	(((uint16_t)(((uint64_t)x) >> 32)) & 0xffff)
70010365e5aSMatt Jacob #define	DMA_WD1(x)	((uint16_t)((x) >> 16) & 0xffff)
70110365e5aSMatt Jacob #define	DMA_WD0(x)	((uint16_t)((x) & 0xffff))
70257c801f5SMatt Jacob 
7031dae40ebSMatt Jacob #define	DMA_LO32(x)	((uint32_t) (x))
7041dae40ebSMatt Jacob #define	DMA_HI32(x)	((uint32_t)(((uint64_t)x) >> 32))
7051dae40ebSMatt Jacob 
7066054c3f6SMatt Jacob /*
70710ed63fcSJoerg Pulz  * function return status codes
70810ed63fcSJoerg Pulz  */
70910ed63fcSJoerg Pulz #define MBS_MASK		0x3fff
71010ed63fcSJoerg Pulz 
71110ed63fcSJoerg Pulz #define ISP_SUCCESS		(MBOX_COMMAND_COMPLETE & MBS_MASK)
71210ed63fcSJoerg Pulz #define ISP_INVALID_COMMAND	(MBOX_INVALID_COMMAND & MBS_MASK)
71310ed63fcSJoerg Pulz #define ISP_INTERFACE_ERROR	(MBOX_HOST_INTERFACE_ERROR & MBS_MASK)
71410ed63fcSJoerg Pulz #define ISP_TEST_FAILED		(MBOX_TEST_FAILED & MBS_MASK)
71510ed63fcSJoerg Pulz #define ISP_COMMAND_ERROR	(MBOX_COMMAND_ERROR & MBS_MASK)
71610ed63fcSJoerg Pulz #define ISP_PARAMETER_ERROR	(MBOX_COMMAND_PARAMETER_ERROR & MBS_MASK)
71710ed63fcSJoerg Pulz #define ISP_PORT_ID_USED	(MBOX_PORT_ID_USED & MBS_MASK)
71810ed63fcSJoerg Pulz #define ISP_LOOP_ID_USED	(MBOX_LOOP_ID_USED & MBS_MASK)
71910ed63fcSJoerg Pulz #define ISP_ALL_IDS_IN_USE	(MBOX_ALL_IDS_IN_USE & MBS_MASK)
72010ed63fcSJoerg Pulz #define ISP_NOT_LOGGED_IN	(MBOX_NOT_LOGGED_IN & MBS_MASK)
72110ed63fcSJoerg Pulz 
72210ed63fcSJoerg Pulz #define ISP_FUNCTION_TIMEOUT		0x100
72310ed63fcSJoerg Pulz #define ISP_FUNCTION_PARAMETER_ERROR	0x101
72410ed63fcSJoerg Pulz #define ISP_FUNCTION_FAILED		0x102
72510ed63fcSJoerg Pulz #define ISP_MEMORY_ALLOC_FAILED		0x103
72610ed63fcSJoerg Pulz #define ISP_LOCK_TIMEOUT		0x104
72710ed63fcSJoerg Pulz #define ISP_ABORTED			0x105
72810ed63fcSJoerg Pulz #define ISP_SUSPENDED			0x106
72910ed63fcSJoerg Pulz #define ISP_BUSY			0x107
73010ed63fcSJoerg Pulz #define ISP_ALREADY_REGISTERED		0x109
73110ed63fcSJoerg Pulz #define ISP_OS_TIMER_EXPIRED		0x10a
73210ed63fcSJoerg Pulz #define ISP_ERR_NO_QPAIR		0x10b
73310ed63fcSJoerg Pulz #define ISP_ERR_NOT_FOUND		0x10c
73410ed63fcSJoerg Pulz #define ISP_ERR_FROM_FW			0x10d
73510ed63fcSJoerg Pulz 
73610ed63fcSJoerg Pulz /*
73753cff3bbSMatt Jacob  * Core System Function Prototypes
7386054c3f6SMatt Jacob  */
7396054c3f6SMatt Jacob 
7406054c3f6SMatt Jacob /*
7412df76c16SMatt Jacob  * Reset Hardware. Totally. Assumes that you'll follow this with a call to isp_init.
7426054c3f6SMatt Jacob  */
7432df76c16SMatt Jacob void isp_reset(ispsoftc_t *, int);
7446054c3f6SMatt Jacob 
7456054c3f6SMatt Jacob /*
7466054c3f6SMatt Jacob  * Initialize Hardware to known state
7476054c3f6SMatt Jacob  */
7481dae40ebSMatt Jacob void isp_init(ispsoftc_t *);
7496054c3f6SMatt Jacob 
7506054c3f6SMatt Jacob /*
751478f8a96SJustin T. Gibbs  * Reset the ISP and call completion for any orphaned commands.
752478f8a96SJustin T. Gibbs  */
753e68eef14SAlexander Motin int isp_reinit(ispsoftc_t *, int);
75401ff579dSMatt Jacob 
755478f8a96SJustin T. Gibbs /*
756a1fa0267SAlexander Motin  * Shutdown hardware after use.
757a1fa0267SAlexander Motin  */
758a1fa0267SAlexander Motin void isp_shutdown(ispsoftc_t *);
759a1fa0267SAlexander Motin 
760a1fa0267SAlexander Motin /*
761126ec864SMatt Jacob  * Internal Interrupt Service Routine
7626054c3f6SMatt Jacob  */
7630e6bc811SAlexander Motin #ifdef	ISP_TARGET_MODE
7640e6bc811SAlexander Motin void isp_intr_atioq(ispsoftc_t *);
7650e6bc811SAlexander Motin #endif
7660e6bc811SAlexander Motin void isp_intr_async(ispsoftc_t *, uint16_t event);
7670e6bc811SAlexander Motin void isp_intr_mbox(ispsoftc_t *, uint16_t mbox0);
7680e6bc811SAlexander Motin void isp_intr_respq(ispsoftc_t *);
769126ec864SMatt Jacob 
7706054c3f6SMatt Jacob 
7716054c3f6SMatt Jacob /*
77253cff3bbSMatt Jacob  * Command Entry Point- Platform Dependent layers call into this
7736054c3f6SMatt Jacob  */
774e2ec5cf0SMatt Jacob int isp_start(XS_T *);
7751dae40ebSMatt Jacob 
77653cff3bbSMatt Jacob /* these values are what isp_start returns */
77753cff3bbSMatt Jacob #define	CMD_COMPLETE	101	/* command completed */
77853cff3bbSMatt Jacob #define	CMD_EAGAIN	102	/* busy- maybe retry later */
779f6854a0cSAlexander Motin #define	CMD_RQLATER	103	/* requeue this command later */
78053cff3bbSMatt Jacob 
78153cff3bbSMatt Jacob /*
78253cff3bbSMatt Jacob  * Command Completion Point- Core layers call out from this with completed cmds
78353cff3bbSMatt Jacob  */
784e2ec5cf0SMatt Jacob void isp_done(XS_T *);
785478f8a96SJustin T. Gibbs 
786478f8a96SJustin T. Gibbs /*
787cbf57b47SMatt Jacob  * Platform Dependent to External to Internal Control Function
788478f8a96SJustin T. Gibbs  *
789410b5567SMatt Jacob  * Assumes locks are held on entry. You should note that with many of
7902df76c16SMatt Jacob  * these commands locks may be released while this function is called.
791478f8a96SJustin T. Gibbs  *
7922df76c16SMatt Jacob  * ... ISPCTL_RESET_BUS, int channel);
7932df76c16SMatt Jacob  *        Reset BUS on this channel
7942df76c16SMatt Jacob  * ... ISPCTL_RESET_DEV, int channel, int target);
7952df76c16SMatt Jacob  *        Reset Device on this channel at this target.
7962df76c16SMatt Jacob  * ... ISPCTL_ABORT_CMD, XS_T *xs);
7972df76c16SMatt Jacob  *        Abort active transaction described by xs.
7982df76c16SMatt Jacob  * ... IPCTL_UPDATE_PARAMS);
7992df76c16SMatt Jacob  *        Update any operating parameters (speed, etc.)
8002df76c16SMatt Jacob  * ... ISPCTL_FCLINK_TEST, int channel);
8012df76c16SMatt Jacob  *        Test FC link status on this channel
8022df76c16SMatt Jacob  * ... ISPCTL_SCAN_LOOP, int channel);
8032df76c16SMatt Jacob  *        Scan local loop on this channel
804b6bd5f7fSAlexander Motin  * ... ISPCTL_SCAN_FABRIC, int channel);
805b6bd5f7fSAlexander Motin  *        Scan fabric on this channel
8062df76c16SMatt Jacob  * ... ISPCTL_PDB_SYNC, int channel);
8072df76c16SMatt Jacob  *        Synchronize port database on this channel
8082df76c16SMatt Jacob  * ... ISPCTL_SEND_LIP, int channel);
8092df76c16SMatt Jacob  *        Send a LIP on this channel
8102df76c16SMatt Jacob  * ... ISPCTL_GET_NAMES, int channel, int np, uint64_t *wwnn, uint64_t *wwpn)
8112df76c16SMatt Jacob  *        Get a WWNN/WWPN for this N-port handle on this channel
812156c1ebeSAlexander Motin  * ... ISPCTL_RUN_MBOXCMD, mbreg_t *mbp)
813156c1ebeSAlexander Motin  *        Run this mailbox command
8142df76c16SMatt Jacob  * ... ISPCTL_GET_PDB, int channel, int nphandle, isp_pdb_t *pdb)
8152df76c16SMatt Jacob  *        Get PDB on this channel for this N-port handle
8162df76c16SMatt Jacob  * ... ISPCTL_PLOGX, isp_plcmd_t *)
8172df76c16SMatt Jacob  *        Performa a port login/logout
8186bef0aa0SAlexander Motin  * ... ISPCTL_CHANGE_ROLE, int channel, int role);
8196bef0aa0SAlexander Motin  *        Change role of specified channel
820410b5567SMatt Jacob  *
821410b5567SMatt Jacob  * ISPCTL_PDB_SYNC is somewhat misnamed. It actually is the final step, in
822b6bd5f7fSAlexander Motin  * order, of ISPCTL_FCLINK_TEST, ISPCTL_SCAN_LOOP, and ISPCTL_SCAN_FABRIC.
823410b5567SMatt Jacob  * The main purpose of ISPCTL_PDB_SYNC is to complete management of logging
824410b5567SMatt Jacob  * and logging out of fabric devices (if one is on a fabric) and then marking
825410b5567SMatt Jacob  * the 'loop state' as being ready to now be used for sending commands to
826b6bd5f7fSAlexander Motin  * devices.
827478f8a96SJustin T. Gibbs  */
828478f8a96SJustin T. Gibbs typedef enum {
8292df76c16SMatt Jacob 	ISPCTL_RESET_BUS,
8302df76c16SMatt Jacob 	ISPCTL_RESET_DEV,
8312df76c16SMatt Jacob 	ISPCTL_ABORT_CMD,
8322df76c16SMatt Jacob 	ISPCTL_UPDATE_PARAMS,
8332df76c16SMatt Jacob 	ISPCTL_FCLINK_TEST,
8342df76c16SMatt Jacob 	ISPCTL_SCAN_FABRIC,
8352df76c16SMatt Jacob 	ISPCTL_SCAN_LOOP,
8362df76c16SMatt Jacob 	ISPCTL_PDB_SYNC,
8372df76c16SMatt Jacob 	ISPCTL_SEND_LIP,
8382df76c16SMatt Jacob 	ISPCTL_GET_NAMES,
839156c1ebeSAlexander Motin 	ISPCTL_RUN_MBOXCMD,
8402df76c16SMatt Jacob 	ISPCTL_GET_PDB,
8416bef0aa0SAlexander Motin 	ISPCTL_PLOGX,
8426bef0aa0SAlexander Motin 	ISPCTL_CHANGE_ROLE
843478f8a96SJustin T. Gibbs } ispctl_t;
8442df76c16SMatt Jacob int isp_control(ispsoftc_t *, ispctl_t, ...);
845cbf57b47SMatt Jacob 
846cbf57b47SMatt Jacob /*
847cbf57b47SMatt Jacob  * Platform Dependent to Internal to External Control Function
848cbf57b47SMatt Jacob  */
849cbf57b47SMatt Jacob 
850cbf57b47SMatt Jacob typedef enum {
85177d4e836SMatt Jacob 	ISPASYNC_LOOP_DOWN,		/* FC Loop Down */
85277d4e836SMatt Jacob 	ISPASYNC_LOOP_UP,		/* FC Loop Up */
8532df76c16SMatt Jacob 	ISPASYNC_LIP,			/* FC LIP Received */
8542df76c16SMatt Jacob 	ISPASYNC_LOOP_RESET,		/* FC Loop Reset Received */
855410b5567SMatt Jacob 	ISPASYNC_CHANGE_NOTIFY,		/* FC Change Notification */
8562df76c16SMatt Jacob 	ISPASYNC_DEV_ARRIVED,		/* FC Device Arrived */
8572df76c16SMatt Jacob 	ISPASYNC_DEV_CHANGED,		/* FC Device Changed */
8582df76c16SMatt Jacob 	ISPASYNC_DEV_STAYED,		/* FC Device Stayed */
8592df76c16SMatt Jacob 	ISPASYNC_DEV_GONE,		/* FC Device Departure */
8602df76c16SMatt Jacob 	ISPASYNC_TARGET_NOTIFY,		/* All target async notification */
861387d8239SMatt Jacob 	ISPASYNC_TARGET_NOTIFY_ACK,	/* All target notify ack required */
8622df76c16SMatt Jacob 	ISPASYNC_TARGET_ACTION,		/* All target action requested */
8632df76c16SMatt Jacob 	ISPASYNC_FW_CRASH,		/* All Firmware has crashed */
8642df76c16SMatt Jacob 	ISPASYNC_FW_RESTARTED		/* All Firmware has been restarted */
865cbf57b47SMatt Jacob } ispasync_t;
8662df76c16SMatt Jacob void isp_async(ispsoftc_t *, ispasync_t, ...);
867cbf57b47SMatt Jacob 
8682df76c16SMatt Jacob #define	ISPASYNC_CHANGE_PDB	0
8692df76c16SMatt Jacob #define	ISPASYNC_CHANGE_SNS	1
8702df76c16SMatt Jacob #define	ISPASYNC_CHANGE_OTHER	2
871410b5567SMatt Jacob 
872478f8a96SJustin T. Gibbs /*
87353cff3bbSMatt Jacob  * Platform Dependent Error and Debug Printout
874547725beSMatt Jacob  *
875670508b1SMatt Jacob  * Two required functions for each platform must be provided:
876547725beSMatt Jacob  *
8771dae40ebSMatt Jacob  *    void isp_prt(ispsoftc_t *, int level, const char *, ...)
878670508b1SMatt Jacob  *    void isp_xs_prt(ispsoftc_t *, XS_T *, int level, const char *, ...)
879547725beSMatt Jacob  *
880547725beSMatt Jacob  * but due to compiler differences on different platforms this won't be
881670508b1SMatt Jacob  * formally defined here. Instead, they go in each platform definition file.
882478f8a96SJustin T. Gibbs  */
883e9423e21SMatt Jacob 
88453cff3bbSMatt Jacob #define	ISP_LOGALL	0x0	/* log always */
88553cff3bbSMatt Jacob #define	ISP_LOGCONFIG	0x1	/* log configuration messages */
88653cff3bbSMatt Jacob #define	ISP_LOGINFO	0x2	/* log informational messages */
88753cff3bbSMatt Jacob #define	ISP_LOGWARN	0x4	/* log warning messages */
88853cff3bbSMatt Jacob #define	ISP_LOGERR	0x8	/* log error messages */
88953cff3bbSMatt Jacob #define	ISP_LOGDEBUG0	0x10	/* log simple debug messages */
89053cff3bbSMatt Jacob #define	ISP_LOGDEBUG1	0x20	/* log intermediate debug messages */
89153cff3bbSMatt Jacob #define	ISP_LOGDEBUG2	0x40	/* log most debug messages */
892b91862efSMatt Jacob #define	ISP_LOGDEBUG3	0x80	/* log high frequency debug messages */
893387d8239SMatt Jacob #define	ISP_LOG_SANCFG	0x100	/* log SAN configuration */
894670508b1SMatt Jacob #define	ISP_LOG_CWARN	0x200	/* log SCSI command "warnings" (e.g., check conditions) */
895387d8239SMatt Jacob #define	ISP_LOG_WARN1	0x400	/* log WARNS we might be interested at some time */
8962df76c16SMatt Jacob #define	ISP_LOGTINFO	0x1000	/* log informational messages (target mode) */
8972df76c16SMatt Jacob #define	ISP_LOGTDEBUG0	0x2000	/* log simple debug messages (target mode) */
8982df76c16SMatt Jacob #define	ISP_LOGTDEBUG1	0x4000	/* log intermediate debug messages (target) */
8992df76c16SMatt Jacob #define	ISP_LOGTDEBUG2	0x8000	/* log all debug messages (target) */
900478f8a96SJustin T. Gibbs 
90153cff3bbSMatt Jacob /*
90253cff3bbSMatt Jacob  * Each Platform provides it's own isposinfo substructure of the ispsoftc
90353cff3bbSMatt Jacob  * defined above.
90453cff3bbSMatt Jacob  *
90553cff3bbSMatt Jacob  * Each platform must also provide the following macros/defines:
90653cff3bbSMatt Jacob  *
90753cff3bbSMatt Jacob  *
9082df76c16SMatt Jacob  *	ISP_FC_SCRLEN				FC scratch area DMA length
90953cff3bbSMatt Jacob  *
9102df76c16SMatt Jacob  *	ISP_MEMZERO(dst, src)			platform zeroing function
9112df76c16SMatt Jacob  *	ISP_MEMCPY(dst, src, count)		platform copying function
9122df76c16SMatt Jacob  *	ISP_SNPRINTF(buf, bufsize, fmt, ...)	snprintf
9132df76c16SMatt Jacob  *	ISP_DELAY(usecs)			microsecond spindelay function
9142df76c16SMatt Jacob  *	ISP_SLEEP(isp, usecs)			microsecond sleep function
9152df76c16SMatt Jacob  *
9162df76c16SMatt Jacob  *	ISP_INLINE				___inline or not- depending on how
9172df76c16SMatt Jacob  *						good your debugger is
918898899d9SMatt Jacob  *	ISP_MIN					shorthand for ((a) < (b))? (a) : (b)
91953cff3bbSMatt Jacob  *
92053cff3bbSMatt Jacob  *	NANOTIME_T				nanosecond time type
92153cff3bbSMatt Jacob  *
92253cff3bbSMatt Jacob  *	GET_NANOTIME(NANOTIME_T *)		get current nanotime.
92353cff3bbSMatt Jacob  *
9241dae40ebSMatt Jacob  *	GET_NANOSEC(NANOTIME_T *)		get uint64_t from NANOTIME_T
92553cff3bbSMatt Jacob  *
92653cff3bbSMatt Jacob  *	NANOTIME_SUB(NANOTIME_T *, NANOTIME_T *)
92753cff3bbSMatt Jacob  *						subtract two NANOTIME_T values
92853cff3bbSMatt Jacob  *
9291dae40ebSMatt Jacob  *	MAXISPREQUEST(ispsoftc_t *)		maximum request queue size
93053cff3bbSMatt Jacob  *						for this particular board type
93153cff3bbSMatt Jacob  *
93237bb79f1SMarius Strobl  *	MEMORYBARRIER(ispsoftc_t *, barrier_type, offset, size, chan)
93353cff3bbSMatt Jacob  *
93453cff3bbSMatt Jacob  *		Function/Macro the provides memory synchronization on
93553cff3bbSMatt Jacob  *		various objects so that the ISP's and the system's view
93653cff3bbSMatt Jacob  *		of the same object is consistent.
93753cff3bbSMatt Jacob  *
9382df76c16SMatt Jacob  *	FC_SCRATCH_ACQUIRE(ispsoftc_t *, chan)	acquire lock on FC scratch area
9392df76c16SMatt Jacob  *						return -1 if you cannot
9402df76c16SMatt Jacob  *	FC_SCRATCH_RELEASE(ispsoftc_t *, chan)	acquire lock on FC scratch area
94153cff3bbSMatt Jacob  *
942ad0ab753SMatt Jacob  *	FCP_NEXT_CRN(ispsoftc_t *, XS_T *, rslt, channel, target, lun)	generate the next command reference number. XS_T * may be null.
943ad0ab753SMatt Jacob  *
94453cff3bbSMatt Jacob  *	SCSI_GOOD	SCSI 'Good' Status
94553cff3bbSMatt Jacob  *	SCSI_CHECK	SCSI 'Check Condition' Status
94653cff3bbSMatt Jacob  *	SCSI_BUSY	SCSI 'Busy' Status
94753cff3bbSMatt Jacob  *	SCSI_QFULL	SCSI 'Queue Full' Status
94853cff3bbSMatt Jacob  *
94953cff3bbSMatt Jacob  *	XS_T			Platform SCSI transaction type (i.e., command for HBA)
9501dae40ebSMatt Jacob  *	XS_DMA_ADDR_T		Platform PCI DMA Address Type
9512df76c16SMatt Jacob  *	XS_GET_DMA64_SEG(..)	Get 64 bit dma segment list value
95253cff3bbSMatt Jacob  *	XS_ISP(xs)		gets an instance out of an XS_T
95353cff3bbSMatt Jacob  *	XS_CHANNEL(xs)		gets the channel (bus # for DUALBUS cards) ""
95453cff3bbSMatt Jacob  *	XS_TGT(xs)		gets the target ""
95553cff3bbSMatt Jacob  *	XS_LUN(xs)		gets the lun ""
95653cff3bbSMatt Jacob  *	XS_CDBP(xs)		gets a pointer to the scsi CDB ""
95753cff3bbSMatt Jacob  *	XS_CDBLEN(xs)		gets the CDB's length ""
95853cff3bbSMatt Jacob  *	XS_XFRLEN(xs)		gets the associated data transfer length ""
959f6854a0cSAlexander Motin  *	XS_XFRIN(xs)		gets IN direction
960f6854a0cSAlexander Motin  *	XS_XFROUT(xs)		gets OUT direction
96131c161a6SAlexander Motin  *	XS_TIME(xs)		gets the time (in seconds) for this command
9622df76c16SMatt Jacob  *	XS_GET_RESID(xs)	gets the current residual count
9632df76c16SMatt Jacob  *	XS_GET_RESID(xs, resid)	sets the current residual count
96453cff3bbSMatt Jacob  *	XS_STSP(xs)		gets a pointer to the SCSI status byte ""
96553cff3bbSMatt Jacob  *	XS_SNSP(xs)		gets a pointer to the associate sense data
966387d8239SMatt Jacob  *	XS_TOT_SNSLEN(xs)	gets the total length of sense data storage
967453130d9SPedro F. Giffuni  *	XS_CUR_SNSLEN(xs)	gets the currently used length of sense data storage
96853cff3bbSMatt Jacob  *	XS_SNSKEY(xs)		dereferences XS_SNSP to get the current stored Sense Key
969670508b1SMatt Jacob  *	XS_SNSASC(xs)		dereferences XS_SNSP to get the current stored Additional Sense Code
970670508b1SMatt Jacob  *	XS_SNSASCQ(xs)		dereferences XS_SNSP to get the current stored Additional Sense Code Qualifier
97153cff3bbSMatt Jacob  *	XS_TAG_P(xs)		predicate of whether this command should be tagged
97253cff3bbSMatt Jacob  *	XS_TAG_TYPE(xs)		which type of tag to use
97388364968SAlexander Motin  *	XS_PRIORITY(xs)		command priority for SIMPLE tag
97453cff3bbSMatt Jacob  *	XS_SETERR(xs)		set error state
97553cff3bbSMatt Jacob  *
97653cff3bbSMatt Jacob  *		HBA_NOERROR	command has no erros
97753cff3bbSMatt Jacob  *		HBA_BOTCH	hba botched something
97853cff3bbSMatt Jacob  *		HBA_CMDTIMEOUT	command timed out
97953cff3bbSMatt Jacob  *		HBA_SELTIMEOUT	selection timed out (also port logouts for FC)
98053cff3bbSMatt Jacob  *		HBA_TGTBSY	target returned a BUSY status
98153cff3bbSMatt Jacob  *		HBA_BUSRESET	bus reset destroyed command
98253cff3bbSMatt Jacob  *		HBA_ABORTED	command was aborted (by request)
98353cff3bbSMatt Jacob  *		HBA_DATAOVR	a data overrun was detected
98453cff3bbSMatt Jacob  *		HBA_ARQFAIL	Automatic Request Sense failed
98553cff3bbSMatt Jacob  *
98653cff3bbSMatt Jacob  *	XS_ERR(xs)	return current error state
98753cff3bbSMatt Jacob  *	XS_NOERR(xs)	there is no error currently set
98853cff3bbSMatt Jacob  *	XS_INITERR(xs)	initialize error state
98953cff3bbSMatt Jacob  *
9902d24b6afSAlexander Motin  *	XS_SAVE_SENSE(xs, sp, len)	save sense data
991387d8239SMatt Jacob  *	XS_APPEND_SENSE(xs, sp, len)	append more sense data
99253cff3bbSMatt Jacob  *
993670508b1SMatt Jacob  *	XS_SENSE_VALID(xs)		indicates whether sense is valid
994670508b1SMatt Jacob  *
9951dae40ebSMatt Jacob  *	DEFAULT_FRAMESIZE(ispsoftc_t *)		Default Frame Size
9962df76c16SMatt Jacob  *
9973e6deb33SAlexander Motin  *	DEFAULT_ROLE(ispsoftc_t *, int)		Get Default Role for a channel
9982df76c16SMatt Jacob  *	DEFAULT_LOOPID(ispsoftc_t *, int)	Default FC Loop ID
9992df76c16SMatt Jacob  *
10009cf43b97SMatt Jacob  *		These establish reasonable defaults for each platform.
10019cf43b97SMatt Jacob  * 		These must be available independent of card NVRAM and are
10029cf43b97SMatt Jacob  *		to be used should NVRAM not be readable.
100353cff3bbSMatt Jacob  *
10042df76c16SMatt Jacob  *	DEFAULT_NODEWWN(ispsoftc_t *, chan)	Default FC Node WWN to use
10052df76c16SMatt Jacob  *	DEFAULT_PORTWWN(ispsoftc_t *, chan)	Default FC Port WWN to use
100653cff3bbSMatt Jacob  *
10072df76c16SMatt Jacob  *		These defines are hooks to allow the setting of node and
1008310d144aSGordon Bergling  *		port WWNs when NVRAM cannot be read or is to be overridden.
100953cff3bbSMatt Jacob  *
10102df76c16SMatt Jacob  *	ACTIVE_NODEWWN(ispsoftc_t *, chan)	FC Node WWN to use
10112df76c16SMatt Jacob  *	ACTIVE_PORTWWN(ispsoftc_t *, chan)	FC Port WWN to use
10122df76c16SMatt Jacob  *
10132df76c16SMatt Jacob  *		After NVRAM is read, these will be invoked to get the
10142df76c16SMatt Jacob  *		node and port WWNs that will actually be used for this
10152df76c16SMatt Jacob  *		channel.
10162df76c16SMatt Jacob  *
10174fd13c1bSMatt Jacob  *
10181dae40ebSMatt Jacob  *	ISP_IOXPUT_8(ispsoftc_t *, uint8_t srcval, uint8_t *dstptr)
10191dae40ebSMatt Jacob  *	ISP_IOXPUT_16(ispsoftc_t *, uint16_t srcval, uint16_t *dstptr)
10201dae40ebSMatt Jacob  *	ISP_IOXPUT_32(ispsoftc_t *, uint32_t srcval, uint32_t *dstptr)
10214fd13c1bSMatt Jacob  *
10221dae40ebSMatt Jacob  *	ISP_IOXGET_8(ispsoftc_t *, uint8_t *srcptr, uint8_t dstrval)
10231dae40ebSMatt Jacob  *	ISP_IOXGET_16(ispsoftc_t *, uint16_t *srcptr, uint16_t dstrval)
10241dae40ebSMatt Jacob  *	ISP_IOXGET_32(ispsoftc_t *, uint32_t *srcptr, uint32_t dstrval)
10254fd13c1bSMatt Jacob  *
10261dae40ebSMatt Jacob  *	ISP_SWIZZLE_NVRAM_WORD(ispsoftc_t *, uint16_t *)
10274607e8eeSMatt Jacob  *	ISP_SWIZZLE_NVRAM_LONG(ispsoftc_t *, uint32_t *)
10284607e8eeSMatt Jacob  *	ISP_SWAP16(ispsoftc_t *, uint16_t srcval)
10294607e8eeSMatt Jacob  *	ISP_SWAP32(ispsoftc_t *, uint32_t srcval)
103053cff3bbSMatt Jacob  */
10315d571944SMatt Jacob 
10322df76c16SMatt Jacob #ifdef	ISP_TARGET_MODE
10332df76c16SMatt Jacob /*
10342df76c16SMatt Jacob  * The functions below are for the publicly available
10352df76c16SMatt Jacob  * target mode functions that are internal to the Qlogic driver.
10362df76c16SMatt Jacob  */
10372df76c16SMatt Jacob 
10382df76c16SMatt Jacob /*
10392df76c16SMatt Jacob  * This function handles new response queue entry appropriate for target mode.
10402df76c16SMatt Jacob  */
1041b8e2395eSAlexander Motin int isp_target_notify(ispsoftc_t *, void *, uint32_t *, uint16_t);
10422df76c16SMatt Jacob 
10432df76c16SMatt Jacob /*
10442df76c16SMatt Jacob  * This function externalizes the ability to acknowledge an Immediate Notify request.
10452df76c16SMatt Jacob  */
10462df76c16SMatt Jacob int isp_notify_ack(ispsoftc_t *, void *);
10472df76c16SMatt Jacob 
10482df76c16SMatt Jacob /*
10492df76c16SMatt Jacob  * This function externalized acknowledging (success/fail) an ABTS frame
10502df76c16SMatt Jacob  */
10512df76c16SMatt Jacob int isp_acknak_abts(ispsoftc_t *, void *, int);
10522df76c16SMatt Jacob 
10532df76c16SMatt Jacob /*
10542df76c16SMatt Jacob  * General routine to send a final CTIO for a command- used mostly for
10552df76c16SMatt Jacob  * local responses.
10562df76c16SMatt Jacob  */
10572df76c16SMatt Jacob int isp_endcmd(ispsoftc_t *, ...);
10582df76c16SMatt Jacob #define	ECMD_SVALID	0x100
1059352427b3SAlexander Motin #define	ECMD_RVALID	0x200
1060352427b3SAlexander Motin #define	ECMD_TERMINATE	0x400
10612df76c16SMatt Jacob 
10622df76c16SMatt Jacob /*
10632df76c16SMatt Jacob  * Handle an asynchronous event
10642df76c16SMatt Jacob  */
10659c2e9bcfSAlexander Motin void isp_target_async(ispsoftc_t *, int, int);
10662df76c16SMatt Jacob #endif
10676054c3f6SMatt Jacob #endif	/* _ISPVAR_H */
1068