ispvar.h revision 196008
150477Speter/* $FreeBSD: head/sys/dev/isp/ispvar.h 196008 2009-08-01 01:04:26Z mjacob $ */
2139749Simp/*-
3196008Smjacob *  Copyright (c) 1997-2009 by Matthew Jacob
4167403Smjacob *  All rights reserved.
5196008Smjacob *
6167403Smjacob *  Redistribution and use in source and binary forms, with or without
7167403Smjacob *  modification, are permitted provided that the following conditions
8167403Smjacob *  are met:
9196008Smjacob *
10167403Smjacob *  1. Redistributions of source code must retain the above copyright
11167403Smjacob *     notice, this list of conditions and the following disclaimer.
12167403Smjacob *  2. Redistributions in binary form must reproduce the above copyright
13167403Smjacob *     notice, this list of conditions and the following disclaimer in the
14167403Smjacob *     documentation and/or other materials provided with the distribution.
15196008Smjacob *
16167403Smjacob *  THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17167403Smjacob *  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18167403Smjacob *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19167403Smjacob *  ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
20167403Smjacob *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21167403Smjacob *  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22167403Smjacob *  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23167403Smjacob *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24167403Smjacob *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25167403Smjacob *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26167403Smjacob *  SUCH DAMAGE.
27196008Smjacob *
28167403Smjacob */
29167403Smjacob/*
3035388Smjacob * Soft Definitions for for Qlogic ISP SCSI adapters.
3135388Smjacob */
3235388Smjacob
3335388Smjacob#ifndef	_ISPVAR_H
3435388Smjacob#define	_ISPVAR_H
3535388Smjacob
3644819Smjacob#if defined(__NetBSD__) || defined(__OpenBSD__)
37163899Smjacob#include <dev/ic/isp_stds.h>
3835388Smjacob#include <dev/ic/ispmbox.h>
3935388Smjacob#endif
4035388Smjacob#ifdef	__FreeBSD__
41163899Smjacob#include <dev/isp/isp_stds.h>
4235388Smjacob#include <dev/isp/ispmbox.h>
4335388Smjacob#endif
4435388Smjacob#ifdef	__linux__
45163899Smjacob#include "isp_stds.h"
4642131Smjacob#include "ispmbox.h"
4735388Smjacob#endif
48155704Smjacob#ifdef	__svr4__
49163899Smjacob#include "isp_stds.h"
50155704Smjacob#include "ispmbox.h"
5153487Smjacob#endif
5235388Smjacob
53196008Smjacob#define	ISP_CORE_VERSION_MAJOR	6
54163899Smjacob#define	ISP_CORE_VERSION_MINOR	0
5539235Sgibbs
5635388Smjacob/*
5743420Smjacob * Vector for bus specific code to provide specific services.
5835388Smjacob */
59155704Smjacobtypedef struct ispsoftc ispsoftc_t;
6035388Smjacobstruct ispmdvec {
61196008Smjacob	int		(*dv_rd_isr) (ispsoftc_t *, uint32_t *, uint16_t *, uint16_t *);
62163899Smjacob	uint32_t	(*dv_rd_reg) (ispsoftc_t *, int);
63163899Smjacob	void		(*dv_wr_reg) (ispsoftc_t *, int, uint32_t);
64155704Smjacob	int		(*dv_mbxdma) (ispsoftc_t *);
65196008Smjacob	int		(*dv_dmaset) (ispsoftc_t *, XS_T *, void *);
66163899Smjacob	void		(*dv_dmaclr) (ispsoftc_t *, XS_T *, uint32_t);
67155704Smjacob	void		(*dv_reset0) (ispsoftc_t *);
68155704Smjacob	void		(*dv_reset1) (ispsoftc_t *);
69155704Smjacob	void		(*dv_dregs) (ispsoftc_t *, const char *);
70167821Smjacob	const void *	dv_ispfw;	/* ptr to f/w */
71155704Smjacob	uint16_t	dv_conf1;
72155704Smjacob	uint16_t	dv_clock;	/* clock frequency */
7335388Smjacob};
7435388Smjacob
7564087Smjacob/*
7664087Smjacob * Overall parameters
7764087Smjacob */
7882689Smjacob#define	MAX_TARGETS		16
79196008Smjacob#ifndef	MAX_FC_TARG
80164272Smjacob#define	MAX_FC_TARG		512
81196008Smjacob#endif
8249909Smjacob#define	ISP_MAX_TARGETS(isp)	(IS_FC(isp)? MAX_FC_TARG : MAX_TARGETS)
8361772Smjacob#define	ISP_MAX_LUNS(isp)	(isp)->isp_maxluns
8449909Smjacob
8582689Smjacob/*
8664087Smjacob * Macros to access ISP registers through bus specific layers-
8764087Smjacob * mostly wrappers to vector through the mdvec structure.
8853487Smjacob */
8982689Smjacob#define	ISP_READ_ISR(isp, isrp, semap, mbox0p)	\
9082689Smjacob	(*(isp)->isp_mdvec->dv_rd_isr)(isp, isrp, semap, mbox0p)
9153487Smjacob
9253487Smjacob#define	ISP_READ(isp, reg)	\
9353487Smjacob	(*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg))
9453487Smjacob
9553487Smjacob#define	ISP_WRITE(isp, reg, val)	\
9653487Smjacob	(*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val))
9753487Smjacob
9853487Smjacob#define	ISP_MBOXDMASETUP(isp)	\
9953487Smjacob	(*(isp)->isp_mdvec->dv_mbxdma)((isp))
10053487Smjacob
101196008Smjacob#define	ISP_DMASETUP(isp, xs, req)	\
102196008Smjacob	(*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req))
10353487Smjacob
104155704Smjacob#define	ISP_DMAFREE(isp, xs, hndl)		\
105155704Smjacob	if ((isp)->isp_mdvec->dv_dmaclr)	\
10653487Smjacob	    (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (hndl))
10753487Smjacob
10853487Smjacob#define	ISP_RESET0(isp)	\
10953487Smjacob	if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp))
11053487Smjacob#define	ISP_RESET1(isp)	\
11153487Smjacob	if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp))
11264087Smjacob#define	ISP_DUMPREGS(isp, m)	\
11364087Smjacob	if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp),(m))
11453487Smjacob
11553487Smjacob#define	ISP_SETBITS(isp, reg, val)	\
11653487Smjacob (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val))
11753487Smjacob
11853487Smjacob#define	ISP_CLRBITS(isp, reg, val)	\
11953487Smjacob (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val))
12053487Smjacob
12164087Smjacob/*
12264087Smjacob * The MEMORYBARRIER macro is defined per platform (to provide synchronization
12364087Smjacob * on Request and Response Queues, Scratch DMA areas, and Registers)
12464087Smjacob *
12564087Smjacob * Defined Memory Barrier Synchronization Types
12664087Smjacob */
12764087Smjacob#define	SYNC_REQUEST	0	/* request queue synchronization */
12864087Smjacob#define	SYNC_RESULT	1	/* result queue synchronization */
12964087Smjacob#define	SYNC_SFORDEV	2	/* scratch, sync for ISP */
13064087Smjacob#define	SYNC_SFORCPU	3	/* scratch, sync for CPU */
13164087Smjacob#define	SYNC_REG	4	/* for registers */
132163899Smjacob#define	SYNC_ATIOQ	5	/* atio result queue (24xx) */
13364087Smjacob
13464087Smjacob/*
13564087Smjacob * Request/Response Queue defines and macros.
13664087Smjacob * The maximum is defined per platform (and can be based on board type).
13764087Smjacob */
13864087Smjacob/* This is the size of a queue entry (request and response) */
13939235Sgibbs#define	QENTRY_LEN			64
14064087Smjacob/* Both request and result queue length must be a power of two */
14164087Smjacob#define	RQUEST_QUEUE_LEN(x)		MAXISPREQUEST(x)
14293706Smjacob#ifdef	ISP_TARGET_MODE
14393706Smjacob#define	RESULT_QUEUE_LEN(x)		MAXISPREQUEST(x)
14493706Smjacob#else
14564087Smjacob#define	RESULT_QUEUE_LEN(x)		\
14664087Smjacob	(((MAXISPREQUEST(x) >> 2) < 64)? 64 : MAXISPREQUEST(x) >> 2)
14793706Smjacob#endif
148155704Smjacob#define	ISP_QUEUE_ENTRY(q, idx)		(((uint8_t *)q) + ((idx) * QENTRY_LEN))
14939235Sgibbs#define	ISP_QUEUE_SIZE(n)		((n) * QENTRY_LEN)
15039235Sgibbs#define	ISP_NXT_QENTRY(idx, qlen)	(((idx) + 1) & ((qlen)-1))
15165140Smjacob#define	ISP_QFREE(in, out, qlen)	\
15239235Sgibbs	((in == out)? (qlen - 1) : ((in > out)? \
15352347Smjacob	((qlen - 1) - (in - out)) : (out - in - 1)))
15465140Smjacob#define	ISP_QAVAIL(isp)	\
15565140Smjacob	ISP_QFREE(isp->isp_reqidx, isp->isp_reqodx, RQUEST_QUEUE_LEN(isp))
15653487Smjacob
15787635Smjacob#define	ISP_ADD_REQUEST(isp, nxti)					\
15887635Smjacob	MEMORYBARRIER(isp, SYNC_REQUEST, isp->isp_reqidx, QENTRY_LEN);	\
159163899Smjacob	ISP_WRITE(isp, isp->isp_rqstinrp, nxti);			\
16087635Smjacob	isp->isp_reqidx = nxti
16153487Smjacob
162196008Smjacob#define	ISP_SYNC_REQUEST(isp)								\
163196008Smjacob	MEMORYBARRIER(isp, SYNC_REQUEST, isp->isp_reqidx, QENTRY_LEN);			\
164196008Smjacob	isp->isp_reqidx = ISP_NXT_QENTRY(isp->isp_reqidx, RQUEST_QUEUE_LEN(isp));	\
165196008Smjacob	ISP_WRITE(isp, isp->isp_rqstinrp, isp->isp_reqidx)
166196008Smjacob
16735388Smjacob/*
16846968Smjacob * SCSI Specific Host Adapter Parameters- per bus, per target
16935388Smjacob */
17035388Smjacobtypedef struct {
171196008Smjacob	uint32_t 				: 8,
172196008Smjacob			update			: 1,
173196008Smjacob			sendmarker		: 1,
174196008Smjacob			role			: 2,
17552347Smjacob			isp_req_ack_active_neg	: 1,
17652347Smjacob			isp_data_line_active_neg: 1,
17735388Smjacob			isp_cmd_dma_burst_enable: 1,
17835388Smjacob			isp_data_dma_burst_enabl: 1,
17942461Smjacob			isp_fifo_threshold	: 3,
180163899Smjacob			isp_ptisp		: 1,
18143420Smjacob			isp_ultramode		: 1,
18235388Smjacob			isp_diffmode		: 1,
18345040Smjacob			isp_lvdmode		: 1,
18465140Smjacob			isp_fast_mttr		: 1,	/* fast sram */
18535388Smjacob			isp_initiator_id	: 4,
18652347Smjacob			isp_async_data_setup	: 4;
187155704Smjacob	uint16_t	isp_selection_timeout;
188155704Smjacob	uint16_t	isp_max_queue_depth;
189155704Smjacob	uint8_t		isp_tag_aging;
190155704Smjacob	uint8_t		isp_bus_reset_delay;
191155704Smjacob	uint8_t		isp_retry_count;
192155704Smjacob	uint8_t		isp_retry_delay;
19335388Smjacob	struct {
194196008Smjacob		uint32_t
19580582Smjacob			exc_throttle	:	8,
19646968Smjacob					:	1,
19780582Smjacob			dev_enable	:	1,	/* ignored */
19843420Smjacob			dev_update	:	1,
19943420Smjacob			dev_refresh	:	1,
20080582Smjacob			actv_offset	:	4,
20180582Smjacob			goal_offset	:	4,
20280582Smjacob			nvrm_offset	:	4;
203155704Smjacob		uint8_t		actv_period;	/* current sync period */
204155704Smjacob		uint8_t		goal_period;	/* goal sync period */
205155704Smjacob		uint8_t		nvrm_period;	/* nvram sync period */
206155704Smjacob		uint16_t	actv_flags;	/* current device flags */
207155704Smjacob		uint16_t	goal_flags;	/* goal device flags */
208155704Smjacob		uint16_t	nvrm_flags;	/* nvram device flags */
20935388Smjacob	} isp_devparam[MAX_TARGETS];
21046968Smjacob} sdparam;
21135388Smjacob
21235388Smjacob/*
21335388Smjacob * Device Flags
21435388Smjacob */
21539235Sgibbs#define	DPARM_DISC	0x8000
21639235Sgibbs#define	DPARM_PARITY	0x4000
21739235Sgibbs#define	DPARM_WIDE	0x2000
21839235Sgibbs#define	DPARM_SYNC	0x1000
21939235Sgibbs#define	DPARM_TQING	0x0800
22039235Sgibbs#define	DPARM_ARQ	0x0400
22139235Sgibbs#define	DPARM_QFRZ	0x0200
22239235Sgibbs#define	DPARM_RENEG	0x0100
22365140Smjacob#define	DPARM_NARROW	0x0080
22465140Smjacob#define	DPARM_ASYNC	0x0040
22565140Smjacob#define	DPARM_PPR	0x0020
22643793Smjacob#define	DPARM_DEFAULT	(0xFF00 & ~DPARM_QFRZ)
22739235Sgibbs#define	DPARM_SAFE_DFLT	(DPARM_DEFAULT & ~(DPARM_WIDE|DPARM_SYNC|DPARM_TQING))
22835388Smjacob
22945040Smjacob/* technically, not really correct, as they need to be rated based upon clock */
23065140Smjacob#define	ISP_80M_SYNCPARMS	0x0c09
23165140Smjacob#define	ISP_40M_SYNCPARMS	0x0c0a
23265140Smjacob#define	ISP_20M_SYNCPARMS	0x0c0c
23365140Smjacob#define	ISP_20M_SYNCPARMS_1040	0x080c
23452347Smjacob#define	ISP_10M_SYNCPARMS	0x0c19
23552347Smjacob#define	ISP_08M_SYNCPARMS	0x0c25
23652347Smjacob#define	ISP_05M_SYNCPARMS	0x0c32
23752347Smjacob#define	ISP_04M_SYNCPARMS	0x0c41
23835388Smjacob
23935388Smjacob/*
24035388Smjacob * Fibre Channel Specifics
24135388Smjacob */
242164909Smjacob/* These are for non-2K Login Firmware cards */
243163899Smjacob#define	FL_ID			0x7e	/* FL_Port Special ID */
244163899Smjacob#define	SNS_ID			0x80	/* SNS Server Special ID */
245163899Smjacob#define	NPH_MAX			0xfe
24652347Smjacob
247196008Smjacob/* Use this handle for the base for multi-id firmware SNS logins */
248196008Smjacob#define	NPH_SNS_HDLBASE		0x400
249196008Smjacob
250164909Smjacob/* These are for 2K Login Firmware cards */
251163899Smjacob#define	NPH_RESERVED		0x7F0	/* begin of reserved N-port handles */
252163899Smjacob#define	NPH_MGT_ID		0x7FA	/* Management Server Special ID */
253163899Smjacob#define	NPH_SNS_ID		0x7FC	/* SNS Server Special ID */
254196008Smjacob#define	NPH_FABRIC_CTLR		0x7FD	/* Fabric Controller (0xFFFFFD) */
255196008Smjacob#define	NPH_FL_ID		0x7FE	/* F Port Special ID (0xFFFFFE) */
256196008Smjacob#define	NPH_IP_BCST		0x7ff	/* IP Broadcast Special ID (0xFFFFFF) */
257164909Smjacob#define	NPH_MAX_2K		0x800
25893837Smjacob
259163899Smjacob/*
260164909Smjacob * "Unassigned" handle to be used internally
261164909Smjacob */
262164909Smjacob#define	NIL_HANDLE		0xffff
263164909Smjacob
264164909Smjacob/*
265163899Smjacob * Limit for devices on an arbitrated loop.
266163899Smjacob */
267163899Smjacob#define	LOCAL_LOOP_LIM		126
268163899Smjacob
269163899Smjacob/*
270196008Smjacob * Limit for (2K login) N-port handle amounts
271196008Smjacob */
272196008Smjacob#define	MAX_NPORT_HANDLE	2048
273196008Smjacob
274196008Smjacob/*
275196008Smjacob * Special Constants
276196008Smjacob */
277196008Smjacob#define	INI_NONE    		((uint64_t) 0)
278196008Smjacob#define	ISP_NOCHAN		0xff
279196008Smjacob
280196008Smjacob/*
281163899Smjacob * Special Port IDs
282163899Smjacob */
283163899Smjacob#define	MANAGEMENT_PORT_ID	0xFFFFFA
284163899Smjacob#define	SNS_PORT_ID		0xFFFFFC
285163899Smjacob#define	FABRIC_PORT_ID		0xFFFFFE
286196008Smjacob#define	PORT_ANY		0xFFFFFF
287196008Smjacob#define	PORT_NONE		0
288196008Smjacob#define	DOMAIN_CONTROLLER_BASE	0xFFFC00
289196008Smjacob#define	DOMAIN_CONTROLLER_END	0xFFFCFF
290163899Smjacob
291163899Smjacob
292163899Smjacob/*
293163899Smjacob * FC Port Database entry.
294163899Smjacob *
295163899Smjacob * It has a handle that the f/w uses to address commands to a device.
296163899Smjacob * This handle's value may be assigned by the firmware (e.g., for local loop
297163899Smjacob * devices) or by the driver (e.g., for fabric devices).
298163899Smjacob *
299163899Smjacob * It has a state. If the state if VALID, that means that we've logged into
300163899Smjacob * the device. We also *may* have a initiator map index entry. This is a value
301196008Smjacob * from 0..MAX_FC_TARG that is used to index into the isp_dev_map array. If
302163899Smjacob * the value therein is non-zero, then that value minus one is used to index
303163899Smjacob * into the Port Database to find the handle for forming commands. There is
304196008Smjacob * back-index minus one value within to Port Database entry that tells us
305196008Smjacob * which entry in isp_dev_map points to us (to avoid searching).
306163899Smjacob *
307163899Smjacob * Local loop devices the firmware automatically performs PLOGI on for us
308163899Smjacob * (which is why that handle is imposed upon us). Fabric devices we assign
309163899Smjacob * a handle to and perform the PLOGI on.
310163899Smjacob *
311163899Smjacob * When a PORT DATABASE CHANGED asynchronous event occurs, we mark all VALID
312163899Smjacob * entries as PROBATIONAL. This allows us, if policy says to, just keep track
313163899Smjacob * of devices whose handles change but are otherwise the same device (and
314163899Smjacob * thus keep 'target' constant).
315163899Smjacob *
316163899Smjacob * In any case, we search all possible local loop handles. For each one that
317163899Smjacob * has a port database entity returned, we search for any PROBATIONAL entry
318163899Smjacob * that matches it and update as appropriate. Otherwise, as a new entry, we
319163899Smjacob * find room for it in the Port Database. We *try* and use the handle as the
320163899Smjacob * index to put it into the Database, but that's just an optimization. We mark
321163899Smjacob * the entry VALID and make sure that the target index is updated and correct.
322163899Smjacob *
323163899Smjacob * When we get done searching the local loop, we then search similarily for
324163899Smjacob * a list of devices we've gotten from the fabric name controller (if we're
325163899Smjacob * on a fabric). VALID marking is also done similarily.
326163899Smjacob *
327163899Smjacob * When all of this is done, we can march through the database and clean up
328163899Smjacob * any entry that is still PROBATIONAL (these represent devices which have
329163899Smjacob * departed). Then we're done and can resume normal operations.
330163899Smjacob *
331163899Smjacob * Negative invariants that we try and test for are:
332163899Smjacob *
333163899Smjacob *  + There can never be two non-NIL entries with the same { Port, Node } WWN
334163899Smjacob *    duples.
335163899Smjacob *
336163899Smjacob *  + There can never be two non-NIL entries with the same handle.
337163899Smjacob *
338196008Smjacob *  + There can never be two non-NIL entries which have the same dev_map_idx
339163899Smjacob *    value.
340163899Smjacob */
34135388Smjacobtypedef struct {
342164272Smjacob	/*
343164272Smjacob	 * This is the handle that the firmware needs in order for us to
344164272Smjacob	 * send commands to the device. For pre-24XX cards, this would be
345164272Smjacob	 * the 'loopid'.
346164272Smjacob	 */
347163899Smjacob	uint16_t	handle;
348196008Smjacob
349164272Smjacob	/*
350196008Smjacob	 * The dev_map_idx, if nonzero, is the system virtual target ID (+1)
351196008Smjacob	 * as a cross-reference with the isp_dev_map.
352164272Smjacob	 *
353164272Smjacob	 * A device is 'autologin' if the firmware automatically logs into
354164272Smjacob	 * it (re-logins as needed). Basically, local private loop devices.
355164272Smjacob	 *
356196008Smjacob	 * The state is the current state of this entry.
357164272Smjacob	 *
358164272Smjacob	 * Role is Initiator, Target, Both
359164272Smjacob	 *
360196008Smjacob	 * Portid is obvious, as are node && port WWNs. The new_role and
361164272Smjacob	 * new_portid is for when we are pending a change.
362196008Smjacob	 *
363196008Smjacob	 * The 'target_mode' tag means that this entry arrived via a
364196008Smjacob	 * target mode command and is immune from normal flushing rules.
365196008Smjacob	 * You should also never see anything with an initiator role
366196008Smjacob	 * with this set.
367164272Smjacob	 */
368196008Smjacob	uint16_t	dev_map_idx	: 12,
369163899Smjacob			autologin	: 1,	/* F/W does PLOGI/PLOGO */
370163899Smjacob			state		: 3;
371196008Smjacob	uint32_t	reserved	: 5,
372196008Smjacob			target_mode	: 1,
373163899Smjacob			roles		: 2,
374163899Smjacob			portid		: 24;
375196008Smjacob	uint32_t
376196008Smjacob			dirty		: 1,	/* commands have been run */
377196008Smjacob			new_reserved	: 5,
378163899Smjacob			new_roles	: 2,
379163899Smjacob			new_portid	: 24;
380163899Smjacob	uint64_t	node_wwn;
381163899Smjacob	uint64_t	port_wwn;
382163899Smjacob} fcportdb_t;
383163899Smjacob
384163899Smjacob#define	FC_PORTDB_STATE_NIL		0
385163899Smjacob#define	FC_PORTDB_STATE_PROBATIONAL	1
386163899Smjacob#define	FC_PORTDB_STATE_DEAD		2
387163899Smjacob#define	FC_PORTDB_STATE_CHANGED		3
388163899Smjacob#define	FC_PORTDB_STATE_NEW		4
389163899Smjacob#define	FC_PORTDB_STATE_PENDING_VALID	5
390164272Smjacob#define	FC_PORTDB_STATE_ZOMBIE		6
391163899Smjacob#define	FC_PORTDB_STATE_VALID		7
392163899Smjacob
393163899Smjacob/*
394163899Smjacob * FC card specific information
395196008Smjacob *
396196008Smjacob * This structure is replicated across multiple channels for multi-id
397196008Smjacob * capapble chipsets, with some entities different on a per-channel basis.
398163899Smjacob */
399196008Smjacob
400163899Smjacobtypedef struct {
401196008Smjacob	uint32_t
402196008Smjacob				link_active	: 1,
403196008Smjacob				npiv_fabric	: 1,
404196008Smjacob				inorder		: 1,
405196008Smjacob				sendmarker	: 1,
406196008Smjacob				role		: 2,
407196008Smjacob				isp_gbspeed	: 4,
40877776Smjacob				isp_loopstate	: 4,	/* Current Loop State */
409160080Smjacob				isp_fwstate	: 4,	/* ISP F/W state */
410196008Smjacob				isp_topo	: 3,	/* Connection Type */
411163899Smjacob				loop_seen_once	: 1;
412196008Smjacob
413155704Smjacob	uint32_t				: 8,
414154704Smjacob				isp_portid	: 24;	/* S_ID */
415196008Smjacob
416196008Smjacob
417155704Smjacob	uint16_t		isp_fwoptions;
418160080Smjacob	uint16_t		isp_xfwoptions;
419160080Smjacob	uint16_t		isp_zfwoptions;
420196008Smjacob	uint16_t		isp_loopid;		/* hard loop id */
421196008Smjacob	uint16_t		isp_sns_hdl;		/* N-port handle for SNS */
422196008Smjacob	uint16_t		isp_lasthdl;		/* only valid for channel 0 */
423196008Smjacob	uint16_t		isp_maxalloc;
424155704Smjacob	uint8_t			isp_retry_delay;
425155704Smjacob	uint8_t			isp_retry_count;
426196008Smjacob
427196008Smjacob	/*
428196008Smjacob	 * Current active WWNN/WWPN
429196008Smjacob	 */
430196008Smjacob	uint64_t		isp_wwnn;
431196008Smjacob	uint64_t		isp_wwpn;
432196008Smjacob
433196008Smjacob	/*
434196008Smjacob	 * NVRAM WWNN/WWPN
435196008Smjacob	 */
436166120Smjacob	uint64_t		isp_wwnn_nvram;
437166120Smjacob	uint64_t		isp_wwpn_nvram;
438164272Smjacob
439164272Smjacob	/*
440164272Smjacob	 * Our Port Data Base
441164272Smjacob	 */
442163899Smjacob	fcportdb_t		portdb[MAX_FC_TARG];
443164272Smjacob
444164272Smjacob	/*
445164272Smjacob	 * This maps system virtual 'target' id to a portdb entry.
446164272Smjacob	 *
447164272Smjacob	 * The mapping function is to take any non-zero entry and
448164272Smjacob	 * subtract one to get the portdb index. This means that
449164272Smjacob	 * entries which are zero are unmapped (i.e., don't exist).
450164272Smjacob	 */
451196008Smjacob	uint16_t		isp_dev_map[MAX_FC_TARG];
452164272Smjacob
453196008Smjacob#ifdef	ISP_TARGET_MODE
45435388Smjacob	/*
455196008Smjacob	 * This maps N-Port Handle to portdb entry so we
456196008Smjacob	 * don't have to search for every incoming command.
457196008Smjacob	 *
458196008Smjacob	 * The mapping function is to take any non-zero entry and
459196008Smjacob	 * subtract one to get the portdb index. This means that
460196008Smjacob	 * entries which are zero are unmapped (i.e., don't exist).
461196008Smjacob	 */
462196008Smjacob	uint16_t		isp_tgt_map[MAX_NPORT_HANDLE];
463196008Smjacob#endif
464196008Smjacob
465196008Smjacob	/*
46635388Smjacob	 * Scratch DMA mapped in area to fetch Port Database stuff, etc.
46735388Smjacob	 */
468155704Smjacob	void *			isp_scratch;
469155704Smjacob	XS_DMA_ADDR_T		isp_scdma;
47035388Smjacob} fcparam;
47135388Smjacob
47248484Smjacob#define	FW_CONFIG_WAIT		0
47348484Smjacob#define	FW_WAIT_AL_PA		1
47448484Smjacob#define	FW_WAIT_LOGIN		2
47548484Smjacob#define	FW_READY		3
47648484Smjacob#define	FW_LOSS_OF_SYNC		4
47748484Smjacob#define	FW_ERROR		5
47848484Smjacob#define	FW_REINIT		6
47948484Smjacob#define	FW_NON_PART		7
48035388Smjacob
48148484Smjacob#define	LOOP_NIL		0
48248484Smjacob#define	LOOP_LIP_RCVD		1
48348484Smjacob#define	LOOP_PDB_RCVD		2
484163899Smjacob#define	LOOP_SCANNING_LOOP	3
485163899Smjacob#define	LOOP_LSCAN_DONE		4
486163899Smjacob#define	LOOP_SCANNING_FABRIC	5
487163899Smjacob#define	LOOP_FSCAN_DONE		6
48877776Smjacob#define	LOOP_SYNCING_PDB	7
48977776Smjacob#define	LOOP_READY		8
49035388Smjacob
49159454Smjacob#define	TOPO_NL_PORT		0
49259454Smjacob#define	TOPO_FL_PORT		1
49359454Smjacob#define	TOPO_N_PORT		2
49459454Smjacob#define	TOPO_F_PORT		3
49559454Smjacob#define	TOPO_PTP_STUB		4
49659454Smjacob
49742131Smjacob/*
49835388Smjacob * Soft Structure per host adapter
49935388Smjacob */
500155704Smjacobstruct ispsoftc {
50135388Smjacob	/*
50235388Smjacob	 * Platform (OS) specific data
50335388Smjacob	 */
50435388Smjacob	struct isposinfo	isp_osinfo;
50535388Smjacob
50635388Smjacob	/*
50753487Smjacob	 * Pointer to bus specific functions and data
50835388Smjacob	 */
50935388Smjacob	struct ispmdvec *	isp_mdvec;
51035388Smjacob
51135388Smjacob	/*
51253487Smjacob	 * (Mostly) nonvolatile state. Board specific parameters
51353487Smjacob	 * may contain some volatile state (e.g., current loop state).
51435388Smjacob	 */
51535388Smjacob
51653487Smjacob	void * 			isp_param;	/* type specific */
517155704Smjacob	uint16_t		isp_fwrev[3];	/* Loaded F/W revision */
518155704Smjacob	uint16_t		isp_maxcmds;	/* max possible I/O cmds */
519155704Smjacob	uint8_t			isp_type;	/* HBA Chip Type */
520155704Smjacob	uint8_t			isp_revision;	/* HBA Chip H/W Revision */
521155704Smjacob	uint32_t		isp_maxluns;	/* maximum luns supported */
52235388Smjacob
523155704Smjacob	uint32_t		isp_clock	: 8,	/* input clock */
52490224Smjacob						: 4,
525163899Smjacob				isp_port	: 1,	/* 23XX/24XX only */
52687635Smjacob				isp_open	: 1,	/* opened (ioctl) */
52753487Smjacob				isp_bustype	: 1,	/* SBus or PCI */
52865140Smjacob				isp_loaded_fw	: 1,	/* loaded firmware */
529196008Smjacob				isp_dblev	: 16;	/* debug log mask */
53071079Smjacob
531196008Smjacob	uint16_t		isp_fwattr;	/* firmware attributes */
532196008Smjacob	uint16_t		isp_nchan;	/* number of channels */
53371079Smjacob
534196008Smjacob	uint32_t		isp_confopts;	/* config options */
535196008Smjacob
536163899Smjacob	uint32_t		isp_rqstinrp;	/* register for REQINP */
537163899Smjacob	uint32_t		isp_rqstoutrp;	/* register for REQOUTP */
538163899Smjacob	uint32_t		isp_respinrp;	/* register for RESINP */
539163899Smjacob	uint32_t		isp_respoutrp;	/* register for RESOUTP */
54082689Smjacob
54169522Smjacob	/*
54269522Smjacob	 * Instrumentation
54369522Smjacob	 */
544155704Smjacob	uint64_t		isp_intcnt;		/* total int count */
545155704Smjacob	uint64_t		isp_intbogus;		/* spurious int count */
546155704Smjacob	uint64_t		isp_intmboxc;		/* mbox completions */
547155704Smjacob	uint64_t		isp_intoasync;		/* other async */
548155704Smjacob	uint64_t		isp_rsltccmplt;		/* CMDs on result q */
549155704Smjacob	uint64_t		isp_fphccmplt;		/* CMDs via fastpost */
550155704Smjacob	uint16_t		isp_rscchiwater;
551155704Smjacob	uint16_t		isp_fpcchiwater;
552196008Smjacob	NANOTIME_T		isp_init_time;		/* time were last initialized */
55339235Sgibbs
55435388Smjacob	/*
55539235Sgibbs	 * Volatile state
55635388Smjacob	 */
55735388Smjacob
558160080Smjacob	volatile uint32_t	:	8,
559196008Smjacob				:	2,
560196008Smjacob		isp_dead	:	1,
561196008Smjacob				:	1,
56287635Smjacob		isp_mboxbsy	:	1,	/* mailbox command active */
56339235Sgibbs		isp_state	:	3,
56452347Smjacob		isp_nactive	:	16;	/* how many commands active */
565163899Smjacob	volatile uint32_t	isp_reqodx;	/* index of last ISP pickup */
566163899Smjacob	volatile uint32_t	isp_reqidx;	/* index of next request */
567163899Smjacob	volatile uint32_t	isp_residx;	/* index of next result */
568163899Smjacob	volatile uint32_t	isp_resodx;	/* index of next result */
569163899Smjacob	volatile uint32_t	isp_lasthdls;	/* last handle seed */
570163899Smjacob	volatile uint32_t	isp_obits;	/* mailbox command output */
571196008Smjacob	volatile uint32_t	isp_serno;	/* rolling serial number */
572155704Smjacob	volatile uint16_t	isp_mboxtmp[MAILBOX_STORAGE];
573155704Smjacob	volatile uint16_t	isp_lastmbxcmd;	/* last mbox command sent */
574155704Smjacob	volatile uint16_t	isp_mbxwrk0;
575155704Smjacob	volatile uint16_t	isp_mbxwrk1;
576155704Smjacob	volatile uint16_t	isp_mbxwrk2;
577160080Smjacob	volatile uint16_t	isp_mbxwrk8;
57890224Smjacob	void *			isp_mbxworkp;
57935388Smjacob
58035388Smjacob	/*
58153487Smjacob	 * Active commands are stored here, indexed by handle functions.
58235388Smjacob	 */
58364087Smjacob	XS_T **isp_xflist;
58435388Smjacob
585129643Snjl#ifdef	ISP_TARGET_MODE
58635388Smjacob	/*
587196008Smjacob	 * Active target commands are stored here, indexed by handle functions.
588129643Snjl	 */
589129643Snjl	void **isp_tgtlist;
590129643Snjl#endif
591129643Snjl
592129643Snjl	/*
593120018Smjacob	 * request/result queue pointers and DMA handles for them.
59435388Smjacob	 */
595155704Smjacob	void *			isp_rquest;
596155704Smjacob	void *			isp_result;
597155704Smjacob	XS_DMA_ADDR_T		isp_rquest_dma;
598155704Smjacob	XS_DMA_ADDR_T		isp_result_dma;
599163899Smjacob#ifdef	ISP_TARGET_MODE
600163899Smjacob	/* for 24XX only */
601163899Smjacob	void *			isp_atioq;
602163899Smjacob	XS_DMA_ADDR_T		isp_atioq_dma;
603163899Smjacob#endif
604155704Smjacob};
60535388Smjacob
606196008Smjacob#define	SDPARAM(isp, chan)	(&((sdparam *)(isp)->isp_param)[(chan)])
607196008Smjacob#define	FCPARAM(isp, chan)	(&((fcparam *)(isp)->isp_param)[(chan)])
60849909Smjacob
609196008Smjacob#define	ISP_SET_SENDMARKER(isp, chan, val)	\
610196008Smjacob    if (IS_FC(isp)) {				\
611196008Smjacob	FCPARAM(isp, chan)->sendmarker = val;	\
612196008Smjacob    } else {					\
613196008Smjacob	SDPARAM(isp, chan)->sendmarker = val;	\
614196008Smjacob    }
615196008Smjacob
616196008Smjacob#define	ISP_TST_SENDMARKER(isp, chan)		\
617196008Smjacob    (IS_FC(isp)?				\
618196008Smjacob	FCPARAM(isp, chan)->sendmarker != 0 :	\
619196008Smjacob	SDPARAM(isp, chan)->sendmarker != 0)
620196008Smjacob
62135388Smjacob/*
62264087Smjacob * ISP Driver Run States
62335388Smjacob */
62435388Smjacob#define	ISP_NILSTATE	0
625160080Smjacob#define	ISP_CRASHED	1
626160080Smjacob#define	ISP_RESETSTATE	2
627160080Smjacob#define	ISP_INITSTATE	3
628160080Smjacob#define	ISP_RUNSTATE	4
62935388Smjacob
63035388Smjacob/*
63135388Smjacob * ISP Configuration Options
63235388Smjacob */
63335388Smjacob#define	ISP_CFG_NORELOAD	0x80	/* don't download f/w */
63443793Smjacob#define	ISP_CFG_NONVRAM		0x40	/* ignore NVRAM */
63584241Smjacob#define	ISP_CFG_TWOGB		0x20	/* force 2GB connection (23XX only) */
63684241Smjacob#define	ISP_CFG_ONEGB		0x10	/* force 1GB connection (23XX only) */
63753487Smjacob#define	ISP_CFG_FULL_DUPLEX	0x01	/* Full Duplex (Fibre Channel only) */
63869522Smjacob#define	ISP_CFG_PORT_PREF	0x0C	/* Mask for Port Prefs (2200 only) */
63969522Smjacob#define	ISP_CFG_LPORT		0x00	/* prefer {N/F}L-Port connection */
64069522Smjacob#define	ISP_CFG_NPORT		0x04	/* prefer {N/F}-Port connection */
64169522Smjacob#define	ISP_CFG_NPORT_ONLY	0x08	/* insist on {N/F}-Port connection */
64269522Smjacob#define	ISP_CFG_LPORT_ONLY	0x0C	/* insist on {N/F}L-Port connection */
64398281Smjacob#define	ISP_CFG_OWNFSZ		0x400	/* override NVRAM frame size */
64498281Smjacob#define	ISP_CFG_OWNLOOPID	0x800	/* override NVRAM loopid */
64598281Smjacob#define	ISP_CFG_OWNEXCTHROTTLE	0x1000	/* override NVRAM execution throttle */
646163899Smjacob#define	ISP_CFG_FOURGB		0x2000	/* force 4GB connection (24XX only) */
64735388Smjacob
64864087Smjacob/*
649196008Smjacob * For each channel, the outer layers should know what role that channel
650196008Smjacob * will take: ISP_ROLE_NONE, ISP_ROLE_INITIATOR, ISP_ROLE_TARGET,
651196008Smjacob * ISP_ROLE_BOTH.
65271079Smjacob *
65371079Smjacob * If you set ISP_ROLE_NONE, the cards will be reset, new firmware loaded,
65471079Smjacob * NVRAM read, and defaults set, but any further initialization (e.g.
65571079Smjacob * INITIALIZE CONTROL BLOCK commands for 2X00 cards) won't be done.
65671079Smjacob *
65771079Smjacob * If INITIATOR MODE isn't set, attempts to run commands will be stopped
658196008Smjacob * at isp_start and completed with the equivalent of SELECTION TIMEOUT.
65971079Smjacob *
66071079Smjacob * If TARGET MODE is set, it doesn't mean that the rest of target mode support
66171079Smjacob * needs to be enabled, or will even work. What happens with the 2X00 cards
66271079Smjacob * here is that if you have enabled it with TARGET MODE as part of the ICB
66371079Smjacob * options, but you haven't given the f/w any ram resources for ATIOs or
66471079Smjacob * Immediate Notifies, the f/w just handles what it can and you never see
66571079Smjacob * anything. Basically, it sends a single byte of data (the first byte,
66671079Smjacob * which you can set as part of the INITIALIZE CONTROL BLOCK command) for
66771079Smjacob * INQUIRY, and sends back QUEUE FULL status for any other command.
66879235Smjacob *
66971079Smjacob */
67071079Smjacob#define	ISP_ROLE_NONE		0x0
671125544Smjacob#define	ISP_ROLE_TARGET		0x1
672125544Smjacob#define	ISP_ROLE_INITIATOR	0x2
67371079Smjacob#define	ISP_ROLE_BOTH		(ISP_ROLE_TARGET|ISP_ROLE_INITIATOR)
67471079Smjacob#define	ISP_ROLE_EITHER		ISP_ROLE_BOTH
67571079Smjacob#ifndef	ISP_DEFAULT_ROLES
67671079Smjacob#define	ISP_DEFAULT_ROLES	ISP_ROLE_INITIATOR
67771079Smjacob#endif
67871079Smjacob
67971079Smjacob
68071079Smjacob/*
68164087Smjacob * Firmware related defines
68264087Smjacob */
68371079Smjacob#define	ISP_CODE_ORG			0x1000	/* default f/w code start */
68482689Smjacob#define	ISP_CODE_ORG_2300		0x0800	/* ..except for 2300s */
685163899Smjacob#define	ISP_CODE_ORG_2400		0x100000 /* ..and 2400s */
68645282Smjacob#define	ISP_FW_REV(maj, min, mic)	((maj << 24) | (min << 16) | mic)
68782841Smjacob#define	ISP_FW_MAJOR(code)		((code >> 24) & 0xff)
68882841Smjacob#define	ISP_FW_MINOR(code)		((code >> 16) & 0xff)
68982841Smjacob#define	ISP_FW_MICRO(code)		((code >>  8) & 0xff)
69071079Smjacob#define	ISP_FW_REVX(xp)			((xp[0]<<24) | (xp[1] << 16) | xp[2])
69182841Smjacob#define	ISP_FW_MAJORX(xp)		(xp[0])
69282841Smjacob#define	ISP_FW_MINORX(xp)		(xp[1])
69382841Smjacob#define	ISP_FW_MICROX(xp)		(xp[2])
694102012Smjacob#define	ISP_FW_NEWER_THAN(i, major, minor, micro)		\
695102012Smjacob (ISP_FW_REVX((i)->isp_fwrev) > ISP_FW_REV(major, minor, micro))
696163899Smjacob#define	ISP_FW_OLDER_THAN(i, major, minor, micro)		\
697163899Smjacob (ISP_FW_REVX((i)->isp_fwrev) < ISP_FW_REV(major, minor, micro))
69839235Sgibbs
69935388Smjacob/*
70039235Sgibbs * Bus (implementation) types
70135388Smjacob */
70239235Sgibbs#define	ISP_BT_PCI		0	/* PCI Implementations */
70339235Sgibbs#define	ISP_BT_SBUS		1	/* SBus Implementations */
70439235Sgibbs
70539235Sgibbs/*
70687635Smjacob * If we have not otherwise defined SBus support away make sure
70787635Smjacob * it is defined here such that the code is included as default
70887635Smjacob */
70987635Smjacob#ifndef	ISP_SBUS_SUPPORTED
71087635Smjacob#define	ISP_SBUS_SUPPORTED	1
71187635Smjacob#endif
71287635Smjacob
71387635Smjacob/*
71439235Sgibbs * Chip Types
71539235Sgibbs */
71635388Smjacob#define	ISP_HA_SCSI		0xf
71739235Sgibbs#define	ISP_HA_SCSI_UNKNOWN	0x1
71839235Sgibbs#define	ISP_HA_SCSI_1020	0x2
71939235Sgibbs#define	ISP_HA_SCSI_1020A	0x3
72039235Sgibbs#define	ISP_HA_SCSI_1040	0x4
72139235Sgibbs#define	ISP_HA_SCSI_1040A	0x5
72239235Sgibbs#define	ISP_HA_SCSI_1040B	0x6
72345282Smjacob#define	ISP_HA_SCSI_1040C	0x7
72454671Smjacob#define	ISP_HA_SCSI_1240	0x8
72554671Smjacob#define	ISP_HA_SCSI_1080	0x9
72654671Smjacob#define	ISP_HA_SCSI_1280	0xa
727104916Smjacob#define	ISP_HA_SCSI_10160	0xb
728104916Smjacob#define	ISP_HA_SCSI_12160	0xc
72935388Smjacob#define	ISP_HA_FC		0xf0
73035388Smjacob#define	ISP_HA_FC_2100		0x10
73148484Smjacob#define	ISP_HA_FC_2200		0x20
73277365Smjacob#define	ISP_HA_FC_2300		0x30
73388855Smjacob#define	ISP_HA_FC_2312		0x40
734154704Smjacob#define	ISP_HA_FC_2322		0x50
735154704Smjacob#define	ISP_HA_FC_2400		0x60
736196008Smjacob#define	ISP_HA_FC_2500		0x70
73735388Smjacob
73844819Smjacob#define	IS_SCSI(isp)	(isp->isp_type & ISP_HA_SCSI)
739196008Smjacob#define	IS_1020(isp)	(isp->isp_type < ISP_HA_SCSI_1240)
74054671Smjacob#define	IS_1240(isp)	(isp->isp_type == ISP_HA_SCSI_1240)
74144819Smjacob#define	IS_1080(isp)	(isp->isp_type == ISP_HA_SCSI_1080)
74254671Smjacob#define	IS_1280(isp)	(isp->isp_type == ISP_HA_SCSI_1280)
743104916Smjacob#define	IS_10160(isp)	(isp->isp_type == ISP_HA_SCSI_10160)
74457145Smjacob#define	IS_12160(isp)	(isp->isp_type == ISP_HA_SCSI_12160)
74557145Smjacob
74657145Smjacob#define	IS_12X0(isp)	(IS_1240(isp) || IS_1280(isp))
747104916Smjacob#define	IS_1X160(isp)	(IS_10160(isp) || IS_12160(isp))
74857145Smjacob#define	IS_DUALBUS(isp)	(IS_12X0(isp) || IS_12160(isp))
749104916Smjacob#define	IS_ULTRA2(isp)	(IS_1080(isp) || IS_1280(isp) || IS_1X160(isp))
750104916Smjacob#define	IS_ULTRA3(isp)	(IS_1X160(isp))
75157145Smjacob
75277365Smjacob#define	IS_FC(isp)	((isp)->isp_type & ISP_HA_FC)
75377365Smjacob#define	IS_2100(isp)	((isp)->isp_type == ISP_HA_FC_2100)
75477365Smjacob#define	IS_2200(isp)	((isp)->isp_type == ISP_HA_FC_2200)
755163899Smjacob#define	IS_23XX(isp)	((isp)->isp_type >= ISP_HA_FC_2300 && \
756163899Smjacob				(isp)->isp_type < ISP_HA_FC_2400)
75788855Smjacob#define	IS_2300(isp)	((isp)->isp_type == ISP_HA_FC_2300)
75888855Smjacob#define	IS_2312(isp)	((isp)->isp_type == ISP_HA_FC_2312)
759154704Smjacob#define	IS_2322(isp)	((isp)->isp_type == ISP_HA_FC_2322)
760154704Smjacob#define	IS_24XX(isp)	((isp)->isp_type >= ISP_HA_FC_2400)
761196008Smjacob#define	IS_25XX(isp)	((isp)->isp_type >= ISP_HA_FC_2500)
76244819Smjacob
76364087Smjacob/*
764155704Smjacob * DMA related macros
76564087Smjacob */
766163899Smjacob#define	DMA_WD3(x)	(((uint16_t)(((uint64_t)x) >> 48)) & 0xffff)
767163899Smjacob#define	DMA_WD2(x)	(((uint16_t)(((uint64_t)x) >> 32)) & 0xffff)
768163899Smjacob#define	DMA_WD1(x)	((uint16_t)((x) >> 16) & 0xffff)
769163899Smjacob#define	DMA_WD0(x)	((uint16_t)((x) & 0xffff))
77057145Smjacob
771155704Smjacob#define	DMA_LO32(x)	((uint32_t) (x))
772155704Smjacob#define	DMA_HI32(x)	((uint32_t)(((uint64_t)x) >> 32))
773155704Smjacob
77435388Smjacob/*
77564087Smjacob * Core System Function Prototypes
77635388Smjacob */
77735388Smjacob
77835388Smjacob/*
779196008Smjacob * Reset Hardware. Totally. Assumes that you'll follow this with a call to isp_init.
78035388Smjacob */
781196008Smjacobvoid isp_reset(ispsoftc_t *, int);
78235388Smjacob
78335388Smjacob/*
78435388Smjacob * Initialize Hardware to known state
78535388Smjacob */
786155704Smjacobvoid isp_init(ispsoftc_t *);
78735388Smjacob
78835388Smjacob/*
78939235Sgibbs * Reset the ISP and call completion for any orphaned commands.
79039235Sgibbs */
791196008Smjacobvoid isp_reinit(ispsoftc_t *, int);
79239235Sgibbs
79339235Sgibbs/*
79482689Smjacob * Internal Interrupt Service Routine
79582689Smjacob *
79682689Smjacob * The outer layers do the spade work to get the appropriate status register,
79782689Smjacob * semaphore register and first mailbox register (if appropriate). This also
79882689Smjacob * means that most spurious/bogus interrupts not for us can be filtered first.
79935388Smjacob */
800163899Smjacobvoid isp_intr(ispsoftc_t *, uint32_t, uint16_t, uint16_t);
80135388Smjacob
80282689Smjacob
80335388Smjacob/*
80464087Smjacob * Command Entry Point- Platform Dependent layers call into this
80535388Smjacob */
80674229Smjacobint isp_start(XS_T *);
807155704Smjacob
80864087Smjacob/* these values are what isp_start returns */
80964087Smjacob#define	CMD_COMPLETE	101	/* command completed */
81064087Smjacob#define	CMD_EAGAIN	102	/* busy- maybe retry later */
81164087Smjacob#define	CMD_QUEUED	103	/* command has been queued for execution */
81264087Smjacob#define	CMD_RQLATER 	104	/* requeue this command later */
81335388Smjacob
81439235Sgibbs/*
81564087Smjacob * Command Completion Point- Core layers call out from this with completed cmds
81664087Smjacob */
81774229Smjacobvoid isp_done(XS_T *);
81864087Smjacob
81964087Smjacob/*
82043420Smjacob * Platform Dependent to External to Internal Control Function
82139235Sgibbs *
82272355Smjacob * Assumes locks are held on entry. You should note that with many of
823196008Smjacob * these commands locks may be released while this function is called.
82439235Sgibbs *
825196008Smjacob * ... ISPCTL_RESET_BUS, int channel);
826196008Smjacob *        Reset BUS on this channel
827196008Smjacob * ... ISPCTL_RESET_DEV, int channel, int target);
828196008Smjacob *        Reset Device on this channel at this target.
829196008Smjacob * ... ISPCTL_ABORT_CMD, XS_T *xs);
830196008Smjacob *        Abort active transaction described by xs.
831196008Smjacob * ... IPCTL_UPDATE_PARAMS);
832196008Smjacob *        Update any operating parameters (speed, etc.)
833196008Smjacob * ... ISPCTL_FCLINK_TEST, int channel);
834196008Smjacob *        Test FC link status on this channel
835196008Smjacob * ... ISPCTL_SCAN_FABRIC, int channel);
836196008Smjacob *        Scan fabric on this channel
837196008Smjacob * ... ISPCTL_SCAN_LOOP, int channel);
838196008Smjacob *        Scan local loop on this channel
839196008Smjacob * ... ISPCTL_PDB_SYNC, int channel);
840196008Smjacob *        Synchronize port database on this channel
841196008Smjacob * ... ISPCTL_SEND_LIP, int channel);
842196008Smjacob *        Send a LIP on this channel
843196008Smjacob * ... ISPCTL_GET_NAMES, int channel, int np, uint64_t *wwnn, uint64_t *wwpn)
844196008Smjacob *        Get a WWNN/WWPN for this N-port handle on this channel
845196008Smjacob * ... ISPCTL_RUN_MBOXCMD, mbreg_t *mbp)
846196008Smjacob *        Run this mailbox command
847196008Smjacob * ... ISPCTL_GET_PDB, int channel, int nphandle, isp_pdb_t *pdb)
848196008Smjacob *        Get PDB on this channel for this N-port handle
849196008Smjacob * ... ISPCTL_PLOGX, isp_plcmd_t *)
850196008Smjacob *        Performa a port login/logout
85172355Smjacob *
85272355Smjacob * ISPCTL_PDB_SYNC is somewhat misnamed. It actually is the final step, in
85372355Smjacob * order, of ISPCTL_FCLINK_TEST, ISPCTL_SCAN_FABRIC, and ISPCTL_SCAN_LOOP.
85472355Smjacob * The main purpose of ISPCTL_PDB_SYNC is to complete management of logging
85572355Smjacob * and logging out of fabric devices (if one is on a fabric) and then marking
85672355Smjacob * the 'loop state' as being ready to now be used for sending commands to
85772355Smjacob * devices. Originally fabric name server and local loop scanning were
85881794Smjacob * part of this function. It's now been separated to allow for finer control.
85939235Sgibbs */
86039235Sgibbstypedef enum {
861196008Smjacob	ISPCTL_RESET_BUS,
862196008Smjacob	ISPCTL_RESET_DEV,
863196008Smjacob	ISPCTL_ABORT_CMD,
864196008Smjacob	ISPCTL_UPDATE_PARAMS,
865196008Smjacob	ISPCTL_FCLINK_TEST,
866196008Smjacob	ISPCTL_SCAN_FABRIC,
867196008Smjacob	ISPCTL_SCAN_LOOP,
868196008Smjacob	ISPCTL_PDB_SYNC,
869196008Smjacob	ISPCTL_SEND_LIP,
870196008Smjacob	ISPCTL_GET_NAMES,
871196008Smjacob	ISPCTL_RUN_MBOXCMD,
872196008Smjacob	ISPCTL_GET_PDB,
873196008Smjacob	ISPCTL_PLOGX
87439235Sgibbs} ispctl_t;
875196008Smjacobint isp_control(ispsoftc_t *, ispctl_t, ...);
87639235Sgibbs
87739235Sgibbs/*
87843420Smjacob * Platform Dependent to Internal to External Control Function
87943420Smjacob */
88043420Smjacob
88143420Smjacobtypedef enum {
882196008Smjacob	ISPASYNC_NEW_TGT_PARAMS,	/* SPI New Target Parameters */
883196008Smjacob	ISPASYNC_BUS_RESET,		/* All Bus Was Reset */
88448484Smjacob	ISPASYNC_LOOP_DOWN,		/* FC Loop Down */
88548484Smjacob	ISPASYNC_LOOP_UP,		/* FC Loop Up */
886196008Smjacob	ISPASYNC_LIP,			/* FC LIP Received */
887196008Smjacob	ISPASYNC_LOOP_RESET,		/* FC Loop Reset Received */
88872355Smjacob	ISPASYNC_CHANGE_NOTIFY,		/* FC Change Notification */
889196008Smjacob	ISPASYNC_DEV_ARRIVED,		/* FC Device Arrived */
890196008Smjacob	ISPASYNC_DEV_CHANGED,		/* FC Device Changed */
891196008Smjacob	ISPASYNC_DEV_STAYED,		/* FC Device Stayed */
892196008Smjacob	ISPASYNC_DEV_GONE,		/* FC Device Departure */
893196008Smjacob	ISPASYNC_TARGET_NOTIFY,		/* All target async notification */
894196008Smjacob	ISPASYNC_TARGET_ACTION,		/* All target action requested */
895196008Smjacob	ISPASYNC_FW_CRASH,		/* All Firmware has crashed */
896196008Smjacob	ISPASYNC_FW_RESTARTED		/* All Firmware has been restarted */
89743420Smjacob} ispasync_t;
898196008Smjacobvoid isp_async(ispsoftc_t *, ispasync_t, ...);
89943420Smjacob
900196008Smjacob#define	ISPASYNC_CHANGE_PDB	0
901196008Smjacob#define	ISPASYNC_CHANGE_SNS	1
902196008Smjacob#define	ISPASYNC_CHANGE_OTHER	2
90372355Smjacob
90443420Smjacob/*
90564087Smjacob * Platform Dependent Error and Debug Printout
906146073Smjacob *
907146073Smjacob * Generally this is:
908146073Smjacob *
909155704Smjacob *    void isp_prt(ispsoftc_t *, int level, const char *, ...)
910146073Smjacob *
911146073Smjacob * but due to compiler differences on different platforms this won't be
912146073Smjacob * formally done here. Instead, it goes in each platform definition file.
91339235Sgibbs */
91470490Smjacob
91564087Smjacob#define	ISP_LOGALL	0x0	/* log always */
91664087Smjacob#define	ISP_LOGCONFIG	0x1	/* log configuration messages */
91764087Smjacob#define	ISP_LOGINFO	0x2	/* log informational messages */
91864087Smjacob#define	ISP_LOGWARN	0x4	/* log warning messages */
91964087Smjacob#define	ISP_LOGERR	0x8	/* log error messages */
92064087Smjacob#define	ISP_LOGDEBUG0	0x10	/* log simple debug messages */
92164087Smjacob#define	ISP_LOGDEBUG1	0x20	/* log intermediate debug messages */
92264087Smjacob#define	ISP_LOGDEBUG2	0x40	/* log most debug messages */
92379235Smjacob#define	ISP_LOGDEBUG3	0x80	/* log high frequency debug messages */
924164272Smjacob#define	ISP_LOGSANCFG	0x100	/* log SAN configuration */
925196008Smjacob#define	ISP_LOGTINFO	0x1000	/* log informational messages (target mode) */
926196008Smjacob#define	ISP_LOGTDEBUG0	0x2000	/* log simple debug messages (target mode) */
927196008Smjacob#define	ISP_LOGTDEBUG1	0x4000	/* log intermediate debug messages (target) */
928196008Smjacob#define	ISP_LOGTDEBUG2	0x8000	/* log all debug messages (target) */
92939235Sgibbs
93064087Smjacob/*
93164087Smjacob * Each Platform provides it's own isposinfo substructure of the ispsoftc
93264087Smjacob * defined above.
93364087Smjacob *
93464087Smjacob * Each platform must also provide the following macros/defines:
93564087Smjacob *
93664087Smjacob *
937196008Smjacob *	ISP_FC_SCRLEN				FC scratch area DMA length
93864087Smjacob *
939196008Smjacob *	ISP_MEMZERO(dst, src)			platform zeroing function
940196008Smjacob *	ISP_MEMCPY(dst, src, count)		platform copying function
941196008Smjacob *	ISP_SNPRINTF(buf, bufsize, fmt, ...)	snprintf
942196008Smjacob *	ISP_DELAY(usecs)			microsecond spindelay function
943196008Smjacob *	ISP_SLEEP(isp, usecs)			microsecond sleep function
94464087Smjacob *
945196008Smjacob *	ISP_INLINE				___inline or not- depending on how
946196008Smjacob *						good your debugger is
947196008Smjacob *
94864087Smjacob *	NANOTIME_T				nanosecond time type
94964087Smjacob *
95064087Smjacob *	GET_NANOTIME(NANOTIME_T *)		get current nanotime.
95164087Smjacob *
952155704Smjacob *	GET_NANOSEC(NANOTIME_T *)		get uint64_t from NANOTIME_T
95364087Smjacob *
95464087Smjacob *	NANOTIME_SUB(NANOTIME_T *, NANOTIME_T *)
95564087Smjacob *						subtract two NANOTIME_T values
95664087Smjacob *
957196008Smjacob *	MAXISPREQUEST(ispsoftc_t *)		maximum request queue size
95864087Smjacob *						for this particular board type
95964087Smjacob *
960155704Smjacob *	MEMORYBARRIER(ispsoftc_t *, barrier_type, offset, size)
96164087Smjacob *
96264087Smjacob *		Function/Macro the provides memory synchronization on
96364087Smjacob *		various objects so that the ISP's and the system's view
96464087Smjacob *		of the same object is consistent.
96564087Smjacob *
966155704Smjacob *	MBOX_ACQUIRE(ispsoftc_t *)		acquire lock on mailbox regs
967163899Smjacob *	MBOX_WAIT_COMPLETE(ispsoftc_t *, mbreg_t *) wait for cmd to be done
968155704Smjacob *	MBOX_NOTIFY_COMPLETE(ispsoftc_t *)	notification of mbox cmd donee
969155704Smjacob *	MBOX_RELEASE(ispsoftc_t *)		release lock on mailbox regs
97064087Smjacob *
971196008Smjacob *	FC_SCRATCH_ACQUIRE(ispsoftc_t *, chan)	acquire lock on FC scratch area
972196008Smjacob *						return -1 if you cannot
973196008Smjacob *	FC_SCRATCH_RELEASE(ispsoftc_t *, chan)	acquire lock on FC scratch area
97472355Smjacob *
97564087Smjacob *	SCSI_GOOD	SCSI 'Good' Status
97664087Smjacob *	SCSI_CHECK	SCSI 'Check Condition' Status
97764087Smjacob *	SCSI_BUSY	SCSI 'Busy' Status
97864087Smjacob *	SCSI_QFULL	SCSI 'Queue Full' Status
97964087Smjacob *
980196008Smjacob *	XS_T			Platform SCSI transaction type (i.e., command for HBA)
981196008Smjacob *	XS_DMA_ADDR_T		Platform PCI DMA Address Type
982196008Smjacob *	XS_GET_DMA_SEG(..)	Get 32 bit dma segment list value
983196008Smjacob *	XS_GET_DMA64_SEG(..)	Get 64 bit dma segment list value
984196008Smjacob *	XS_ISP(xs)		gets an instance out of an XS_T
985196008Smjacob *	XS_CHANNEL(xs)		gets the channel (bus # for DUALBUS cards) ""
986196008Smjacob *	XS_TGT(xs)		gets the target ""
987196008Smjacob *	XS_LUN(xs)		gets the lun ""
988196008Smjacob *	XS_CDBP(xs)		gets a pointer to the scsi CDB ""
989196008Smjacob *	XS_CDBLEN(xs)		gets the CDB's length ""
990196008Smjacob *	XS_XFRLEN(xs)		gets the associated data transfer length ""
991196008Smjacob *	XS_TIME(xs)		gets the time (in milliseconds) for this command
992196008Smjacob *	XS_GET_RESID(xs)	gets the current residual count
993196008Smjacob *	XS_GET_RESID(xs, resid)	sets the current residual count
994196008Smjacob *	XS_STSP(xs)		gets a pointer to the SCSI status byte ""
995196008Smjacob *	XS_SNSP(xs)		gets a pointer to the associate sense data
996196008Smjacob *	XS_SNSLEN(xs)		gets the length of sense data storage
997196008Smjacob *	XS_SNSKEY(xs)		dereferences XS_SNSP to get the current stored Sense Key
998196008Smjacob *	XS_TAG_P(xs)		predicate of whether this command should be tagged
999196008Smjacob *	XS_TAG_TYPE(xs)		which type of tag to use
1000196008Smjacob *	XS_SETERR(xs)		set error state
100164087Smjacob *
100264087Smjacob *		HBA_NOERROR	command has no erros
100364087Smjacob *		HBA_BOTCH	hba botched something
100464087Smjacob *		HBA_CMDTIMEOUT	command timed out
100564087Smjacob *		HBA_SELTIMEOUT	selection timed out (also port logouts for FC)
100664087Smjacob *		HBA_TGTBSY	target returned a BUSY status
100764087Smjacob *		HBA_BUSRESET	bus reset destroyed command
100864087Smjacob *		HBA_ABORTED	command was aborted (by request)
100964087Smjacob *		HBA_DATAOVR	a data overrun was detected
101064087Smjacob *		HBA_ARQFAIL	Automatic Request Sense failed
101164087Smjacob *
101264087Smjacob *	XS_ERR(xs)	return current error state
101364087Smjacob *	XS_NOERR(xs)	there is no error currently set
101464087Smjacob *	XS_INITERR(xs)	initialize error state
101564087Smjacob *
1016164272Smjacob *	XS_SAVE_SENSE(xs, sp, len)	save sense data
101764087Smjacob *
1018196008Smjacob *	DEFAULT_FRAMESIZE(ispsoftc_t *)		Default Frame Size
1019196008Smjacob *	DEFAULT_EXEC_THROTTLE(ispsoftc_t *)	Default Execution Throttle
102064087Smjacob *
1021196008Smjacob *	GET_DEFAULT_ROLE(ispsoftc_t *, int)	Get Default Role for a channel
1022196008Smjacob *	SET_DEFAULT_ROLE(ispsoftc_t *, int, int) Set Default Role for a channel
1023196008Smjacob *	DEFAULT_IID(ispsoftc_t *, int)		Default SCSI initiator ID
1024196008Smjacob *	DEFAULT_LOOPID(ispsoftc_t *, int)	Default FC Loop ID
102564087Smjacob *
102667047Smjacob *		These establish reasonable defaults for each platform.
102767047Smjacob * 		These must be available independent of card NVRAM and are
102867047Smjacob *		to be used should NVRAM not be readable.
102964087Smjacob *
1030196008Smjacob *	DEFAULT_NODEWWN(ispsoftc_t *, chan)	Default FC Node WWN to use
1031196008Smjacob *	DEFAULT_PORTWWN(ispsoftc_t *, chan)	Default FC Port WWN to use
103264087Smjacob *
1033196008Smjacob *		These defines are hooks to allow the setting of node and
1034196008Smjacob *		port WWNs when NVRAM cannot be read or is to be overriden.
103564087Smjacob *
1036196008Smjacob *	ACTIVE_NODEWWN(ispsoftc_t *, chan)	FC Node WWN to use
1037196008Smjacob *	ACTIVE_PORTWWN(ispsoftc_t *, chan)	FC Port WWN to use
103887635Smjacob *
1039196008Smjacob *		After NVRAM is read, these will be invoked to get the
1040196008Smjacob *		node and port WWNs that will actually be used for this
1041196008Smjacob *		channel.
1042196008Smjacob *
1043196008Smjacob *
1044155704Smjacob *	ISP_IOXPUT_8(ispsoftc_t *, uint8_t srcval, uint8_t *dstptr)
1045155704Smjacob *	ISP_IOXPUT_16(ispsoftc_t *, uint16_t srcval, uint16_t *dstptr)
1046155704Smjacob *	ISP_IOXPUT_32(ispsoftc_t *, uint32_t srcval, uint32_t *dstptr)
104787635Smjacob *
1048155704Smjacob *	ISP_IOXGET_8(ispsoftc_t *, uint8_t *srcptr, uint8_t dstrval)
1049155704Smjacob *	ISP_IOXGET_16(ispsoftc_t *, uint16_t *srcptr, uint16_t dstrval)
1050155704Smjacob *	ISP_IOXGET_32(ispsoftc_t *, uint32_t *srcptr, uint32_t dstrval)
105187635Smjacob *
1052155704Smjacob *	ISP_SWIZZLE_NVRAM_WORD(ispsoftc_t *, uint16_t *)
1053171159Smjacob *	ISP_SWIZZLE_NVRAM_LONG(ispsoftc_t *, uint32_t *)
1054171159Smjacob *	ISP_SWAP16(ispsoftc_t *, uint16_t srcval)
1055171159Smjacob *	ISP_SWAP32(ispsoftc_t *, uint32_t srcval)
105664087Smjacob */
105777365Smjacob
1058196008Smjacob#ifdef	ISP_TARGET_MODE
1059196008Smjacob/*
1060196008Smjacob * The functions below are for the publicly available
1061196008Smjacob * target mode functions that are internal to the Qlogic driver.
1062196008Smjacob */
1063196008Smjacob
1064196008Smjacob/*
1065196008Smjacob * This function handles new response queue entry appropriate for target mode.
1066196008Smjacob */
1067196008Smjacobint isp_target_notify(ispsoftc_t *, void *, uint32_t *);
1068196008Smjacob
1069196008Smjacob/*
1070196008Smjacob * This function externalizes the ability to acknowledge an Immediate Notify request.
1071196008Smjacob */
1072196008Smjacobint isp_notify_ack(ispsoftc_t *, void *);
1073196008Smjacob
1074196008Smjacob/*
1075196008Smjacob * This function externalized acknowledging (success/fail) an ABTS frame
1076196008Smjacob */
1077196008Smjacobint isp_acknak_abts(ispsoftc_t *, void *, int);
1078196008Smjacob
1079196008Smjacob/*
1080196008Smjacob * Enable/Disable/Modify a logical unit.
1081196008Smjacob * (softc, cmd, bus, tgt, lun, cmd_cnt, inotify_cnt)
1082196008Smjacob */
1083196008Smjacob#define	DFLT_CMND_CNT	0xfe	/* unmonitored */
1084196008Smjacob#define	DFLT_INOT_CNT	0xfe	/* unmonitored */
1085196008Smjacobint isp_lun_cmd(ispsoftc_t *, int, int, int, int, int);
1086196008Smjacob
1087196008Smjacob/*
1088196008Smjacob * General request queue 'put' routine for target mode entries.
1089196008Smjacob */
1090196008Smjacobint isp_target_put_entry(ispsoftc_t *isp, void *);
1091196008Smjacob
1092196008Smjacob/*
1093196008Smjacob * General routine to put back an ATIO entry-
1094196008Smjacob * used for replenishing f/w resource counts.
1095196008Smjacob * The argument is a pointer to a source ATIO
1096196008Smjacob * or ATIO2.
1097196008Smjacob */
1098196008Smjacobint isp_target_put_atio(ispsoftc_t *, void *);
1099196008Smjacob
1100196008Smjacob/*
1101196008Smjacob * General routine to send a final CTIO for a command- used mostly for
1102196008Smjacob * local responses.
1103196008Smjacob */
1104196008Smjacobint isp_endcmd(ispsoftc_t *, ...);
1105196008Smjacob#define	ECMD_SVALID	0x100
1106196008Smjacob#define	ECMD_TERMINATE	0x200
1107196008Smjacob
1108196008Smjacob/*
1109196008Smjacob * Handle an asynchronous event
1110196008Smjacob *
1111196008Smjacob * Return nonzero if the interrupt that generated this event has been dismissed.
1112196008Smjacob */
1113196008Smjacobint isp_target_async(ispsoftc_t *, int, int);
1114196008Smjacob#endif
111535388Smjacob#endif	/* _ISPVAR_H */
1116