isp_freebsd.h revision 238869
1/* $FreeBSD: head/sys/dev/isp/isp_freebsd.h 238869 2012-07-28 20:06:29Z mjacob $ */
2/*-
3 * Qlogic ISP SCSI Host Adapter FreeBSD Wrapper Definitions
4 *
5 * Copyright (c) 1997-2008 by Matthew Jacob
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice immediately at the beginning of the file, without modification,
13 *    this list of conditions, and the following disclaimer.
14 * 2. The name of the author may not be used to endorse or promote products
15 *    derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29#ifndef	_ISP_FREEBSD_H
30#define	_ISP_FREEBSD_H
31
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/endian.h>
35#include <sys/lock.h>
36#include <sys/kernel.h>
37#include <sys/queue.h>
38#include <sys/malloc.h>
39#include <sys/mutex.h>
40#include <sys/condvar.h>
41#include <sys/sysctl.h>
42
43#include <sys/proc.h>
44#include <sys/bus.h>
45#include <sys/taskqueue.h>
46
47#include <machine/bus.h>
48#include <machine/cpu.h>
49#include <machine/stdarg.h>
50
51#include <cam/cam.h>
52#include <cam/cam_debug.h>
53#include <cam/cam_ccb.h>
54#include <cam/cam_sim.h>
55#include <cam/cam_xpt.h>
56#include <cam/cam_xpt_sim.h>
57#include <cam/cam_debug.h>
58#include <cam/scsi/scsi_all.h>
59#include <cam/scsi/scsi_message.h>
60
61#include "opt_ddb.h"
62#include "opt_isp.h"
63
64#define	ISP_PLATFORM_VERSION_MAJOR	7
65#define	ISP_PLATFORM_VERSION_MINOR	10
66
67/*
68 * Efficiency- get rid of SBus code && tests unless we need them.
69 */
70#ifdef __sparc64__
71#define	ISP_SBUS_SUPPORTED	1
72#else
73#define	ISP_SBUS_SUPPORTED	0
74#endif
75
76#define	ISP_IFLAGS	INTR_TYPE_CAM | INTR_ENTROPY | INTR_MPSAFE
77
78#define	N_XCMDS		64
79#define	XCMD_SIZE	512
80struct ispsoftc;
81typedef union isp_ecmd {
82	union isp_ecmd *	next;
83	uint8_t			data[XCMD_SIZE];
84} isp_ecmd_t;
85isp_ecmd_t *	isp_get_ecmd(struct ispsoftc *);
86void		isp_put_ecmd(struct ispsoftc *, isp_ecmd_t *);
87
88#ifdef	ISP_TARGET_MODE
89/* Not quite right, but there was no bump for this change */
90#if __FreeBSD_version < 225469
91#define	SDFIXED(x)	(&x)
92#else
93#define	SDFIXED(x)	((struct scsi_sense_data_fixed *)(&x))
94#endif
95
96#define	ISP_TARGET_FUNCTIONS	1
97#define	ATPDPSIZE	4096
98
99#include <dev/isp/isp_target.h>
100
101typedef struct {
102	void *		next;
103	uint32_t	orig_datalen;
104	uint32_t	bytes_xfered;
105	uint32_t	last_xframt;
106	uint32_t	tag;		/* typically f/w RX_ID */
107	uint32_t	lun;
108	uint32_t	nphdl;
109	uint32_t	sid;
110	uint32_t	portid;
111	uint16_t	rxid;	/* wire rxid */
112	uint16_t	oxid;	/* wire oxid */
113	uint16_t	word3;	/* PRLI word3 params */
114	uint16_t	ctcnt;	/* number of CTIOs currently active */
115	uint32_t
116			srr_notify_rcvd	: 1,
117			cdb0		: 8,
118			sendst		: 1,
119			dead		: 1,
120			tattr		: 3,
121			state		: 3;
122	void *		ests;
123	/*
124	 * The current SRR notify copy
125	 */
126	uint8_t		srr[64];	/*  sb QENTRY_LEN, but order of definitions is wrong */
127	void *		srr_ccb;
128	uint32_t	nsrr;
129} atio_private_data_t;
130#define	ATPD_STATE_FREE			0
131#define	ATPD_STATE_ATIO			1
132#define	ATPD_STATE_CAM			2
133#define	ATPD_STATE_CTIO			3
134#define	ATPD_STATE_LAST_CTIO		4
135#define	ATPD_STATE_PDON			5
136
137typedef union inot_private_data inot_private_data_t;
138union inot_private_data {
139	inot_private_data_t *next;
140	struct {
141		isp_notify_t nt;	/* must be first! */
142		uint8_t data[64];	/* sb QENTRY_LEN, but order of definitions is wrong */
143		uint32_t tag_id, seq_id;
144	} rd;
145};
146typedef struct isp_timed_notify_ack {
147	void *isp;
148	void *not;
149	uint8_t data[64];	 /* sb QENTRY_LEN, but order of definitions is wrong */
150} isp_tna_t;
151
152typedef struct tstate {
153	SLIST_ENTRY(tstate) next;
154	struct cam_path *owner;
155	struct ccb_hdr_slist atios;
156	struct ccb_hdr_slist inots;
157	uint32_t hold;
158	uint32_t
159		enabled		: 1,
160		atio_count	: 15,
161		inot_count	: 15;
162	inot_private_data_t *	restart_queue;
163	inot_private_data_t *	ntfree;
164	inot_private_data_t	ntpool[ATPDPSIZE];
165	atio_private_data_t *	atfree;
166	atio_private_data_t	atpool[ATPDPSIZE];
167} tstate_t;
168
169#define	LUN_HASH_SIZE		32
170#define	LUN_HASH_FUNC(lun)	((lun) & (LUN_HASH_SIZE - 1))
171
172#endif
173
174/*
175 * Per command info.
176 */
177struct isp_pcmd {
178	struct isp_pcmd *	next;
179	bus_dmamap_t 		dmap;		/* dma map for this command */
180	struct ispsoftc *	isp;		/* containing isp */
181	struct callout		wdog;		/* watchdog timer */
182	uint8_t			totslen;	/* sense length on status response */
183	uint8_t			cumslen;	/* sense length on status response */
184	uint8_t 		crn;		/* command reference number */
185};
186#define	ISP_PCMD(ccb)		(ccb)->ccb_h.spriv_ptr1
187#define	PISP_PCMD(ccb)		((struct isp_pcmd *)ISP_PCMD(ccb))
188
189/*
190 * Per nexus info.
191 */
192struct isp_nexus {
193	struct isp_nexus *	next;
194	uint32_t
195		crnseed	:	8;	/* next command reference number */
196	uint32_t
197		tgt	:	16,	/* TGT for target */
198		lun	:	16;	/* LUN for target */
199};
200#define	NEXUS_HASH_WIDTH	32
201#define	INITIAL_NEXUS_COUNT	MAX_FC_TARG
202#define	NEXUS_HASH(tgt, lun)	((tgt + lun) % NEXUS_HASH_WIDTH)
203
204/*
205 * Per channel information
206 */
207SLIST_HEAD(tslist, tstate);
208
209struct isp_fc {
210	struct cam_sim *sim;
211	struct cam_path *path;
212	struct ispsoftc *isp;
213	struct proc *kproc;
214	bus_dma_tag_t tdmat;
215	bus_dmamap_t tdmap;
216	uint64_t def_wwpn;
217	uint64_t def_wwnn;
218	uint32_t loop_down_time;
219	uint32_t loop_down_limit;
220	uint32_t gone_device_time;
221	/*
222	 * Per target/lun info- just to keep a per-ITL nexus crn count
223	 */
224	struct isp_nexus *nexus_hash[NEXUS_HASH_WIDTH];
225	struct isp_nexus *nexus_free_list;
226	uint32_t
227#ifdef	ISP_TARGET_MODE
228#ifdef	ISP_INTERNAL_TARGET
229		proc_active	: 1,
230#endif
231		tm_luns_enabled	: 1,
232		tm_enable_defer	: 1,
233		tm_enabled	: 1,
234#endif
235		simqfrozen	: 3,
236		default_id	: 8,
237		hysteresis	: 8,
238		def_role	: 2,	/* default role */
239		gdt_running	: 1,
240		loop_dead	: 1,
241		fcbsy		: 1,
242		ready		: 1;
243	struct callout ldt;	/* loop down timer */
244	struct callout gdt;	/* gone device timer */
245	struct task ltask;
246	struct task gtask;
247#ifdef	ISP_TARGET_MODE
248	struct tslist lun_hash[LUN_HASH_SIZE];
249#ifdef	ISP_INTERNAL_TARGET
250	struct proc *		target_proc;
251#endif
252#if defined(DEBUG)
253	unsigned int inject_lost_data_frame;
254#endif
255#endif
256};
257
258struct isp_spi {
259	struct cam_sim *sim;
260	struct cam_path *path;
261	uint32_t
262#ifdef	ISP_TARGET_MODE
263#ifdef	ISP_INTERNAL_TARGET
264		proc_active	: 1,
265#endif
266		tm_luns_enabled	: 1,
267		tm_enable_defer	: 1,
268		tm_enabled	: 1,
269#endif
270		simqfrozen	: 3,
271		def_role	: 2,
272		iid		: 4;
273#ifdef	ISP_TARGET_MODE
274	struct tslist lun_hash[LUN_HASH_SIZE];
275#ifdef	ISP_INTERNAL_TARGET
276	struct proc *		target_proc;
277#endif
278#endif
279};
280
281struct isposinfo {
282	/*
283	 * Linkage, locking, and identity
284	 */
285	struct mtx		lock;
286	device_t		dev;
287	struct cdev *		cdev;
288	struct intr_config_hook	ehook;
289	struct cam_devq *	devq;
290
291	/*
292	 * Firmware pointer
293	 */
294	const struct firmware *	fw;
295
296	/*
297	 * DMA related sdtuff
298	 */
299	bus_space_tag_t		bus_tag;
300	bus_dma_tag_t		dmat;
301	bus_space_handle_t	bus_handle;
302	bus_dma_tag_t		cdmat;
303	bus_dmamap_t		cdmap;
304
305	/*
306	 * Command and transaction related related stuff
307	 */
308	struct isp_pcmd *	pcmd_pool;
309	struct isp_pcmd *	pcmd_free;
310
311	uint32_t
312#ifdef	ISP_TARGET_MODE
313		tmwanted	: 1,
314		tmbusy		: 1,
315#else
316				: 2,
317#endif
318		sixtyfourbit	: 1,	/* sixtyfour bit platform */
319		timer_active	: 1,
320		autoconf	: 1,
321		ehook_active	: 1,
322		disabled	: 1,
323		mbox_sleeping	: 1,
324		mbox_sleep_ok	: 1,
325		mboxcmd_done	: 1,
326		mboxbsy		: 1;
327
328	struct callout		tmo;	/* general timer */
329
330	/*
331	 * misc- needs to be sorted better XXXXXX
332	 */
333	int			framesize;
334	int			exec_throttle;
335	int			cont_max;
336
337#ifdef	ISP_TARGET_MODE
338	cam_status *		rptr;
339#endif
340
341	bus_addr_t		ecmd_dma;
342	isp_ecmd_t *		ecmd_base;
343	isp_ecmd_t *		ecmd_free;
344
345	/*
346	 * Per-type private storage...
347	 */
348	union {
349		struct isp_fc *fc;
350		struct isp_spi *spi;
351		void *ptr;
352	} pc;
353};
354#define	ISP_FC_PC(isp, chan)	(&(isp)->isp_osinfo.pc.fc[(chan)])
355#define	ISP_SPI_PC(isp, chan)	(&(isp)->isp_osinfo.pc.spi[(chan)])
356#define	ISP_GET_PC(isp, chan, tag, rslt)		\
357	if (IS_SCSI(isp)) {				\
358		rslt = ISP_SPI_PC(isp, chan)-> tag;	\
359	} else {					\
360		rslt = ISP_FC_PC(isp, chan)-> tag;	\
361	}
362#define	ISP_GET_PC_ADDR(isp, chan, tag, rp)		\
363	if (IS_SCSI(isp)) {				\
364		rp = &ISP_SPI_PC(isp, chan)-> tag;	\
365	} else {					\
366		rp = &ISP_FC_PC(isp, chan)-> tag;	\
367	}
368#define	ISP_SET_PC(isp, chan, tag, val)			\
369	if (IS_SCSI(isp)) {				\
370		ISP_SPI_PC(isp, chan)-> tag = val;	\
371	} else {					\
372		ISP_FC_PC(isp, chan)-> tag = val;	\
373	}
374
375#define	FCP_NEXT_CRN	isp_fcp_next_crn
376#define	isp_lock	isp_osinfo.lock
377#define	isp_bus_tag	isp_osinfo.bus_tag
378#define	isp_bus_handle	isp_osinfo.bus_handle
379
380/*
381 * Locking macros...
382 */
383#define	ISP_LOCK(isp)	mtx_lock(&isp->isp_osinfo.lock)
384#define	ISP_UNLOCK(isp)	mtx_unlock(&isp->isp_osinfo.lock)
385
386/*
387 * Required Macros/Defines
388 */
389#define	ISP_FC_SCRLEN		0x1000
390
391#define	ISP_MEMZERO(a, b)	memset(a, 0, b)
392#define	ISP_MEMCPY		memcpy
393#define	ISP_SNPRINTF		snprintf
394#define	ISP_DELAY		DELAY
395#define	ISP_SLEEP(isp, x)	DELAY(x)
396
397#define	ISP_MIN			imin
398
399#ifndef	DIAGNOSTIC
400#define	ISP_INLINE		__inline
401#else
402#define	ISP_INLINE
403#endif
404
405#define	NANOTIME_T		struct timespec
406#define	GET_NANOTIME		nanotime
407#define	GET_NANOSEC(x)		((x)->tv_sec * 1000000000 + (x)->tv_nsec)
408#define	NANOTIME_SUB		isp_nanotime_sub
409
410#define	MAXISPREQUEST(isp)	((IS_FC(isp) || IS_ULTRA2(isp))? 1024 : 256)
411
412#define	MEMORYBARRIER(isp, type, offset, size, chan)		\
413switch (type) {							\
414case SYNC_SFORDEV:						\
415{								\
416	struct isp_fc *fc = ISP_FC_PC(isp, chan);		\
417	bus_dmamap_sync(fc->tdmat, fc->tdmap,			\
418	   BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);		\
419	break;							\
420}								\
421case SYNC_REQUEST:						\
422	bus_dmamap_sync(isp->isp_osinfo.cdmat,			\
423	   isp->isp_osinfo.cdmap, 				\
424	   BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);		\
425	break;							\
426case SYNC_SFORCPU:						\
427{								\
428	struct isp_fc *fc = ISP_FC_PC(isp, chan);		\
429	bus_dmamap_sync(fc->tdmat, fc->tdmap,			\
430	   BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);	\
431	break;							\
432}								\
433case SYNC_RESULT:						\
434	bus_dmamap_sync(isp->isp_osinfo.cdmat, 			\
435	   isp->isp_osinfo.cdmap,				\
436	   BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);	\
437	break;							\
438case SYNC_REG:							\
439	bus_space_barrier(isp->isp_osinfo.bus_tag,		\
440	    isp->isp_osinfo.bus_handle, offset, size,		\
441	    BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE);	\
442	break;							\
443default:							\
444	break;							\
445}
446
447#define	MBOX_ACQUIRE			isp_mbox_acquire
448#define	MBOX_WAIT_COMPLETE		isp_mbox_wait_complete
449#define	MBOX_NOTIFY_COMPLETE		isp_mbox_notify_done
450#define	MBOX_RELEASE			isp_mbox_release
451
452#define	FC_SCRATCH_ACQUIRE		isp_fc_scratch_acquire
453#define	FC_SCRATCH_RELEASE(isp, chan)	isp->isp_osinfo.pc.fc[chan].fcbsy = 0
454
455#ifndef	SCSI_GOOD
456#define	SCSI_GOOD	SCSI_STATUS_OK
457#endif
458#ifndef	SCSI_CHECK
459#define	SCSI_CHECK	SCSI_STATUS_CHECK_COND
460#endif
461#ifndef	SCSI_BUSY
462#define	SCSI_BUSY	SCSI_STATUS_BUSY
463#endif
464#ifndef	SCSI_QFULL
465#define	SCSI_QFULL	SCSI_STATUS_QUEUE_FULL
466#endif
467
468#define	XS_T			struct ccb_scsiio
469#define	XS_DMA_ADDR_T		bus_addr_t
470#define XS_GET_DMA64_SEG(a, b, c)		\
471{						\
472	ispds64_t *d = a;			\
473	bus_dma_segment_t *e = b;		\
474	uint32_t f = c;				\
475	e += f;					\
476        d->ds_base = DMA_LO32(e->ds_addr);	\
477        d->ds_basehi = DMA_HI32(e->ds_addr);	\
478        d->ds_count = e->ds_len;		\
479}
480#define XS_GET_DMA_SEG(a, b, c)			\
481{						\
482	ispds_t *d = a;				\
483	bus_dma_segment_t *e = b;		\
484	uint32_t f = c;				\
485	e += f;					\
486        d->ds_base = DMA_LO32(e->ds_addr);	\
487        d->ds_count = e->ds_len;		\
488}
489#define	XS_ISP(ccb)		cam_sim_softc(xpt_path_sim((ccb)->ccb_h.path))
490#define	XS_CHANNEL(ccb)		cam_sim_bus(xpt_path_sim((ccb)->ccb_h.path))
491#define	XS_TGT(ccb)		(ccb)->ccb_h.target_id
492#define	XS_LUN(ccb)		(ccb)->ccb_h.target_lun
493
494#define	XS_CDBP(ccb)	\
495	(((ccb)->ccb_h.flags & CAM_CDB_POINTER)? \
496	 (ccb)->cdb_io.cdb_ptr : (ccb)->cdb_io.cdb_bytes)
497
498#define	XS_CDBLEN(ccb)		(ccb)->cdb_len
499#define	XS_XFRLEN(ccb)		(ccb)->dxfer_len
500#define	XS_TIME(ccb)		(ccb)->ccb_h.timeout
501#define	XS_GET_RESID(ccb)	(ccb)->resid
502#define	XS_SET_RESID(ccb, r)	(ccb)->resid = r
503#define	XS_STSP(ccb)		(&(ccb)->scsi_status)
504#define	XS_SNSP(ccb)		(&(ccb)->sense_data)
505
506#define	XS_TOT_SNSLEN(ccb)	ccb->sense_len
507#define	XS_CUR_SNSLEN(ccb)	(ccb->sense_len - ccb->sense_resid)
508
509#define	XS_SNSKEY(ccb)		(scsi_get_sense_key(&(ccb)->sense_data, \
510				 ccb->sense_len - ccb->sense_resid, 1))
511
512#define	XS_SNSASC(ccb)		(scsi_get_asc(&(ccb)->sense_data,	\
513				 ccb->sense_len - ccb->sense_resid, 1))
514
515#define	XS_SNSASCQ(ccb)		(scsi_get_ascq(&(ccb)->sense_data,	\
516				 ccb->sense_len - ccb->sense_resid, 1))
517#define	XS_TAG_P(ccb)	\
518	(((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) && \
519	 (ccb)->tag_action != CAM_TAG_ACTION_NONE)
520
521#define	XS_TAG_TYPE(ccb)	\
522	((ccb->tag_action == MSG_SIMPLE_Q_TAG)? REQFLAG_STAG : \
523	 ((ccb->tag_action == MSG_HEAD_OF_Q_TAG)? REQFLAG_HTAG : REQFLAG_OTAG))
524
525
526#define	XS_SETERR(ccb, v)	(ccb)->ccb_h.status &= ~CAM_STATUS_MASK, \
527				(ccb)->ccb_h.status |= v
528
529#	define	HBA_NOERROR		CAM_REQ_INPROG
530#	define	HBA_BOTCH		CAM_UNREC_HBA_ERROR
531#	define	HBA_CMDTIMEOUT		CAM_CMD_TIMEOUT
532#	define	HBA_SELTIMEOUT		CAM_SEL_TIMEOUT
533#	define	HBA_TGTBSY		CAM_SCSI_STATUS_ERROR
534#	define	HBA_BUSRESET		CAM_SCSI_BUS_RESET
535#	define	HBA_ABORTED		CAM_REQ_ABORTED
536#	define	HBA_DATAOVR		CAM_DATA_RUN_ERR
537#	define	HBA_ARQFAIL		CAM_AUTOSENSE_FAIL
538
539
540#define	XS_ERR(ccb)		((ccb)->ccb_h.status & CAM_STATUS_MASK)
541
542#define	XS_NOERR(ccb)		(((ccb)->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG)
543
544#define	XS_INITERR(ccb)		XS_SETERR(ccb, CAM_REQ_INPROG), ccb->sense_resid = ccb->sense_len
545
546#define	XS_SAVE_SENSE(xs, sense_ptr, totslen, slen)	do {			\
547		uint32_t tlen = slen;						\
548		if (tlen > (xs)->sense_len)					\
549			tlen = (xs)->sense_len;					\
550		PISP_PCMD(xs)->totslen = imin((xs)->sense_len, totslen);	\
551		PISP_PCMD(xs)->cumslen = tlen;					\
552		memcpy(&(xs)->sense_data, sense_ptr, tlen);			\
553		(xs)->sense_resid = (xs)->sense_len - tlen;			\
554		(xs)->ccb_h.status |= CAM_AUTOSNS_VALID;			\
555	} while (0)
556
557#define	XS_SENSE_APPEND(xs, xsnsp, xsnsl)	do {				\
558		uint32_t off = PISP_PCMD(xs)->cumslen;				\
559		uint8_t *ptr = &((uint8_t *)(&(xs)->sense_data))[off];		\
560		uint32_t amt = imin(xsnsl, PISP_PCMD(xs)->totslen - off);	\
561		if (amt) {							\
562			memcpy(ptr, xsnsp, amt);				\
563			(xs)->sense_resid -= amt;				\
564			PISP_PCMD(xs)->cumslen += amt;				\
565		}								\
566	} while (0)
567
568#define	XS_SENSE_VALID(xs)	(((xs)->ccb_h.status & CAM_AUTOSNS_VALID) != 0)
569
570#define	DEFAULT_FRAMESIZE(isp)		isp->isp_osinfo.framesize
571#define	DEFAULT_EXEC_THROTTLE(isp)	isp->isp_osinfo.exec_throttle
572
573#define	GET_DEFAULT_ROLE(isp, chan)	\
574	(IS_FC(isp)? ISP_FC_PC(isp, chan)->def_role : ISP_SPI_PC(isp, chan)->def_role)
575#define	SET_DEFAULT_ROLE(isp, chan, val)		\
576	if (IS_FC(isp)) { 				\
577		ISP_FC_PC(isp, chan)->def_role = val;	\
578	} else {					\
579		ISP_SPI_PC(isp, chan)->def_role = val;	\
580	}
581
582#define	DEFAULT_IID(isp, chan)		isp->isp_osinfo.pc.spi[chan].iid
583
584#define	DEFAULT_LOOPID(x, chan)		isp->isp_osinfo.pc.fc[chan].default_id
585
586#define DEFAULT_NODEWWN(isp, chan)  	isp_default_wwn(isp, chan, 0, 1)
587#define DEFAULT_PORTWWN(isp, chan)  	isp_default_wwn(isp, chan, 0, 0)
588#define ACTIVE_NODEWWN(isp, chan)   	isp_default_wwn(isp, chan, 1, 1)
589#define ACTIVE_PORTWWN(isp, chan)   	isp_default_wwn(isp, chan, 1, 0)
590
591
592#if	BYTE_ORDER == BIG_ENDIAN
593#ifdef	ISP_SBUS_SUPPORTED
594#define	ISP_IOXPUT_8(isp, s, d)		*(d) = s
595#define	ISP_IOXPUT_16(isp, s, d)				\
596	*(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap16(s)
597#define	ISP_IOXPUT_32(isp, s, d)				\
598	*(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap32(s)
599#define	ISP_IOXGET_8(isp, s, d)		d = (*((uint8_t *)s))
600#define	ISP_IOXGET_16(isp, s, d)				\
601	d = (isp->isp_bustype == ISP_BT_SBUS)?			\
602	*((uint16_t *)s) : bswap16(*((uint16_t *)s))
603#define	ISP_IOXGET_32(isp, s, d)				\
604	d = (isp->isp_bustype == ISP_BT_SBUS)?			\
605	*((uint32_t *)s) : bswap32(*((uint32_t *)s))
606
607#else	/* ISP_SBUS_SUPPORTED */
608#define	ISP_IOXPUT_8(isp, s, d)		*(d) = s
609#define	ISP_IOXPUT_16(isp, s, d)	*(d) = bswap16(s)
610#define	ISP_IOXPUT_32(isp, s, d)	*(d) = bswap32(s)
611#define	ISP_IOXGET_8(isp, s, d)		d = (*((uint8_t *)s))
612#define	ISP_IOXGET_16(isp, s, d)	d = bswap16(*((uint16_t *)s))
613#define	ISP_IOXGET_32(isp, s, d)	d = bswap32(*((uint32_t *)s))
614#endif
615#define	ISP_SWIZZLE_NVRAM_WORD(isp, rp)	*rp = bswap16(*rp)
616#define	ISP_SWIZZLE_NVRAM_LONG(isp, rp)	*rp = bswap32(*rp)
617
618#define	ISP_IOZGET_8(isp, s, d)		d = (*((uint8_t *)s))
619#define	ISP_IOZGET_16(isp, s, d)	d = (*((uint16_t *)s))
620#define	ISP_IOZGET_32(isp, s, d)	d = (*((uint32_t *)s))
621#define	ISP_IOZPUT_8(isp, s, d)		*(d) = s
622#define	ISP_IOZPUT_16(isp, s, d)	*(d) = s
623#define	ISP_IOZPUT_32(isp, s, d)	*(d) = s
624
625
626#else
627#define	ISP_IOXPUT_8(isp, s, d)		*(d) = s
628#define	ISP_IOXPUT_16(isp, s, d)	*(d) = s
629#define	ISP_IOXPUT_32(isp, s, d)	*(d) = s
630#define	ISP_IOXGET_8(isp, s, d)		d = *(s)
631#define	ISP_IOXGET_16(isp, s, d)	d = *(s)
632#define	ISP_IOXGET_32(isp, s, d)	d = *(s)
633#define	ISP_SWIZZLE_NVRAM_WORD(isp, rp)
634#define	ISP_SWIZZLE_NVRAM_LONG(isp, rp)
635
636#define	ISP_IOZPUT_8(isp, s, d)		*(d) = s
637#define	ISP_IOZPUT_16(isp, s, d)	*(d) = bswap16(s)
638#define	ISP_IOZPUT_32(isp, s, d)	*(d) = bswap32(s)
639
640#define	ISP_IOZGET_8(isp, s, d)		d = (*((uint8_t *)(s)))
641#define	ISP_IOZGET_16(isp, s, d)	d = bswap16(*((uint16_t *)(s)))
642#define	ISP_IOZGET_32(isp, s, d)	d = bswap32(*((uint32_t *)(s)))
643
644#endif
645
646#define	ISP_SWAP16(isp, s)	bswap16(s)
647#define	ISP_SWAP32(isp, s)	bswap32(s)
648
649/*
650 * Includes of common header files
651 */
652
653#include <dev/isp/ispreg.h>
654#include <dev/isp/ispvar.h>
655#include <dev/isp/ispmbox.h>
656
657/*
658 * isp_osinfo definiitions && shorthand
659 */
660#define	SIMQFRZ_RESOURCE	0x1
661#define	SIMQFRZ_LOOPDOWN	0x2
662#define	SIMQFRZ_TIMED		0x4
663
664#define	isp_dev		isp_osinfo.dev
665
666/*
667 * prototypes for isp_pci && isp_freebsd to share
668 */
669extern int isp_attach(ispsoftc_t *);
670extern int isp_detach(ispsoftc_t *);
671extern void isp_uninit(ispsoftc_t *);
672extern uint64_t isp_default_wwn(ispsoftc_t *, int, int, int);
673
674/*
675 * driver global data
676 */
677extern int isp_announced;
678extern int isp_fabric_hysteresis;
679extern int isp_loop_down_limit;
680extern int isp_gone_device_time;
681extern int isp_quickboot_time;
682extern int isp_autoconfig;
683
684/*
685 * Platform private flags
686 */
687
688/*
689 * Platform Library Functions
690 */
691void isp_prt(ispsoftc_t *, int level, const char *, ...) __printflike(3, 4);
692void isp_xs_prt(ispsoftc_t *, XS_T *, int level, const char *, ...) __printflike(4, 5);
693uint64_t isp_nanotime_sub(struct timespec *, struct timespec *);
694int isp_mbox_acquire(ispsoftc_t *);
695void isp_mbox_wait_complete(ispsoftc_t *, mbreg_t *);
696void isp_mbox_notify_done(ispsoftc_t *);
697void isp_mbox_release(ispsoftc_t *);
698int isp_fc_scratch_acquire(ispsoftc_t *, int);
699int isp_mstohz(int);
700void isp_platform_intr(void *);
701void isp_common_dmateardown(ispsoftc_t *, struct ccb_scsiio *, uint32_t);
702int isp_fcp_next_crn(ispsoftc_t *, uint8_t *, XS_T *);
703
704/*
705 * Platform Version specific defines
706 */
707#define	BUS_DMA_ROOTARG(x)	bus_get_dma_tag(x)
708#define	isp_dma_tag_create(a, b, c, d, e, f, g, h, i, j, k, z)	\
709	bus_dma_tag_create(a, b, c, d, e, f, g, h, i, j, k, \
710	busdma_lock_mutex, &isp->isp_osinfo.lock, z)
711
712#define	isp_setup_intr	bus_setup_intr
713
714#define	isp_sim_alloc(a, b, c, d, e, f, g, h)	\
715	cam_sim_alloc(a, b, c, d, e, &(d)->isp_osinfo.lock, f, g, h)
716
717/* Should be BUS_SPACE_MAXSIZE, but MAXPHYS is larger than BUS_SPACE_MAXSIZE */
718#define ISP_NSEGS ((MAXPHYS / PAGE_SIZE) + 1)
719
720#define	ISP_PATH_PRT(i, l, p, ...)					\
721	if ((l) == ISP_LOGALL || ((l)& (i)->isp_dblev) != 0) {		\
722                xpt_print(p, __VA_ARGS__);				\
723        }
724
725/*
726 * Platform specific inline functions
727 */
728
729/*
730 * ISP General Library functions
731 */
732
733#include <dev/isp/isp_library.h>
734
735#endif	/* _ISP_FREEBSD_H */
736