xref: /freebsd/sys/dev/mpt/mpt.h (revision c87e3f833c6b6efcebeeb51abc182c9f3e556071)
19b631363SMatt Jacob /* $FreeBSD$ */
2098ca2bdSWarner Losh /*-
39b631363SMatt Jacob  * Generic defines for LSI '909 FC  adapters.
49b631363SMatt Jacob  * FreeBSD Version.
59b631363SMatt Jacob  *
69b631363SMatt Jacob  * Copyright (c)  2000, 2001 by Greg Ansley
79b631363SMatt Jacob  *
89b631363SMatt Jacob  * Redistribution and use in source and binary forms, with or without
99b631363SMatt Jacob  * modification, are permitted provided that the following conditions
109b631363SMatt Jacob  * are met:
119b631363SMatt Jacob  * 1. Redistributions of source code must retain the above copyright
129b631363SMatt Jacob  *    notice immediately at the beginning of the file, without modification,
139b631363SMatt Jacob  *    this list of conditions, and the following disclaimer.
149b631363SMatt Jacob  * 2. The name of the author may not be used to endorse or promote products
159b631363SMatt Jacob  *    derived from this software without specific prior written permission.
169b631363SMatt Jacob  *
179b631363SMatt Jacob  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
189b631363SMatt Jacob  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199b631363SMatt Jacob  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
209b631363SMatt Jacob  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
219b631363SMatt Jacob  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
229b631363SMatt Jacob  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
239b631363SMatt Jacob  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
249b631363SMatt Jacob  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
259b631363SMatt Jacob  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
269b631363SMatt Jacob  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
279b631363SMatt Jacob  * SUCH DAMAGE.
280b80d21bSMatt Jacob  */
290b80d21bSMatt Jacob /*-
300b80d21bSMatt Jacob  * Copyright (c) 2002, 2006 by Matthew Jacob
310b80d21bSMatt Jacob  * All rights reserved.
32b0a2fdeeSScott Long  *
330b80d21bSMatt Jacob  * Redistribution and use in source and binary forms, with or without
340b80d21bSMatt Jacob  * modification, are permitted provided that the following conditions are
350b80d21bSMatt Jacob  * met:
360b80d21bSMatt Jacob  * 1. Redistributions of source code must retain the above copyright
370b80d21bSMatt Jacob  *    notice, this list of conditions and the following disclaimer.
380b80d21bSMatt Jacob  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
390b80d21bSMatt Jacob  *    substantially similar to the "NO WARRANTY" disclaimer below
400b80d21bSMatt Jacob  *    ("Disclaimer") and any redistribution must be conditioned upon including
410b80d21bSMatt Jacob  *    a substantially similar Disclaimer requirement for further binary
420b80d21bSMatt Jacob  *    redistribution.
430b80d21bSMatt Jacob  * 3. Neither the names of the above listed copyright holders nor the names
440b80d21bSMatt Jacob  *    of any contributors may be used to endorse or promote products derived
450b80d21bSMatt Jacob  *    from this software without specific prior written permission.
460b80d21bSMatt Jacob  *
470b80d21bSMatt Jacob  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
480b80d21bSMatt Jacob  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
490b80d21bSMatt Jacob  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
500b80d21bSMatt Jacob  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
510b80d21bSMatt Jacob  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
520b80d21bSMatt Jacob  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
530b80d21bSMatt Jacob  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
540b80d21bSMatt Jacob  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
550b80d21bSMatt Jacob  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
560b80d21bSMatt Jacob  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
570b80d21bSMatt Jacob  * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
580b80d21bSMatt Jacob  *
590b80d21bSMatt Jacob  * Support from Chris Ellsworth in order to make SAS adapters work
600b80d21bSMatt Jacob  * is gratefully acknowledged.
619b631363SMatt Jacob  */
629b631363SMatt Jacob /*
63b0a2fdeeSScott Long  * Copyright (c) 2004, Avid Technology, Inc. and its contributors.
64b0a2fdeeSScott Long  * Copyright (c) 2004, 2005 Justin T. Gibbs
65b0a2fdeeSScott Long  * Copyright (c) 2005, WHEEL Sp. z o.o.
66b0a2fdeeSScott Long  * All rights reserved.
67b0a2fdeeSScott Long  *
68b0a2fdeeSScott Long  * Redistribution and use in source and binary forms, with or without
69b0a2fdeeSScott Long  * modification, are permitted provided that the following conditions are
70b0a2fdeeSScott Long  * met:
71b0a2fdeeSScott Long  * 1. Redistributions of source code must retain the above copyright
72b0a2fdeeSScott Long  *    notice, this list of conditions and the following disclaimer.
73b0a2fdeeSScott Long  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
74b0a2fdeeSScott Long  *    substantially similar to the "NO WARRANTY" disclaimer below
75b0a2fdeeSScott Long  *    ("Disclaimer") and any redistribution must be conditioned upon including
76b0a2fdeeSScott Long  *    a substantially similar Disclaimer requirement for further binary
77b0a2fdeeSScott Long  *    redistribution.
78286e947fSJustin T. Gibbs  * 3. Neither the names of the above listed copyright holders nor the names
79286e947fSJustin T. Gibbs  *    of any contributors may be used to endorse or promote products derived
80286e947fSJustin T. Gibbs  *    from this software without specific prior written permission.
81b0a2fdeeSScott Long  *
82b0a2fdeeSScott Long  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
83b0a2fdeeSScott Long  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
84b0a2fdeeSScott Long  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
85b0a2fdeeSScott Long  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
86b0a2fdeeSScott Long  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
87b0a2fdeeSScott Long  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
88b0a2fdeeSScott Long  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
89b0a2fdeeSScott Long  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
90b0a2fdeeSScott Long  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
91b0a2fdeeSScott Long  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
92b0a2fdeeSScott Long  * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
939b631363SMatt Jacob  */
949b631363SMatt Jacob 
959b631363SMatt Jacob #ifndef _MPT_H_
969b631363SMatt Jacob #define _MPT_H_
97b0a2fdeeSScott Long 
98b0a2fdeeSScott Long /********************************* OS Includes ********************************/
99b0a2fdeeSScott Long #include <sys/types.h>
100b0a2fdeeSScott Long #include <sys/param.h>
101b0a2fdeeSScott Long #include <sys/systm.h>
102b0a2fdeeSScott Long #include <sys/endian.h>
103b0a2fdeeSScott Long #include <sys/eventhandler.h>
104b0a2fdeeSScott Long #if __FreeBSD_version < 500000
105b0a2fdeeSScott Long #include <sys/kernel.h>
106b0a2fdeeSScott Long #include <sys/queue.h>
107b0a2fdeeSScott Long #include <sys/malloc.h>
108b0a2fdeeSScott Long #else
109b0a2fdeeSScott Long #include <sys/lock.h>
110b0a2fdeeSScott Long #include <sys/kernel.h>
111b0a2fdeeSScott Long #include <sys/queue.h>
112b0a2fdeeSScott Long #include <sys/malloc.h>
113b0a2fdeeSScott Long #include <sys/mutex.h>
114b0a2fdeeSScott Long #include <sys/condvar.h>
115b0a2fdeeSScott Long #endif
116b0a2fdeeSScott Long #include <sys/proc.h>
117b0a2fdeeSScott Long #include <sys/bus.h>
118b0a2fdeeSScott Long #include <sys/module.h>
119b0a2fdeeSScott Long 
120b0a2fdeeSScott Long #include <machine/clock.h>
121b0a2fdeeSScott Long #include <machine/cpu.h>
122b0a2fdeeSScott Long #include <machine/resource.h>
123b0a2fdeeSScott Long 
124c87e3f83SMatt Jacob #if __FreeBSD_version < 500000
125c87e3f83SMatt Jacob #include <machine/bus.h>
126c87e3f83SMatt Jacob #endif
127c87e3f83SMatt Jacob 
128b0a2fdeeSScott Long #include <sys/rman.h>
129b0a2fdeeSScott Long 
130444dd2b6SMatt Jacob #if __FreeBSD_version < 500000
131444dd2b6SMatt Jacob #include <pci/pcireg.h>
132444dd2b6SMatt Jacob #include <pci/pcivar.h>
133444dd2b6SMatt Jacob #else
134444dd2b6SMatt Jacob #include <dev/pci/pcireg.h>
135444dd2b6SMatt Jacob #include <dev/pci/pcivar.h>
136444dd2b6SMatt Jacob #endif
137444dd2b6SMatt Jacob 
138444dd2b6SMatt Jacob #include <machine/bus.h>
139b0a2fdeeSScott Long #include "opt_ddb.h"
140b0a2fdeeSScott Long 
141b0a2fdeeSScott Long /**************************** Register Definitions ****************************/
142b0a2fdeeSScott Long #include <dev/mpt/mpt_reg.h>
143b0a2fdeeSScott Long 
144b0a2fdeeSScott Long /******************************* MPI Definitions ******************************/
145b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_type.h>
146b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi.h>
147b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_cnfg.h>
148b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_ioc.h>
149b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_raid.h>
150b0a2fdeeSScott Long 
151b0a2fdeeSScott Long /* XXX For mpt_debug.c */
152b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_init.h>
153b0a2fdeeSScott Long 
154b0a2fdeeSScott Long /****************************** Misc Definitions ******************************/
1559b631363SMatt Jacob #define MPT_OK (0)
1569b631363SMatt Jacob #define MPT_FAIL (0x10000)
1579b631363SMatt Jacob 
158b0a2fdeeSScott Long #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array))
1599b631363SMatt Jacob 
160c87e3f83SMatt Jacob #define	MPT_ROLE_NONE		0
161c87e3f83SMatt Jacob #define	MPT_ROLE_INITIATOR	1
162c87e3f83SMatt Jacob #define	MPT_ROLE_TARGET		2
163c87e3f83SMatt Jacob #define	MPT_ROLE_BOTH		3
164c87e3f83SMatt Jacob #define	MPT_ROLE_DEFAULT	MPT_ROLE_INITIATOR
165c87e3f83SMatt Jacob 
166b0a2fdeeSScott Long /**************************** Forward Declarations ****************************/
167b0a2fdeeSScott Long struct mpt_softc;
168b0a2fdeeSScott Long struct mpt_personality;
169b0a2fdeeSScott Long typedef struct req_entry request_t;
1709b631363SMatt Jacob 
171b0a2fdeeSScott Long /************************* Personality Module Support *************************/
172b0a2fdeeSScott Long typedef int mpt_load_handler_t(struct mpt_personality *);
173b0a2fdeeSScott Long typedef int mpt_probe_handler_t(struct mpt_softc *);
174b0a2fdeeSScott Long typedef int mpt_attach_handler_t(struct mpt_softc *);
175c87e3f83SMatt Jacob typedef int mpt_enable_handler_t(struct mpt_softc *);
176b0a2fdeeSScott Long typedef int mpt_event_handler_t(struct mpt_softc *, request_t *,
177b0a2fdeeSScott Long 				MSG_EVENT_NOTIFY_REPLY *);
178b0a2fdeeSScott Long typedef void mpt_reset_handler_t(struct mpt_softc *, int /*type*/);
179b0a2fdeeSScott Long /* XXX Add return value and use for veto? */
180b0a2fdeeSScott Long typedef void mpt_shutdown_handler_t(struct mpt_softc *);
181b0a2fdeeSScott Long typedef void mpt_detach_handler_t(struct mpt_softc *);
182b0a2fdeeSScott Long typedef int mpt_unload_handler_t(struct mpt_personality *);
183b0a2fdeeSScott Long 
184b0a2fdeeSScott Long struct mpt_personality
185b0a2fdeeSScott Long {
186b0a2fdeeSScott Long 	const char		*name;
187b0a2fdeeSScott Long 	uint32_t		 id;		/* Assigned identifier. */
188b0a2fdeeSScott Long 	u_int			 use_count;	/* Instances using personality*/
189b0a2fdeeSScott Long 	mpt_load_handler_t	*load;		/* configure personailty */
190b0a2fdeeSScott Long #define MPT_PERS_FIRST_HANDLER(pers) (&(pers)->load)
191b0a2fdeeSScott Long 	mpt_probe_handler_t	*probe;		/* configure personailty */
192b0a2fdeeSScott Long 	mpt_attach_handler_t	*attach;	/* initialize device instance */
193c87e3f83SMatt Jacob 	mpt_enable_handler_t	*enable;	/* enable device */
194b0a2fdeeSScott Long 	mpt_event_handler_t	*event;		/* Handle MPI event. */
195b0a2fdeeSScott Long 	mpt_reset_handler_t	*reset;		/* Re-init after reset. */
196b0a2fdeeSScott Long 	mpt_shutdown_handler_t	*shutdown;	/* Shutdown instance. */
197b0a2fdeeSScott Long 	mpt_detach_handler_t	*detach;	/* release device instance */
198b0a2fdeeSScott Long 	mpt_unload_handler_t	*unload;	/* Shutdown personality */
199b0a2fdeeSScott Long #define MPT_PERS_LAST_HANDLER(pers) (&(pers)->unload)
2009b631363SMatt Jacob };
2019b631363SMatt Jacob 
202b0a2fdeeSScott Long int mpt_modevent(module_t, int, void *);
2039b631363SMatt Jacob 
204b0a2fdeeSScott Long /* Maximum supported number of personalities. */
205b0a2fdeeSScott Long #define MPT_MAX_PERSONALITIES	(15)
2069b631363SMatt Jacob 
207b0a2fdeeSScott Long #define MPT_PERSONALITY_DEPEND(name, dep, vmin, vpref, vmax) \
208b0a2fdeeSScott Long 	MODULE_DEPEND(name, dep, vmin, vpref, vmax)
209b0a2fdeeSScott Long 
210b0a2fdeeSScott Long #define DECLARE_MPT_PERSONALITY(name, order)				  \
211b0a2fdeeSScott Long 	static moduledata_t name##_mod = {				  \
212b0a2fdeeSScott Long 		#name, mpt_modevent, &name##_personality		  \
213b0a2fdeeSScott Long 	};								  \
214b0a2fdeeSScott Long 	DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, order);	  \
215b0a2fdeeSScott Long 	MODULE_VERSION(name, 1);					  \
216b0a2fdeeSScott Long 	MPT_PERSONALITY_DEPEND(name, mpt_core, 1, 1, 1)
217b0a2fdeeSScott Long 
218b0a2fdeeSScott Long /******************************* Bus DMA Support ******************************/
219b0a2fdeeSScott Long /* XXX Need to update bus_dmamap_sync to take a range argument. */
220b0a2fdeeSScott Long #define bus_dmamap_sync_range(dma_tag, dmamap, offset, len, op)	\
221b0a2fdeeSScott Long 	bus_dmamap_sync(dma_tag, dmamap, op)
222b0a2fdeeSScott Long 
223b0a2fdeeSScott Long #if __FreeBSD_version >= 501102
224b0a2fdeeSScott Long #define mpt_dma_tag_create(mpt, parent_tag, alignment, boundary,	\
225b0a2fdeeSScott Long 			   lowaddr, highaddr, filter, filterarg,	\
226b0a2fdeeSScott Long 			   maxsize, nsegments, maxsegsz, flags,		\
227b0a2fdeeSScott Long 			   dma_tagp)					\
228b0a2fdeeSScott Long 	bus_dma_tag_create(parent_tag, alignment, boundary,		\
229b0a2fdeeSScott Long 			   lowaddr, highaddr, filter, filterarg,	\
230b0a2fdeeSScott Long 			   maxsize, nsegments, maxsegsz, flags,		\
231b0a2fdeeSScott Long 			   busdma_lock_mutex, &Giant,			\
232b0a2fdeeSScott Long 			   dma_tagp)
233b0a2fdeeSScott Long #else
234b0a2fdeeSScott Long #define mpt_dma_tag_create(mpt, parent_tag, alignment, boundary,	\
235b0a2fdeeSScott Long 			   lowaddr, highaddr, filter, filterarg,	\
236b0a2fdeeSScott Long 			   maxsize, nsegments, maxsegsz, flags,		\
237b0a2fdeeSScott Long 			   dma_tagp)					\
238b0a2fdeeSScott Long 	bus_dma_tag_create(parent_tag, alignment, boundary,		\
239b0a2fdeeSScott Long 			   lowaddr, highaddr, filter, filterarg,	\
240b0a2fdeeSScott Long 			   maxsize, nsegments, maxsegsz, flags,		\
241b0a2fdeeSScott Long 			   dma_tagp)
242b0a2fdeeSScott Long #endif
243b0a2fdeeSScott Long 
244b0a2fdeeSScott Long struct mpt_map_info {
245b0a2fdeeSScott Long 	struct mpt_softc *mpt;
246b0a2fdeeSScott Long 	int		  error;
247b0a2fdeeSScott Long 	uint32_t	  phys;
248b0a2fdeeSScott Long };
249b0a2fdeeSScott Long 
250b0a2fdeeSScott Long void mpt_map_rquest(void *, bus_dma_segment_t *, int, int);
251b0a2fdeeSScott Long 
252b0a2fdeeSScott Long /**************************** Kernel Thread Support ***************************/
253b0a2fdeeSScott Long #if __FreeBSD_version > 500005
254b0a2fdeeSScott Long #define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \
255b0a2fdeeSScott Long 	kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg)
256b0a2fdeeSScott Long #else
257b0a2fdeeSScott Long #define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \
258b0a2fdeeSScott Long 	kthread_create(func, farg, proc_ptr, fmtstr, arg)
259b0a2fdeeSScott Long #endif
260b0a2fdeeSScott Long 
261b0a2fdeeSScott Long /****************************** Timer Facilities ******************************/
262b0a2fdeeSScott Long #if __FreeBSD_version > 500000
263b0a2fdeeSScott Long #define mpt_callout_init(c)	callout_init(c, /*mpsafe*/0);
264b0a2fdeeSScott Long #else
265b0a2fdeeSScott Long #define mpt_callout_init(c)	callout_init(c);
266b0a2fdeeSScott Long #endif
267b0a2fdeeSScott Long 
268b0a2fdeeSScott Long /********************************** Endianess *********************************/
269b0a2fdeeSScott Long static __inline uint64_t
270b0a2fdeeSScott Long u64toh(U64 s)
271b0a2fdeeSScott Long {
272b0a2fdeeSScott Long 	uint64_t result;
273b0a2fdeeSScott Long 
274b0a2fdeeSScott Long 	result = le32toh(s.Low);
275b0a2fdeeSScott Long 	result |= ((uint64_t)le32toh(s.High)) << 32;
276b0a2fdeeSScott Long 	return (result);
277b0a2fdeeSScott Long }
278b0a2fdeeSScott Long 
279b0a2fdeeSScott Long /**************************** MPI Transaction State ***************************/
280b0a2fdeeSScott Long typedef enum {
281b0a2fdeeSScott Long 	REQ_STATE_FREE		= 0x00,
282b0a2fdeeSScott Long 	REQ_STATE_ALLOCATED	= 0x01,
283b0a2fdeeSScott Long 	REQ_STATE_QUEUED	= 0x02,
284b0a2fdeeSScott Long 	REQ_STATE_DONE		= 0x04,
285b0a2fdeeSScott Long 	REQ_STATE_TIMEDOUT	= 0x08,
286b0a2fdeeSScott Long 	REQ_STATE_NEED_WAKEUP	= 0x10,
287b0a2fdeeSScott Long 	REQ_STATE_MASK		= 0xFF
288b0a2fdeeSScott Long } mpt_req_state_t;
289b0a2fdeeSScott Long 
290b0a2fdeeSScott Long struct req_entry {
291b0a2fdeeSScott Long 	TAILQ_ENTRY(req_entry) links;	/* Pointer to next in list */
292b0a2fdeeSScott Long 	mpt_req_state_t	state;		/* Request State Information */
293b0a2fdeeSScott Long 	uint16_t	index;		/* Index of this entry */
294b0a2fdeeSScott Long 	uint16_t	IOCStatus;	/* Completion status */
295c87e3f83SMatt Jacob 	uint16_t	serno;		/* serial number */
296b0a2fdeeSScott Long 	union ccb      *ccb;		/* CAM request */
297b0a2fdeeSScott Long 	void	       *req_vbuf;	/* Virtual Address of Entry */
298b0a2fdeeSScott Long 	void	       *sense_vbuf;	/* Virtual Address of sense data */
299b0a2fdeeSScott Long 	bus_addr_t	req_pbuf;	/* Physical Address of Entry */
300b0a2fdeeSScott Long 	bus_addr_t	sense_pbuf;	/* Physical Address of sense data */
301b0a2fdeeSScott Long 	bus_dmamap_t	dmap;		/* DMA map for data buffer */
302444dd2b6SMatt Jacob 	struct req_entry *chain;	/* for SGE overallocations */
303b0a2fdeeSScott Long };
304b0a2fdeeSScott Long 
305c87e3f83SMatt Jacob /**************************** MPI Target State Info ***************************/
306c87e3f83SMatt Jacob 
307c87e3f83SMatt Jacob typedef struct {
308c87e3f83SMatt Jacob 	uint32_t reply_desc;	/* current reply descriptor */
309c87e3f83SMatt Jacob 	uint32_t resid;		/* current data residual */
310c87e3f83SMatt Jacob 	uint32_t bytes_xfered;	/* current relative offset */
311c87e3f83SMatt Jacob 	union ccb *ccb;		/* pointer to currently active ccb */
312c87e3f83SMatt Jacob 	request_t *req;		/* pointer to currently active assist request */
313c87e3f83SMatt Jacob 	int	flags;
314c87e3f83SMatt Jacob #define	BOGUS_JO	0x01
315c87e3f83SMatt Jacob 	int	nxfers;
316c87e3f83SMatt Jacob 	enum {
317c87e3f83SMatt Jacob 		TGT_STATE_NIL,
318c87e3f83SMatt Jacob 		TGT_STATE_LOADED,
319c87e3f83SMatt Jacob 		TGT_STATE_IN_CAM,
320c87e3f83SMatt Jacob                 TGT_STATE_SETTING_UP_FOR_DATA,
321c87e3f83SMatt Jacob                 TGT_STATE_MOVING_DATA,
322c87e3f83SMatt Jacob                 TGT_STATE_MOVING_DATA_AND_STATUS,
323c87e3f83SMatt Jacob                 TGT_STATE_SENDING_STATUS
324c87e3f83SMatt Jacob 	} state;
325c87e3f83SMatt Jacob } mpt_tgt_state_t;
326c87e3f83SMatt Jacob 
327c87e3f83SMatt Jacob /*
328c87e3f83SMatt Jacob  * When we get an incoming command it has its own tag which is called the
329c87e3f83SMatt Jacob  * IoIndex. This is the value we gave that particular command buffer when
330c87e3f83SMatt Jacob  * we originally assigned it. It's just a number, really. The FC card uses
331c87e3f83SMatt Jacob  * it as an RX_ID. We can use it to index into mpt->tgt_cmd_ptrs, which
332c87e3f83SMatt Jacob  * contains pointers the request_t structures related to that IoIndex.
333c87e3f83SMatt Jacob  *
334c87e3f83SMatt Jacob  * What *we* do is construct a tag out of the index for the target command
335c87e3f83SMatt Jacob  * which owns the incoming ATIO plus a rolling sequence number.
336c87e3f83SMatt Jacob  */
337c87e3f83SMatt Jacob #define	MPT_MAKE_TAGID(mpt, req, ioindex)	\
338c87e3f83SMatt Jacob 	((ioindex << 16) | (mpt->sequence++))
339c87e3f83SMatt Jacob 
340c87e3f83SMatt Jacob #ifdef	INVARIANTS
341c87e3f83SMatt Jacob #define	MPT_TAG_2_REQ(a, b)		mpt_tag_2_req(a, (uint32_t) b)
342c87e3f83SMatt Jacob #else
343c87e3f83SMatt Jacob #define	MPT_TAG_2_REQ(mpt, tag)		mpt->tgt_cmd_ptrs[tag >> 16]
344c87e3f83SMatt Jacob #endif
345c87e3f83SMatt Jacob 
346c87e3f83SMatt Jacob #define	MPT_TGT_STATE(mpt, req) ((mpt_tgt_state_t *) \
347c87e3f83SMatt Jacob     (&((uint8_t *)req->req_vbuf)[MPT_RQSL(mpt) - sizeof (mpt_tgt_state_t)]))
348c87e3f83SMatt Jacob 
349c87e3f83SMatt Jacob STAILQ_HEAD(mpt_hdr_stailq, ccb_hdr);
350c87e3f83SMatt Jacob #define	MPT_MAX_LUNS	256
351c87e3f83SMatt Jacob typedef struct {
352c87e3f83SMatt Jacob 	struct mpt_hdr_stailq	atios;
353c87e3f83SMatt Jacob 	struct mpt_hdr_stailq	inots;
354c87e3f83SMatt Jacob 	int enabled;
355c87e3f83SMatt Jacob } tgt_resource_t;
356c87e3f83SMatt Jacob #define	MPT_MAX_ELS	8
357c87e3f83SMatt Jacob 
358b0a2fdeeSScott Long /**************************** Handler Registration ****************************/
359b0a2fdeeSScott Long /*
360b0a2fdeeSScott Long  * Global table of registered reply handlers.  The
361b0a2fdeeSScott Long  * handler is indicated by byte 3 of the request
362b0a2fdeeSScott Long  * index submitted to the IOC.  This allows the
363b0a2fdeeSScott Long  * driver core to perform generic processing without
364b0a2fdeeSScott Long  * any knowledge of per-personality behavior.
365b0a2fdeeSScott Long  *
366b0a2fdeeSScott Long  * MPT_NUM_REPLY_HANDLERS must be a power of 2
367b0a2fdeeSScott Long  * to allow the easy generation of a mask.
368b0a2fdeeSScott Long  *
369b0a2fdeeSScott Long  * The handler offsets used by the core are hard coded
370b0a2fdeeSScott Long  * allowing faster code generation when assigning a handler
371b0a2fdeeSScott Long  * to a request.  All "personalities" must use the
372b0a2fdeeSScott Long  * the handler registration mechanism.
373b0a2fdeeSScott Long  *
374b0a2fdeeSScott Long  * The IOC handlers that are rarely executed are placed
375b0a2fdeeSScott Long  * at the tail of the table to make it more likely that
376b0a2fdeeSScott Long  * all commonly executed handlers fit in a single cache
377b0a2fdeeSScott Long  * line.
378b0a2fdeeSScott Long  */
379c87e3f83SMatt Jacob #define MPT_NUM_REPLY_HANDLERS		(32)
380b0a2fdeeSScott Long #define MPT_REPLY_HANDLER_EVENTS	MPT_CBI_TO_HID(0)
381b0a2fdeeSScott Long #define MPT_REPLY_HANDLER_CONFIG	MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-1)
382b0a2fdeeSScott Long #define MPT_REPLY_HANDLER_HANDSHAKE	MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-2)
383b0a2fdeeSScott Long typedef int mpt_reply_handler_t(struct mpt_softc *mpt, request_t *request,
384c87e3f83SMatt Jacob     uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame);
385b0a2fdeeSScott Long typedef union {
386b0a2fdeeSScott Long 	mpt_reply_handler_t	*reply_handler;
387b0a2fdeeSScott Long } mpt_handler_t;
388b0a2fdeeSScott Long 
389b0a2fdeeSScott Long typedef enum {
390b0a2fdeeSScott Long 	MPT_HANDLER_REPLY,
391b0a2fdeeSScott Long 	MPT_HANDLER_EVENT,
392b0a2fdeeSScott Long 	MPT_HANDLER_RESET,
393b0a2fdeeSScott Long 	MPT_HANDLER_SHUTDOWN
394b0a2fdeeSScott Long } mpt_handler_type;
395b0a2fdeeSScott Long 
396b0a2fdeeSScott Long struct mpt_handler_record
397b0a2fdeeSScott Long {
398b0a2fdeeSScott Long 	LIST_ENTRY(mpt_handler_record)	links;
399b0a2fdeeSScott Long 	mpt_handler_t			handler;
400b0a2fdeeSScott Long };
401b0a2fdeeSScott Long 
402b0a2fdeeSScott Long LIST_HEAD(mpt_handler_list, mpt_handler_record);
4039b631363SMatt Jacob 
4049b631363SMatt Jacob /*
405b0a2fdeeSScott Long  * The handler_id is currently unused but would contain the
406b0a2fdeeSScott Long  * handler ID used in the MsgContext field to allow direction
407b0a2fdeeSScott Long  * of replies to the handler.  Registrations that don't require
408b0a2fdeeSScott Long  * a handler id can pass in NULL for the handler_id.
409b0a2fdeeSScott Long  *
410b0a2fdeeSScott Long  * Deregistrations for handlers without a handler id should
411b0a2fdeeSScott Long  * pass in MPT_HANDLER_ID_NONE.
4129b631363SMatt Jacob  */
413b0a2fdeeSScott Long #define MPT_HANDLER_ID_NONE		(0xFFFFFFFF)
414b0a2fdeeSScott Long int mpt_register_handler(struct mpt_softc *, mpt_handler_type,
415b0a2fdeeSScott Long 			 mpt_handler_t, uint32_t *);
416b0a2fdeeSScott Long int mpt_deregister_handler(struct mpt_softc *, mpt_handler_type,
417b0a2fdeeSScott Long 			   mpt_handler_t, uint32_t);
4189b631363SMatt Jacob 
419b0a2fdeeSScott Long /******************* Per-Controller Instance Data Structures ******************/
420b0a2fdeeSScott Long TAILQ_HEAD(req_queue, req_entry);
4219b631363SMatt Jacob 
422b0a2fdeeSScott Long /* Structure for saving proper values for modifyable PCI config registers */
423b0a2fdeeSScott Long struct mpt_pci_cfg {
424b0a2fdeeSScott Long 	uint16_t Command;
425b0a2fdeeSScott Long 	uint16_t LatencyTimer_LineSize;
426b0a2fdeeSScott Long 	uint32_t IO_BAR;
427b0a2fdeeSScott Long 	uint32_t Mem0_BAR[2];
428b0a2fdeeSScott Long 	uint32_t Mem1_BAR[2];
429b0a2fdeeSScott Long 	uint32_t ROM_BAR;
430b0a2fdeeSScott Long 	uint8_t  IntLine;
431b0a2fdeeSScott Long 	uint32_t PMCSR;
4329b631363SMatt Jacob };
4339b631363SMatt Jacob 
434b0a2fdeeSScott Long typedef enum {
435b0a2fdeeSScott Long 	MPT_RVF_NONE		= 0x0,
436b0a2fdeeSScott Long 	MPT_RVF_ACTIVE		= 0x1,
437b0a2fdeeSScott Long 	MPT_RVF_ANNOUNCED	= 0x2,
438b0a2fdeeSScott Long 	MPT_RVF_UP2DATE		= 0x4,
439b0a2fdeeSScott Long 	MPT_RVF_REFERENCED	= 0x8,
440b0a2fdeeSScott Long 	MPT_RVF_WCE_CHANGED	= 0x10
441b0a2fdeeSScott Long } mpt_raid_volume_flags;
442b0a2fdeeSScott Long 
443b0a2fdeeSScott Long struct mpt_raid_volume {
444b0a2fdeeSScott Long 	CONFIG_PAGE_RAID_VOL_0	       *config_page;
445b0a2fdeeSScott Long 	MPI_RAID_VOL_INDICATOR		sync_progress;
446b0a2fdeeSScott Long 	mpt_raid_volume_flags		flags;
447b0a2fdeeSScott Long 	u_int				quieced_disks;
4489b631363SMatt Jacob };
4499b631363SMatt Jacob 
450b0a2fdeeSScott Long typedef enum {
451b0a2fdeeSScott Long 	MPT_RDF_NONE		= 0x00,
452b0a2fdeeSScott Long 	MPT_RDF_ACTIVE		= 0x01,
453b0a2fdeeSScott Long 	MPT_RDF_ANNOUNCED	= 0x02,
454b0a2fdeeSScott Long 	MPT_RDF_UP2DATE		= 0x04,
455b0a2fdeeSScott Long 	MPT_RDF_REFERENCED	= 0x08,
456b0a2fdeeSScott Long 	MPT_RDF_QUIESCING	= 0x10,
457b0a2fdeeSScott Long 	MPT_RDF_QUIESCED	= 0x20
458b0a2fdeeSScott Long } mpt_raid_disk_flags;
4599b631363SMatt Jacob 
460b0a2fdeeSScott Long struct mpt_raid_disk {
461b0a2fdeeSScott Long 	CONFIG_PAGE_RAID_PHYS_DISK_0	config_page;
462b0a2fdeeSScott Long 	struct mpt_raid_volume	       *volume;
463b0a2fdeeSScott Long 	u_int				member_number;
464b0a2fdeeSScott Long 	u_int				pass_thru_active;
465b0a2fdeeSScott Long 	mpt_raid_disk_flags		flags;
4669b631363SMatt Jacob };
4679b631363SMatt Jacob 
468b0a2fdeeSScott Long struct mpt_evtf_record {
469b0a2fdeeSScott Long 	MSG_EVENT_NOTIFY_REPLY		reply;
470b0a2fdeeSScott Long 	uint32_t			context;
471b0a2fdeeSScott Long 	LIST_ENTRY(mpt_evtf_record)	links;
4729b631363SMatt Jacob };
4739b631363SMatt Jacob 
474b0a2fdeeSScott Long LIST_HEAD(mpt_evtf_list, mpt_evtf_record);
4759b631363SMatt Jacob 
476b0a2fdeeSScott Long struct mpt_softc {
477b0a2fdeeSScott Long 	device_t		dev;
478b0a2fdeeSScott Long #if __FreeBSD_version < 500000
479b0a2fdeeSScott Long 	int			mpt_splsaved;
480b0a2fdeeSScott Long 	uint32_t		mpt_islocked;
481b0a2fdeeSScott Long #else
482b0a2fdeeSScott Long 	struct mtx		mpt_lock;
483b0a2fdeeSScott Long #endif
484b0a2fdeeSScott Long 	uint32_t		mpt_pers_mask;
485c87e3f83SMatt Jacob 	uint32_t		: 8,
486c87e3f83SMatt Jacob 		unit		: 8,
487c87e3f83SMatt Jacob 				: 1,
488c87e3f83SMatt Jacob 		twildcard	: 1,
489c87e3f83SMatt Jacob 		tenabled	: 1,
490c87e3f83SMatt Jacob 		cap 		: 2,	/* none, ini, target, both */
491c87e3f83SMatt Jacob 		role		: 2,	/* none, ini, target, both */
492b0a2fdeeSScott Long 		raid_mwce_set	: 1,
493b0a2fdeeSScott Long 		getreqwaiter	: 1,
494b0a2fdeeSScott Long 		shutdwn_raid    : 1,
495b0a2fdeeSScott Long 		shutdwn_recovery: 1,
496b0a2fdeeSScott Long 		outofbeer	: 1,
497b0a2fdeeSScott Long 		mpt_locksetup	: 1,
498b0a2fdeeSScott Long 		disabled	: 1,
499c87e3f83SMatt Jacob 		is_sas		: 1,
500c87e3f83SMatt Jacob 		is_fc		: 1;
5019b631363SMatt Jacob 
502b0a2fdeeSScott Long 	u_int			verbose;
5039b631363SMatt Jacob 
504b0a2fdeeSScott Long 	/*
505b0a2fdeeSScott Long 	 * IOC Facts
506b0a2fdeeSScott Long 	 */
507b0a2fdeeSScott Long 	uint16_t	mpt_global_credits;
508b0a2fdeeSScott Long 	uint16_t	request_frame_size;
509b0a2fdeeSScott Long 	uint8_t		mpt_max_devices;
510b0a2fdeeSScott Long 	uint8_t		mpt_max_buses;
511444dd2b6SMatt Jacob 	uint8_t		ioc_facts_flags;
5129b631363SMatt Jacob 
513b0a2fdeeSScott Long 	/*
514b0a2fdeeSScott Long 	 * Port Facts
515b0a2fdeeSScott Long 	 * XXX - Add multi-port support!.
516b0a2fdeeSScott Long 	 */
517b0a2fdeeSScott Long 	uint16_t	mpt_ini_id;
518b0a2fdeeSScott Long 	uint16_t	mpt_port_type;
519b0a2fdeeSScott Long 	uint16_t	mpt_proto_flags;
520c87e3f83SMatt Jacob 	uint16_t	mpt_max_tgtcmds;
5219b631363SMatt Jacob 
522b0a2fdeeSScott Long 	/*
523b0a2fdeeSScott Long 	 * Device Configuration Information
524b0a2fdeeSScott Long 	 */
525b0a2fdeeSScott Long 	union {
526b0a2fdeeSScott Long 		struct mpt_spi_cfg {
527b0a2fdeeSScott Long 			CONFIG_PAGE_SCSI_PORT_0		_port_page0;
528b0a2fdeeSScott Long 			CONFIG_PAGE_SCSI_PORT_1		_port_page1;
529b0a2fdeeSScott Long 			CONFIG_PAGE_SCSI_PORT_2		_port_page2;
530b0a2fdeeSScott Long 			CONFIG_PAGE_SCSI_DEVICE_0	_dev_page0[16];
531b0a2fdeeSScott Long 			CONFIG_PAGE_SCSI_DEVICE_1	_dev_page1[16];
532b0a2fdeeSScott Long 			uint16_t			_tag_enable;
533b0a2fdeeSScott Long 			uint16_t			_disc_enable;
534b0a2fdeeSScott Long 			uint16_t			_update_params0;
535b0a2fdeeSScott Long 			uint16_t			_update_params1;
536b0a2fdeeSScott Long 		} spi;
537b0a2fdeeSScott Long #define	mpt_port_page0		cfg.spi._port_page0
538b0a2fdeeSScott Long #define	mpt_port_page1		cfg.spi._port_page1
539b0a2fdeeSScott Long #define	mpt_port_page2		cfg.spi._port_page2
540b0a2fdeeSScott Long #define	mpt_dev_page0		cfg.spi._dev_page0
541b0a2fdeeSScott Long #define	mpt_dev_page1		cfg.spi._dev_page1
542b0a2fdeeSScott Long #define	mpt_tag_enable		cfg.spi._tag_enable
543b0a2fdeeSScott Long #define	mpt_disc_enable		cfg.spi._disc_enable
544b0a2fdeeSScott Long #define	mpt_update_params0	cfg.spi._update_params0
545b0a2fdeeSScott Long #define	mpt_update_params1	cfg.spi._update_params1
546b0a2fdeeSScott Long 		struct mpi_fc_cfg {
547c87e3f83SMatt Jacob 			CONFIG_PAGE_FC_PORT_0 _port_page0;
548c87e3f83SMatt Jacob #define	mpt_fcport_page0	cfg.fc._port_page0
549b0a2fdeeSScott Long 		} fc;
550b0a2fdeeSScott Long 	} cfg;
551b0a2fdeeSScott Long 
552b0a2fdeeSScott Long 	/* Controller Info */
553b0a2fdeeSScott Long 	CONFIG_PAGE_IOC_2 *	ioc_page2;
554b0a2fdeeSScott Long 	CONFIG_PAGE_IOC_3 *	ioc_page3;
555b0a2fdeeSScott Long 
556b0a2fdeeSScott Long 	/* Raid Data */
557b0a2fdeeSScott Long 	struct mpt_raid_volume* raid_volumes;
558b0a2fdeeSScott Long 	struct mpt_raid_disk*	raid_disks;
559b0a2fdeeSScott Long 	u_int			raid_max_volumes;
560b0a2fdeeSScott Long 	u_int			raid_max_disks;
561b0a2fdeeSScott Long 	u_int			raid_page0_len;
562b0a2fdeeSScott Long 	u_int			raid_wakeup;
563b0a2fdeeSScott Long 	u_int			raid_rescan;
564b0a2fdeeSScott Long 	u_int			raid_resync_rate;
565b0a2fdeeSScott Long 	u_int			raid_mwce_setting;
566b0a2fdeeSScott Long 	u_int			raid_queue_depth;
5675cc0208aSAlexander Kabaev 	u_int			raid_nonopt_volumes;
568b0a2fdeeSScott Long 	struct proc	       *raid_thread;
569b0a2fdeeSScott Long 	struct callout		raid_timer;
570b0a2fdeeSScott Long 
571b0a2fdeeSScott Long 	/*
572b0a2fdeeSScott Long 	 * PCI Hardware info
573b0a2fdeeSScott Long 	 */
574b0a2fdeeSScott Long 	struct resource *	pci_irq;	/* Interrupt map for chip */
575b0a2fdeeSScott Long 	void *			ih;		/* Interupt handle */
576b0a2fdeeSScott Long 	struct mpt_pci_cfg	pci_cfg;	/* saved PCI conf registers */
577b0a2fdeeSScott Long 
578b0a2fdeeSScott Long 	/*
579b0a2fdeeSScott Long 	 * DMA Mapping Stuff
580b0a2fdeeSScott Long 	 */
581b0a2fdeeSScott Long 	struct resource *	pci_reg;	/* Register map for chip */
582b0a2fdeeSScott Long 	int			pci_mem_rid;	/* Resource ID */
583b0a2fdeeSScott Long 	bus_space_tag_t		pci_st;		/* Bus tag for registers */
584b0a2fdeeSScott Long 	bus_space_handle_t	pci_sh;		/* Bus handle for registers */
585b0a2fdeeSScott Long 	/* PIO versions of above. */
586b0a2fdeeSScott Long 	int			pci_pio_rid;
587b0a2fdeeSScott Long 	struct resource *	pci_pio_reg;
588b0a2fdeeSScott Long 	bus_space_tag_t		pci_pio_st;
589b0a2fdeeSScott Long 	bus_space_handle_t	pci_pio_sh;
590b0a2fdeeSScott Long 
591b0a2fdeeSScott Long 	bus_dma_tag_t		parent_dmat;	/* DMA tag for parent PCI bus */
592b0a2fdeeSScott Long 	bus_dma_tag_t		reply_dmat;	/* DMA tag for reply memory */
593b0a2fdeeSScott Long 	bus_dmamap_t		reply_dmap;	/* DMA map for reply memory */
594b0a2fdeeSScott Long 	uint8_t		       *reply;		/* KVA of reply memory */
595b0a2fdeeSScott Long 	bus_addr_t		reply_phys;	/* BusAddr of reply memory */
596b0a2fdeeSScott Long 
597b0a2fdeeSScott Long 	bus_dma_tag_t		buffer_dmat;	/* DMA tag for buffers */
598b0a2fdeeSScott Long 	bus_dma_tag_t		request_dmat;	/* DMA tag for request memroy */
599b0a2fdeeSScott Long 	bus_dmamap_t		request_dmap;	/* DMA map for request memroy */
600b0a2fdeeSScott Long 	uint8_t		       *request;	/* KVA of Request memory */
601c87e3f83SMatt Jacob 	bus_addr_t		request_phys;	/* BusAddr of request memory */
602b0a2fdeeSScott Long 
603444dd2b6SMatt Jacob 	uint32_t		max_seg_cnt;	/* calculated after IOC facts */
604444dd2b6SMatt Jacob 
605444dd2b6SMatt Jacob 	/*
606444dd2b6SMatt Jacob 	 * Hardware management
607444dd2b6SMatt Jacob 	 */
608b0a2fdeeSScott Long 	u_int			reset_cnt;
609b0a2fdeeSScott Long 
610b0a2fdeeSScott Long 	/*
611b0a2fdeeSScott Long 	 * CAM && Software Management
612b0a2fdeeSScott Long 	 */
613b0a2fdeeSScott Long 	request_t	       *request_pool;
614b0a2fdeeSScott Long 	struct req_queue	request_free_list;
615b0a2fdeeSScott Long 	struct req_queue	request_pending_list;
616b0a2fdeeSScott Long 	struct req_queue	request_timeout_list;
617b0a2fdeeSScott Long 
618b0a2fdeeSScott Long 	/*
619b0a2fdeeSScott Long 	 * Deferred frame acks due to resource shortage.
620b0a2fdeeSScott Long 	 */
621b0a2fdeeSScott Long 	struct mpt_evtf_list	ack_frames;
622b0a2fdeeSScott Long 
623b0a2fdeeSScott Long 
624b0a2fdeeSScott Long 	struct cam_sim	       *sim;
625b0a2fdeeSScott Long 	struct cam_path	       *path;
626b0a2fdeeSScott Long 
627b0a2fdeeSScott Long 	struct cam_sim	       *phydisk_sim;
628b0a2fdeeSScott Long 	struct cam_path	       *phydisk_path;
629b0a2fdeeSScott Long 
630b0a2fdeeSScott Long 	struct proc	       *recovery_thread;
631b0a2fdeeSScott Long 	request_t	       *tmf_req;
632b0a2fdeeSScott Long 
633c87e3f83SMatt Jacob 	/*
634c87e3f83SMatt Jacob 	 * Target Mode Support
635c87e3f83SMatt Jacob 	 */
636c87e3f83SMatt Jacob 	uint32_t		scsi_tgt_handler_id;
637c87e3f83SMatt Jacob 	request_t **		tgt_cmd_ptrs;
638c87e3f83SMatt Jacob 
639c87e3f83SMatt Jacob 	/*
640c87e3f83SMatt Jacob 	 * *snork*- this is chosen to be here *just in case* somebody
641c87e3f83SMatt Jacob 	 * forgets to point to it exactly and we index off of trt with
642c87e3f83SMatt Jacob 	 * CAM_LUN_WILDCARD.
643c87e3f83SMatt Jacob 	 */
644c87e3f83SMatt Jacob 	tgt_resource_t		trt_wildcard;	/* wildcard luns */
645c87e3f83SMatt Jacob 	tgt_resource_t		trt[MPT_MAX_LUNS];
646c87e3f83SMatt Jacob 	uint16_t		tgt_cmds_allocated;
647c87e3f83SMatt Jacob 
648c87e3f83SMatt Jacob 	/*
649c87e3f83SMatt Jacob 	 * Stuff..
650c87e3f83SMatt Jacob 	 */
651c87e3f83SMatt Jacob 	uint16_t		sequence;	/* Sequence Number */
652c87e3f83SMatt Jacob 	uint16_t		timeouts;	/* timeout count */
653c87e3f83SMatt Jacob 	uint16_t		success;	/* successes afer timeout */
654c87e3f83SMatt Jacob 
655b0a2fdeeSScott Long 
656b0a2fdeeSScott Long 	/* Opposing port in a 929 or 1030, or NULL */
657b0a2fdeeSScott Long 	struct mpt_softc *	mpt2;
658b0a2fdeeSScott Long 
659b0a2fdeeSScott Long 	/* FW Image management */
660b0a2fdeeSScott Long 	uint32_t		fw_image_size;
661b0a2fdeeSScott Long 	uint8_t		       *fw_image;
662b0a2fdeeSScott Long 	bus_dma_tag_t		fw_dmat;	/* DMA tag for firmware image */
663b0a2fdeeSScott Long 	bus_dmamap_t		fw_dmap;	/* DMA map for firmware image */
664b0a2fdeeSScott Long 	bus_addr_t		fw_phys;	/* BusAddr of request memory */
665b0a2fdeeSScott Long 
666b0a2fdeeSScott Long 	/* Shutdown Event Handler. */
667b0a2fdeeSScott Long 	eventhandler_tag         eh;
668b0a2fdeeSScott Long 
669b0a2fdeeSScott Long 	TAILQ_ENTRY(mpt_softc)	links;
670b0a2fdeeSScott Long };
671b0a2fdeeSScott Long 
672c87e3f83SMatt Jacob /***************************** Locking Primitives *****************************/
673b0a2fdeeSScott Long #if __FreeBSD_version < 500000
674b0a2fdeeSScott Long #define	MPT_IFLAGS		INTR_TYPE_CAM
675b0a2fdeeSScott Long #define	MPT_LOCK(mpt)		mpt_lockspl(mpt)
676b0a2fdeeSScott Long #define	MPT_UNLOCK(mpt)		mpt_unlockspl(mpt)
677b0a2fdeeSScott Long #define	MPTLOCK_2_CAMLOCK	MPT_UNLOCK
678b0a2fdeeSScott Long #define	CAMLOCK_2_MPTLOCK	MPT_LOCK
679b0a2fdeeSScott Long #define	MPT_LOCK_SETUP(mpt)
680b0a2fdeeSScott Long #define	MPT_LOCK_DESTROY(mpt)
681b0a2fdeeSScott Long 
682b0a2fdeeSScott Long static __inline void mpt_lockspl(struct mpt_softc *mpt);
683b0a2fdeeSScott Long static __inline void mpt_unlockspl(struct mpt_softc *mpt);
684b0a2fdeeSScott Long 
685b0a2fdeeSScott Long static __inline void
686b0a2fdeeSScott Long mpt_lockspl(struct mpt_softc *mpt)
687b0a2fdeeSScott Long {
688b0a2fdeeSScott Long        int s;
689b0a2fdeeSScott Long 
690b0a2fdeeSScott Long        s = splcam();
691b0a2fdeeSScott Long        if (mpt->mpt_islocked++ == 0) {
692b0a2fdeeSScott Long                mpt->mpt_splsaved = s;
693b0a2fdeeSScott Long        } else {
694b0a2fdeeSScott Long                splx(s);
695b0a2fdeeSScott Long 	       panic("Recursed lock with mask: 0x%x\n", s);
696b0a2fdeeSScott Long        }
697b0a2fdeeSScott Long }
698b0a2fdeeSScott Long 
699b0a2fdeeSScott Long static __inline void
700b0a2fdeeSScott Long mpt_unlockspl(struct mpt_softc *mpt)
701b0a2fdeeSScott Long {
702b0a2fdeeSScott Long        if (mpt->mpt_islocked) {
703b0a2fdeeSScott Long                if (--mpt->mpt_islocked == 0) {
704b0a2fdeeSScott Long                        splx(mpt->mpt_splsaved);
705b0a2fdeeSScott Long                }
706b0a2fdeeSScott Long        } else
707b0a2fdeeSScott Long 	       panic("Negative lock count\n");
708b0a2fdeeSScott Long }
709b0a2fdeeSScott Long 
710b0a2fdeeSScott Long static __inline int
711b0a2fdeeSScott Long mpt_sleep(struct mpt_softc *mpt, void *ident, int priority,
712b0a2fdeeSScott Long 	   const char *wmesg, int timo)
713b0a2fdeeSScott Long {
714b0a2fdeeSScott Long 	int saved_cnt;
715b0a2fdeeSScott Long 	int saved_spl;
716b0a2fdeeSScott Long 	int error;
717b0a2fdeeSScott Long 
718b0a2fdeeSScott Long 	KASSERT(mpt->mpt_islocked <= 1, ("Invalid lock count on tsleep"));
719b0a2fdeeSScott Long 	saved_cnt = mpt->mpt_islocked;
720b0a2fdeeSScott Long 	saved_spl = mpt->mpt_splsaved;
721b0a2fdeeSScott Long 	mpt->mpt_islocked = 0;
722b0a2fdeeSScott Long 	error = tsleep(ident, priority, wmesg, timo);
723c87e3f83SMatt Jacob 	KASSERT(mpt->mpt_islocked == 0, ("Invalid lock count on wakeup"));
724b0a2fdeeSScott Long 	mpt->mpt_islocked = saved_cnt;
725b0a2fdeeSScott Long 	mpt->mpt_splsaved = saved_spl;
726b0a2fdeeSScott Long 	return (error);
727b0a2fdeeSScott Long }
728b0a2fdeeSScott Long 
729b0a2fdeeSScott Long #else
730f4e98881SRuslan Ermilov #ifdef	LOCKING_WORKED_AS_IT_SHOULD
731b0a2fdeeSScott Long #error "Shouldn't Be Here!"
732b0a2fdeeSScott Long #define	MPT_IFLAGS		INTR_TYPE_CAM | INTR_ENTROPY | INTR_MPSAFE
733b0a2fdeeSScott Long #define	MPT_LOCK_SETUP(mpt)						\
734b0a2fdeeSScott Long 		mtx_init(&mpt->mpt_lock, "mpt", NULL, MTX_DEF);		\
735b0a2fdeeSScott Long 		mpt->mpt_locksetup = 1
736b0a2fdeeSScott Long #define	MPT_LOCK_DESTROY(mpt)						\
737b0a2fdeeSScott Long 	if (mpt->mpt_locksetup) {					\
738b0a2fdeeSScott Long 		mtx_destroy(&mpt->mpt_lock);				\
739b0a2fdeeSScott Long 		mpt->mpt_locksetup = 0;					\
740b0a2fdeeSScott Long 	}
741b0a2fdeeSScott Long 
742b0a2fdeeSScott Long #define	MPT_LOCK(mpt)		mtx_lock(&(mpt)->mpt_lock)
743b0a2fdeeSScott Long #define	MPT_UNLOCK(mpt)		mtx_unlock(&(mpt)->mpt_lock)
744b0a2fdeeSScott Long #define	MPTLOCK_2_CAMLOCK(mpt)	\
745b0a2fdeeSScott Long 	mtx_unlock(&(mpt)->mpt_lock); mtx_lock(&Giant)
746b0a2fdeeSScott Long #define	CAMLOCK_2_MPTLOCK(mpt)	\
747b0a2fdeeSScott Long 	mtx_unlock(&Giant); mtx_lock(&(mpt)->mpt_lock)
748b0a2fdeeSScott Long #define mpt_sleep(mpt, ident, priority, wmesg, timo) \
749b0a2fdeeSScott Long 	msleep(ident, &(mpt)->mpt_lock, priority, wmesg, timo)
750b0a2fdeeSScott Long #else
751b0a2fdeeSScott Long #define	MPT_IFLAGS		INTR_TYPE_CAM | INTR_ENTROPY
752b0a2fdeeSScott Long #define	MPT_LOCK_SETUP(mpt)	do { } while (0)
753b0a2fdeeSScott Long #define	MPT_LOCK_DESTROY(mpt)	do { } while (0)
754b0a2fdeeSScott Long #define	MPT_LOCK(mpt)		do { } while (0)
755b0a2fdeeSScott Long #define	MPT_UNLOCK(mpt)		do { } while (0)
756b0a2fdeeSScott Long #define	MPTLOCK_2_CAMLOCK(mpt)	do { } while (0)
757b0a2fdeeSScott Long #define	CAMLOCK_2_MPTLOCK(mpt)	do { } while (0)
758b0a2fdeeSScott Long #define mpt_sleep(mpt, ident, priority, wmesg, timo) \
759b0a2fdeeSScott Long 	tsleep(ident, priority, wmesg, timo)
760b0a2fdeeSScott Long #endif
761b0a2fdeeSScott Long #endif
762b0a2fdeeSScott Long 
763b0a2fdeeSScott Long /******************************* Register Access ******************************/
764b0a2fdeeSScott Long static __inline void mpt_write(struct mpt_softc *, size_t, uint32_t);
765b0a2fdeeSScott Long static __inline uint32_t mpt_read(struct mpt_softc *, int);
766b0a2fdeeSScott Long static __inline void mpt_pio_write(struct mpt_softc *, size_t, uint32_t);
767b0a2fdeeSScott Long static __inline uint32_t mpt_pio_read(struct mpt_softc *, int);
768b0a2fdeeSScott Long 
769b0a2fdeeSScott Long static __inline void
770b0a2fdeeSScott Long mpt_write(struct mpt_softc *mpt, size_t offset, uint32_t val)
771b0a2fdeeSScott Long {
772b0a2fdeeSScott Long 	bus_space_write_4(mpt->pci_st, mpt->pci_sh, offset, val);
773b0a2fdeeSScott Long }
774b0a2fdeeSScott Long 
775b0a2fdeeSScott Long static __inline uint32_t
776b0a2fdeeSScott Long mpt_read(struct mpt_softc *mpt, int offset)
777b0a2fdeeSScott Long {
778b0a2fdeeSScott Long 	return (bus_space_read_4(mpt->pci_st, mpt->pci_sh, offset));
779b0a2fdeeSScott Long }
780b0a2fdeeSScott Long 
781b0a2fdeeSScott Long /*
782b0a2fdeeSScott Long  * Some operations (e.g. diagnostic register writes while the ARM proccessor
783b0a2fdeeSScott Long  * is disabled), must be performed using "PCI pio" operations.  On non-PCI
784b0a2fdeeSScott Long  * busses, these operations likely map to normal register accesses.
785b0a2fdeeSScott Long  */
786b0a2fdeeSScott Long static __inline void
787b0a2fdeeSScott Long mpt_pio_write(struct mpt_softc *mpt, size_t offset, uint32_t val)
788b0a2fdeeSScott Long {
789b0a2fdeeSScott Long 	bus_space_write_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset, val);
790b0a2fdeeSScott Long }
791b0a2fdeeSScott Long 
792b0a2fdeeSScott Long static __inline uint32_t
793b0a2fdeeSScott Long mpt_pio_read(struct mpt_softc *mpt, int offset)
794b0a2fdeeSScott Long {
795b0a2fdeeSScott Long 	return (bus_space_read_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset));
796b0a2fdeeSScott Long }
797b0a2fdeeSScott Long /*********************** Reply Frame/Request Management ***********************/
798b0a2fdeeSScott Long /* Max MPT Reply we are willing to accept (must be power of 2) */
799444dd2b6SMatt Jacob #define MPT_REPLY_SIZE   	256
800b0a2fdeeSScott Long 
801c87e3f83SMatt Jacob /*
802c87e3f83SMatt Jacob  * Must be less than 16384 in order for target mode to work
803c87e3f83SMatt Jacob  */
804444dd2b6SMatt Jacob #define MPT_MAX_REQUESTS(mpt)	512
805b0a2fdeeSScott Long #define MPT_REQUEST_AREA	512
806444dd2b6SMatt Jacob #define MPT_SENSE_SIZE		32	/* included in MPT_REQUEST_AREA */
807b0a2fdeeSScott Long #define MPT_REQ_MEM_SIZE(mpt)	(MPT_MAX_REQUESTS(mpt) * MPT_REQUEST_AREA)
808b0a2fdeeSScott Long 
809c87e3f83SMatt Jacob /*
810c87e3f83SMatt Jacob  * Currently we try to pack both callbacks and request indices into 14 bits
811c87e3f83SMatt Jacob  * so that we don't have to get fancy when we get a target mode context
812c87e3f83SMatt Jacob  * reply (which only has 14 bits of IoIndex value) or a normal scsi
813c87e3f83SMatt Jacob  * initiator context reply (where we get bits 28..0 of context).
814c87e3f83SMatt Jacob  */
815c87e3f83SMatt Jacob #define MPT_CONTEXT_CB_SHIFT	(14)
816b0a2fdeeSScott Long #define MPT_CBI(handle)		(handle >> MPT_CONTEXT_CB_SHIFT)
817b0a2fdeeSScott Long #define MPT_CBI_TO_HID(cbi)	((cbi) << MPT_CONTEXT_CB_SHIFT)
818b0a2fdeeSScott Long #define MPT_CONTEXT_TO_CBI(x)	\
819b0a2fdeeSScott Long     (((x) >> MPT_CONTEXT_CB_SHIFT) & (MPT_NUM_REPLY_HANDLERS - 1))
820c87e3f83SMatt Jacob #define MPT_CONTEXT_REQI_MASK	0x3FFF
821c87e3f83SMatt Jacob #define MPT_CONTEXT_TO_REQI(x)	((x) & MPT_CONTEXT_REQI_MASK)
822b0a2fdeeSScott Long 
823b0a2fdeeSScott Long /*
824b0a2fdeeSScott Long  * Convert a 32bit physical address returned from IOC to an
825b0a2fdeeSScott Long  * offset into our reply frame memory or the kvm address needed
826b0a2fdeeSScott Long  * to access the data.  The returned address is only the low
827b0a2fdeeSScott Long  * 32 bits, so mask our base physical address accordingly.
828b0a2fdeeSScott Long  */
829b0a2fdeeSScott Long #define MPT_REPLY_BADDR(x)		\
830b0a2fdeeSScott Long 	(x << 1)
831b0a2fdeeSScott Long #define MPT_REPLY_OTOV(m, i) 		\
832b0a2fdeeSScott Long 	((void *)(&m->reply[i]))
833b0a2fdeeSScott Long 
834b0a2fdeeSScott Long #define	MPT_DUMP_REPLY_FRAME(mpt, reply_frame)		\
835b0a2fdeeSScott Long do {							\
836b0a2fdeeSScott Long 	if (mpt->verbose >= MPT_PRT_DEBUG)		\
837b0a2fdeeSScott Long 		mpt_dump_reply_frame(mpt, reply_frame);	\
838b0a2fdeeSScott Long } while(0)
839b0a2fdeeSScott Long 
840b0a2fdeeSScott Long static __inline uint32_t mpt_pop_reply_queue(struct mpt_softc *mpt);
841b0a2fdeeSScott Long static __inline void mpt_free_reply(struct mpt_softc *mpt, uint32_t ptr);
842b0a2fdeeSScott Long 
843b0a2fdeeSScott Long /*
844b0a2fdeeSScott Long  * Give the reply buffer back to the IOC after we have
845b0a2fdeeSScott Long  * finished processing it.
846b0a2fdeeSScott Long  */
847b0a2fdeeSScott Long static __inline void
848b0a2fdeeSScott Long mpt_free_reply(struct mpt_softc *mpt, uint32_t ptr)
849b0a2fdeeSScott Long {
850b0a2fdeeSScott Long      mpt_write(mpt, MPT_OFFSET_REPLY_Q, ptr);
851b0a2fdeeSScott Long }
852b0a2fdeeSScott Long 
853b0a2fdeeSScott Long /* Get a reply from the IOC */
854b0a2fdeeSScott Long static __inline uint32_t
855b0a2fdeeSScott Long mpt_pop_reply_queue(struct mpt_softc *mpt)
856b0a2fdeeSScott Long {
857b0a2fdeeSScott Long      return mpt_read(mpt, MPT_OFFSET_REPLY_Q);
858b0a2fdeeSScott Long }
859b0a2fdeeSScott Long 
860b0a2fdeeSScott Long void mpt_complete_request_chain(struct mpt_softc *mpt,
861b0a2fdeeSScott Long 				struct req_queue *chain, u_int iocstatus);
862b0a2fdeeSScott Long /************************** Scatter Gather Managment **************************/
863444dd2b6SMatt Jacob /* MPT_RQSL- size of request frame, in bytes */
864b0a2fdeeSScott Long #define	MPT_RQSL(mpt)		(mpt->request_frame_size << 2)
865b0a2fdeeSScott Long 
866444dd2b6SMatt Jacob /* MPT_NSGL- how many SG entries can fit in a request frame size */
867444dd2b6SMatt Jacob #define	MPT_NSGL(mpt)		(MPT_RQSL(mpt) / sizeof (SGE_IO_UNION))
868444dd2b6SMatt Jacob 
869444dd2b6SMatt Jacob /* MPT_NRFM- how many request frames can fit in each request alloc we make */
870444dd2b6SMatt Jacob #define	MPT_NRFM(mpt)		(MPT_REQUEST_AREA / MPT_RQSL(mpt))
871444dd2b6SMatt Jacob 
872444dd2b6SMatt Jacob /*
873444dd2b6SMatt Jacob  * MPT_NSGL_FIRST- # of SG elements that can fit after
874444dd2b6SMatt Jacob  * an I/O request but still within the request frame.
875444dd2b6SMatt Jacob  * Do this safely based upon SGE_IO_UNION.
876444dd2b6SMatt Jacob  *
877444dd2b6SMatt Jacob  * Note that the first element is *within* the SCSI request.
878444dd2b6SMatt Jacob  */
879b0a2fdeeSScott Long #define	MPT_NSGL_FIRST(mpt)	\
880444dd2b6SMatt Jacob     ((MPT_RQSL(mpt) - sizeof (MSG_SCSI_IO_REQUEST) + sizeof (SGE_IO_UNION)) / \
881444dd2b6SMatt Jacob     sizeof (SGE_IO_UNION))
882b0a2fdeeSScott Long 
883b0a2fdeeSScott Long /***************************** IOC Initialization *****************************/
884b0a2fdeeSScott Long int mpt_reset(struct mpt_softc *, int /*reinit*/);
885b0a2fdeeSScott Long 
886c87e3f83SMatt Jacob /****************************** Debugging ************************************/
887b0a2fdeeSScott Long typedef struct mpt_decode_entry {
888b0a2fdeeSScott Long 	char    *name;
889b0a2fdeeSScott Long 	u_int	 value;
890b0a2fdeeSScott Long 	u_int	 mask;
891b0a2fdeeSScott Long } mpt_decode_entry_t;
892b0a2fdeeSScott Long 
893b0a2fdeeSScott Long int mpt_decode_value(mpt_decode_entry_t *table, u_int num_entries,
894b0a2fdeeSScott Long 		     const char *name, u_int value, u_int *cur_column,
895b0a2fdeeSScott Long 		     u_int wrap_point);
896b0a2fdeeSScott Long 
897b0a2fdeeSScott Long enum {
898b0a2fdeeSScott Long 	MPT_PRT_ALWAYS,
899b0a2fdeeSScott Long 	MPT_PRT_FATAL,
900b0a2fdeeSScott Long 	MPT_PRT_ERROR,
901b0a2fdeeSScott Long 	MPT_PRT_WARN,
902b0a2fdeeSScott Long 	MPT_PRT_INFO,
903b0a2fdeeSScott Long 	MPT_PRT_DEBUG,
904c87e3f83SMatt Jacob 	MPT_PRT_DEBUG1,
905c87e3f83SMatt Jacob 	MPT_PRT_DEBUG2,
906c87e3f83SMatt Jacob 	MPT_PRT_DEBUG3,
907444dd2b6SMatt Jacob 	MPT_PRT_TRACE,
908444dd2b6SMatt Jacob 	MPT_PRT_NONE=100
909b0a2fdeeSScott Long };
910b0a2fdeeSScott Long 
911c87e3f83SMatt Jacob #if __FreeBSD_version > 500000
912b0a2fdeeSScott Long #define mpt_lprt(mpt, level, ...)		\
913b0a2fdeeSScott Long do {						\
914b0a2fdeeSScott Long 	if (level <= (mpt)->verbose)		\
915b0a2fdeeSScott Long 		mpt_prt(mpt, __VA_ARGS__);	\
916b0a2fdeeSScott Long } while (0)
917b0a2fdeeSScott Long 
918b0a2fdeeSScott Long #define mpt_lprtc(mpt, level, ...)		 \
919b0a2fdeeSScott Long do {						 \
920b0a2fdeeSScott Long 	if (level <= (mpt)->debug_level)	 \
921b0a2fdeeSScott Long 		mpt_prtc(mpt, __VA_ARGS__);	 \
922b0a2fdeeSScott Long } while (0)
923c87e3f83SMatt Jacob #else
924c87e3f83SMatt Jacob void mpt_lprt(struct mpt_softc *, int, const char *, ...)
925c87e3f83SMatt Jacob 	__printflike(3, 4);
926c87e3f83SMatt Jacob void mpt_lprtc(struct mpt_softc *, int, const char *, ...)
927c87e3f83SMatt Jacob 	__printflike(3, 4);
928c87e3f83SMatt Jacob #endif
929c87e3f83SMatt Jacob void mpt_prt(struct mpt_softc *, const char *, ...)
930c87e3f83SMatt Jacob 	__printflike(2, 3);
931c87e3f83SMatt Jacob void mpt_prtc(struct mpt_softc *, const char *, ...)
932c87e3f83SMatt Jacob 	__printflike(2, 3);
933b0a2fdeeSScott Long 
934c87e3f83SMatt Jacob /**************************** Target Mode Related ***************************/
935c87e3f83SMatt Jacob static __inline int mpt_cdblen(uint8_t, int);
936c87e3f83SMatt Jacob static __inline int
937c87e3f83SMatt Jacob mpt_cdblen(uint8_t cdb0, int maxlen)
938c87e3f83SMatt Jacob {
939c87e3f83SMatt Jacob 	int group = cdb0 >> 5;
940c87e3f83SMatt Jacob 	switch (group) {
941c87e3f83SMatt Jacob 	case 0:
942c87e3f83SMatt Jacob 		return (6);
943c87e3f83SMatt Jacob 	case 1:
944c87e3f83SMatt Jacob 		return (10);
945c87e3f83SMatt Jacob 	case 4:
946c87e3f83SMatt Jacob 	case 5:
947c87e3f83SMatt Jacob 		return (12);
948c87e3f83SMatt Jacob 	default:
949c87e3f83SMatt Jacob 		return (16);
950c87e3f83SMatt Jacob 	}
951c87e3f83SMatt Jacob }
952c87e3f83SMatt Jacob #ifdef	INVARIANTS
953c87e3f83SMatt Jacob static __inline request_t * mpt_tag_2_req(struct mpt_softc *, uint32_t);
954c87e3f83SMatt Jacob static __inline request_t *
955c87e3f83SMatt Jacob mpt_tag_2_req(struct mpt_softc *mpt, uint32_t tag)
956c87e3f83SMatt Jacob {
957c87e3f83SMatt Jacob 	uint16_t rtg = (tag >> 16);
958c87e3f83SMatt Jacob 	KASSERT(rtg < mpt->tgt_cmds_allocated, ("bad tag %d\n", tag));
959c87e3f83SMatt Jacob 	KASSERT(mpt->tgt_cmd_ptrs, ("no cmd backpointer array"));
960c87e3f83SMatt Jacob 	KASSERT(mpt->tgt_cmd_ptrs[rtg], ("no cmd backpointer"));
961c87e3f83SMatt Jacob 	return (mpt->tgt_cmd_ptrs[rtg]);
962c87e3f83SMatt Jacob }
963c87e3f83SMatt Jacob #endif
964c87e3f83SMatt Jacob 
965c87e3f83SMatt Jacob typedef enum {
966c87e3f83SMatt Jacob 	MPT_ABORT_TASK_SET=1234,
967c87e3f83SMatt Jacob 	MPT_CLEAR_TASK_SET,
968c87e3f83SMatt Jacob 	MPT_TARGET_RESET,
969c87e3f83SMatt Jacob 	MPT_CLEAR_ACA,
970c87e3f83SMatt Jacob 	MPT_TERMINATE_TASK,
971c87e3f83SMatt Jacob 	MPT_NIL_TMT_VALUE=5678
972c87e3f83SMatt Jacob } mpt_task_mgmt_t;
973b0a2fdeeSScott Long 
974b0a2fdeeSScott Long /**************************** Unclassified Routines ***************************/
975b0a2fdeeSScott Long void		mpt_send_cmd(struct mpt_softc *mpt, request_t *req);
976b0a2fdeeSScott Long int		mpt_recv_handshake_reply(struct mpt_softc *mpt,
977b0a2fdeeSScott Long 					 size_t reply_len, void *reply);
978b0a2fdeeSScott Long int		mpt_wait_req(struct mpt_softc *mpt, request_t *req,
979b0a2fdeeSScott Long 			     mpt_req_state_t state, mpt_req_state_t mask,
980b0a2fdeeSScott Long 			     int sleep_ok, int time_ms);
981b0a2fdeeSScott Long void		mpt_enable_ints(struct mpt_softc *mpt);
982b0a2fdeeSScott Long void		mpt_disable_ints(struct mpt_softc *mpt);
983b0a2fdeeSScott Long int		mpt_attach(struct mpt_softc *mpt);
984b0a2fdeeSScott Long int		mpt_shutdown(struct mpt_softc *mpt);
985b0a2fdeeSScott Long int		mpt_detach(struct mpt_softc *mpt);
986b0a2fdeeSScott Long int		mpt_send_handshake_cmd(struct mpt_softc *mpt,
987b0a2fdeeSScott Long 				       size_t len, void *cmd);
988b0a2fdeeSScott Long request_t *	mpt_get_request(struct mpt_softc *mpt, int sleep_ok);
989b0a2fdeeSScott Long void		mpt_free_request(struct mpt_softc *mpt, request_t *req);
990b0a2fdeeSScott Long void		mpt_intr(void *arg);
991b0a2fdeeSScott Long void		mpt_check_doorbell(struct mpt_softc *mpt);
992b0a2fdeeSScott Long void		mpt_dump_reply_frame(struct mpt_softc *mpt,
993b0a2fdeeSScott Long 				     MSG_DEFAULT_REPLY *reply_frame);
994b0a2fdeeSScott Long 
995b0a2fdeeSScott Long void		mpt_set_config_regs(struct mpt_softc *);
996b0a2fdeeSScott Long int		mpt_issue_cfg_req(struct mpt_softc */*mpt*/, request_t */*req*/,
997b0a2fdeeSScott Long 				  u_int /*Action*/, u_int /*PageVersion*/,
998b0a2fdeeSScott Long 				  u_int /*PageLength*/, u_int /*PageNumber*/,
999b0a2fdeeSScott Long 				  u_int /*PageType*/, uint32_t /*PageAddress*/,
1000b0a2fdeeSScott Long 				  bus_addr_t /*addr*/, bus_size_t/*len*/,
1001b0a2fdeeSScott Long 				  int /*sleep_ok*/, int /*timeout_ms*/);
1002b0a2fdeeSScott Long int		mpt_read_cfg_header(struct mpt_softc *, int /*PageType*/,
1003b0a2fdeeSScott Long 				    int /*PageNumber*/,
1004b0a2fdeeSScott Long 				    uint32_t /*PageAddress*/,
1005b0a2fdeeSScott Long 				    CONFIG_PAGE_HEADER *,
1006b0a2fdeeSScott Long 				    int /*sleep_ok*/, int /*timeout_ms*/);
1007b0a2fdeeSScott Long int		mpt_read_cfg_page(struct mpt_softc *t, int /*Action*/,
1008b0a2fdeeSScott Long 				  uint32_t /*PageAddress*/,
1009b0a2fdeeSScott Long 				  CONFIG_PAGE_HEADER *, size_t /*len*/,
1010b0a2fdeeSScott Long 				  int /*sleep_ok*/, int /*timeout_ms*/);
1011b0a2fdeeSScott Long int		mpt_write_cfg_page(struct mpt_softc *, int /*Action*/,
1012b0a2fdeeSScott Long 				   uint32_t /*PageAddress*/,
1013b0a2fdeeSScott Long 				   CONFIG_PAGE_HEADER *, size_t /*len*/,
1014b0a2fdeeSScott Long 				   int /*sleep_ok*/, int /*timeout_ms*/);
1015b0a2fdeeSScott Long static __inline int
1016b0a2fdeeSScott Long mpt_read_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress,
1017b0a2fdeeSScott Long 		      CONFIG_PAGE_HEADER *hdr, size_t len,
1018b0a2fdeeSScott Long 		      int sleep_ok, int timeout_ms)
1019b0a2fdeeSScott Long {
1020b0a2fdeeSScott Long 	return (mpt_read_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_READ_CURRENT,
1021b0a2fdeeSScott Long 				  PageAddress, hdr, len, sleep_ok, timeout_ms));
1022b0a2fdeeSScott Long }
1023b0a2fdeeSScott Long 
1024b0a2fdeeSScott Long static __inline int
1025b0a2fdeeSScott Long mpt_write_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress,
1026b0a2fdeeSScott Long 		       CONFIG_PAGE_HEADER *hdr, size_t len, int sleep_ok,
1027b0a2fdeeSScott Long 		       int timeout_ms)
1028b0a2fdeeSScott Long {
1029b0a2fdeeSScott Long 	return (mpt_write_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT,
1030b0a2fdeeSScott Long 				   PageAddress, hdr, len, sleep_ok,
1031b0a2fdeeSScott Long 				   timeout_ms));
1032b0a2fdeeSScott Long }
1033ce68dae5SMatt Jacob 
10349b631363SMatt Jacob /* mpt_debug.c functions */
10359b631363SMatt Jacob void mpt_print_reply(void *vmsg);
1036b0a2fdeeSScott Long void mpt_print_db(uint32_t mb);
10379b631363SMatt Jacob void mpt_print_config_reply(void *vmsg);
1038b0a2fdeeSScott Long char *mpt_ioc_diag(uint32_t diag);
1039b0a2fdeeSScott Long void mpt_req_state(mpt_req_state_t state);
10409b631363SMatt Jacob void mpt_print_config_request(void *vmsg);
10419b631363SMatt Jacob void mpt_print_request(void *vmsg);
1042b0a2fdeeSScott Long void mpt_print_scsi_io_request(MSG_SCSI_IO_REQUEST *msg);
1043444dd2b6SMatt Jacob void mpt_dump_sgl(SGE_IO_UNION *se, int offset);
10449b631363SMatt Jacob #endif /* _MPT_H_ */
1045