xref: /freebsd/sys/dev/mpt/mpt.h (revision cd23a6e0198d96c39ce501b2528632e91c8d0a19)
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.
61ec5fe39dSMatt Jacob  *
62ec5fe39dSMatt Jacob  *
63ec5fe39dSMatt Jacob  * Support from LSI-Logic has also gone a great deal toward making this a
64ec5fe39dSMatt Jacob  * workable subsystem and is gratefully acknowledged.
659b631363SMatt Jacob  */
669b631363SMatt Jacob /*
67b0a2fdeeSScott Long  * Copyright (c) 2004, Avid Technology, Inc. and its contributors.
68b0a2fdeeSScott Long  * Copyright (c) 2004, 2005 Justin T. Gibbs
69b0a2fdeeSScott Long  * Copyright (c) 2005, WHEEL Sp. z o.o.
70b0a2fdeeSScott Long  * All rights reserved.
71b0a2fdeeSScott Long  *
72b0a2fdeeSScott Long  * Redistribution and use in source and binary forms, with or without
73b0a2fdeeSScott Long  * modification, are permitted provided that the following conditions are
74b0a2fdeeSScott Long  * met:
75b0a2fdeeSScott Long  * 1. Redistributions of source code must retain the above copyright
76b0a2fdeeSScott Long  *    notice, this list of conditions and the following disclaimer.
77b0a2fdeeSScott Long  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
78b0a2fdeeSScott Long  *    substantially similar to the "NO WARRANTY" disclaimer below
79b0a2fdeeSScott Long  *    ("Disclaimer") and any redistribution must be conditioned upon including
80b0a2fdeeSScott Long  *    a substantially similar Disclaimer requirement for further binary
81b0a2fdeeSScott Long  *    redistribution.
82286e947fSJustin T. Gibbs  * 3. Neither the names of the above listed copyright holders nor the names
83286e947fSJustin T. Gibbs  *    of any contributors may be used to endorse or promote products derived
84286e947fSJustin T. Gibbs  *    from this software without specific prior written permission.
85b0a2fdeeSScott Long  *
86b0a2fdeeSScott Long  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
87b0a2fdeeSScott Long  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
88b0a2fdeeSScott Long  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
89b0a2fdeeSScott Long  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
90b0a2fdeeSScott Long  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
91b0a2fdeeSScott Long  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
92b0a2fdeeSScott Long  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
93b0a2fdeeSScott Long  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
94b0a2fdeeSScott Long  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
95b0a2fdeeSScott Long  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
96b0a2fdeeSScott Long  * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
979b631363SMatt Jacob  */
989b631363SMatt Jacob 
999b631363SMatt Jacob #ifndef _MPT_H_
1009b631363SMatt Jacob #define _MPT_H_
101b0a2fdeeSScott Long 
102b0a2fdeeSScott Long /********************************* OS Includes ********************************/
103b0a2fdeeSScott Long #include <sys/types.h>
104b0a2fdeeSScott Long #include <sys/param.h>
105b0a2fdeeSScott Long #include <sys/systm.h>
106b0a2fdeeSScott Long #include <sys/endian.h>
107b0a2fdeeSScott Long #include <sys/eventhandler.h>
108b0a2fdeeSScott Long #if __FreeBSD_version < 500000
109b0a2fdeeSScott Long #include <sys/kernel.h>
110b0a2fdeeSScott Long #include <sys/queue.h>
111b0a2fdeeSScott Long #include <sys/malloc.h>
112d0a68c27SMatt Jacob #include <sys/devicestat.h>
113b0a2fdeeSScott Long #else
114b0a2fdeeSScott Long #include <sys/lock.h>
115b0a2fdeeSScott Long #include <sys/kernel.h>
116b0a2fdeeSScott Long #include <sys/queue.h>
117b0a2fdeeSScott Long #include <sys/malloc.h>
118b0a2fdeeSScott Long #include <sys/mutex.h>
119b0a2fdeeSScott Long #include <sys/condvar.h>
120b0a2fdeeSScott Long #endif
121b0a2fdeeSScott Long #include <sys/proc.h>
122b0a2fdeeSScott Long #include <sys/bus.h>
123b0a2fdeeSScott Long #include <sys/module.h>
124b0a2fdeeSScott Long 
125b0a2fdeeSScott Long #include <machine/cpu.h>
126b0a2fdeeSScott Long #include <machine/resource.h>
127b0a2fdeeSScott Long 
128c87e3f83SMatt Jacob #if __FreeBSD_version < 500000
129c87e3f83SMatt Jacob #include <machine/bus.h>
1306dea56baSMatt Jacob #include <machine/clock.h>
131c87e3f83SMatt Jacob #endif
132c87e3f83SMatt Jacob 
1338ba5efbdSMarius Strobl #ifdef __sparc64__
1348ba5efbdSMarius Strobl #include <dev/ofw/openfirm.h>
1358ba5efbdSMarius Strobl #include <machine/ofw_machdep.h>
1368ba5efbdSMarius Strobl #endif
1378ba5efbdSMarius Strobl 
138b0a2fdeeSScott Long #include <sys/rman.h>
139b0a2fdeeSScott Long 
140444dd2b6SMatt Jacob #if __FreeBSD_version < 500000
141444dd2b6SMatt Jacob #include <pci/pcireg.h>
142444dd2b6SMatt Jacob #include <pci/pcivar.h>
143444dd2b6SMatt Jacob #else
144444dd2b6SMatt Jacob #include <dev/pci/pcireg.h>
145444dd2b6SMatt Jacob #include <dev/pci/pcivar.h>
146444dd2b6SMatt Jacob #endif
147444dd2b6SMatt Jacob 
148444dd2b6SMatt Jacob #include <machine/bus.h>
149b0a2fdeeSScott Long #include "opt_ddb.h"
150b0a2fdeeSScott Long 
151b0a2fdeeSScott Long /**************************** Register Definitions ****************************/
152b0a2fdeeSScott Long #include <dev/mpt/mpt_reg.h>
153b0a2fdeeSScott Long 
154b0a2fdeeSScott Long /******************************* MPI Definitions ******************************/
155b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_type.h>
156b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi.h>
157b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_cnfg.h>
158b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_ioc.h>
159b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_raid.h>
160b0a2fdeeSScott Long 
161b0a2fdeeSScott Long /* XXX For mpt_debug.c */
162b0a2fdeeSScott Long #include <dev/mpt/mpilib/mpi_init.h>
163b0a2fdeeSScott Long 
1640e0521a1SMatt Jacob #define	MPT_S64_2_SCALAR(y)	((((int64_t)y.High) << 32) | (y.Low))
1650e0521a1SMatt Jacob #define	MPT_U64_2_SCALAR(y)	((((uint64_t)y.High) << 32) | (y.Low))
1660e0521a1SMatt Jacob 
167b0a2fdeeSScott Long /****************************** Misc Definitions ******************************/
168a2baed97SMatt Jacob /* #define MPT_TEST_MULTIPATH	1 */
1699b631363SMatt Jacob #define MPT_OK (0)
1709b631363SMatt Jacob #define MPT_FAIL (0x10000)
1719b631363SMatt Jacob 
172b0a2fdeeSScott Long #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array))
1739b631363SMatt Jacob 
174c87e3f83SMatt Jacob #define	MPT_ROLE_NONE		0
175c87e3f83SMatt Jacob #define	MPT_ROLE_INITIATOR	1
176c87e3f83SMatt Jacob #define	MPT_ROLE_TARGET		2
177c87e3f83SMatt Jacob #define	MPT_ROLE_BOTH		3
178c87e3f83SMatt Jacob #define	MPT_ROLE_DEFAULT	MPT_ROLE_INITIATOR
179c87e3f83SMatt Jacob 
1808ba5efbdSMarius Strobl #define	MPT_INI_ID_NONE		-1
1818ba5efbdSMarius Strobl 
182b0a2fdeeSScott Long /**************************** Forward Declarations ****************************/
183b0a2fdeeSScott Long struct mpt_softc;
184b0a2fdeeSScott Long struct mpt_personality;
185b0a2fdeeSScott Long typedef struct req_entry request_t;
1869b631363SMatt Jacob 
187b0a2fdeeSScott Long /************************* Personality Module Support *************************/
188b0a2fdeeSScott Long typedef int mpt_load_handler_t(struct mpt_personality *);
189b0a2fdeeSScott Long typedef int mpt_probe_handler_t(struct mpt_softc *);
190b0a2fdeeSScott Long typedef int mpt_attach_handler_t(struct mpt_softc *);
191c87e3f83SMatt Jacob typedef int mpt_enable_handler_t(struct mpt_softc *);
192a7303be1SMatt Jacob typedef void mpt_ready_handler_t(struct mpt_softc *);
193b0a2fdeeSScott Long typedef int mpt_event_handler_t(struct mpt_softc *, request_t *,
194b0a2fdeeSScott Long 				MSG_EVENT_NOTIFY_REPLY *);
195b0a2fdeeSScott Long typedef void mpt_reset_handler_t(struct mpt_softc *, int /*type*/);
196b0a2fdeeSScott Long /* XXX Add return value and use for veto? */
197b0a2fdeeSScott Long typedef void mpt_shutdown_handler_t(struct mpt_softc *);
198b0a2fdeeSScott Long typedef void mpt_detach_handler_t(struct mpt_softc *);
199b0a2fdeeSScott Long typedef int mpt_unload_handler_t(struct mpt_personality *);
200b0a2fdeeSScott Long 
201b0a2fdeeSScott Long struct mpt_personality
202b0a2fdeeSScott Long {
203b0a2fdeeSScott Long 	const char		*name;
204b0a2fdeeSScott Long 	uint32_t		 id;		/* Assigned identifier. */
205b0a2fdeeSScott Long 	u_int			 use_count;	/* Instances using personality*/
206b0a2fdeeSScott Long 	mpt_load_handler_t	*load;		/* configure personailty */
207b0a2fdeeSScott Long #define MPT_PERS_FIRST_HANDLER(pers) (&(pers)->load)
208b0a2fdeeSScott Long 	mpt_probe_handler_t	*probe;		/* configure personailty */
209b0a2fdeeSScott Long 	mpt_attach_handler_t	*attach;	/* initialize device instance */
210c87e3f83SMatt Jacob 	mpt_enable_handler_t	*enable;	/* enable device */
211a7303be1SMatt Jacob 	mpt_ready_handler_t	*ready;		/* final open for business */
212b0a2fdeeSScott Long 	mpt_event_handler_t	*event;		/* Handle MPI event. */
213b0a2fdeeSScott Long 	mpt_reset_handler_t	*reset;		/* Re-init after reset. */
214b0a2fdeeSScott Long 	mpt_shutdown_handler_t	*shutdown;	/* Shutdown instance. */
215b0a2fdeeSScott Long 	mpt_detach_handler_t	*detach;	/* release device instance */
216b0a2fdeeSScott Long 	mpt_unload_handler_t	*unload;	/* Shutdown personality */
217b0a2fdeeSScott Long #define MPT_PERS_LAST_HANDLER(pers) (&(pers)->unload)
2189b631363SMatt Jacob };
2199b631363SMatt Jacob 
220b0a2fdeeSScott Long int mpt_modevent(module_t, int, void *);
2219b631363SMatt Jacob 
222b0a2fdeeSScott Long /* Maximum supported number of personalities. */
223b0a2fdeeSScott Long #define MPT_MAX_PERSONALITIES	(15)
2249b631363SMatt Jacob 
225b0a2fdeeSScott Long #define MPT_PERSONALITY_DEPEND(name, dep, vmin, vpref, vmax) \
226b0a2fdeeSScott Long 	MODULE_DEPEND(name, dep, vmin, vpref, vmax)
227b0a2fdeeSScott Long 
228b0a2fdeeSScott Long #define DECLARE_MPT_PERSONALITY(name, order)				  \
229b0a2fdeeSScott Long 	static moduledata_t name##_mod = {				  \
230b0a2fdeeSScott Long 		#name, mpt_modevent, &name##_personality		  \
231b0a2fdeeSScott Long 	};								  \
232b0a2fdeeSScott Long 	DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, order);	  \
233b0a2fdeeSScott Long 	MODULE_VERSION(name, 1);					  \
234b0a2fdeeSScott Long 	MPT_PERSONALITY_DEPEND(name, mpt_core, 1, 1, 1)
235b0a2fdeeSScott Long 
236b0a2fdeeSScott Long /******************************* Bus DMA Support ******************************/
237b0a2fdeeSScott Long /* XXX Need to update bus_dmamap_sync to take a range argument. */
238b0a2fdeeSScott Long #define bus_dmamap_sync_range(dma_tag, dmamap, offset, len, op)	\
239b0a2fdeeSScott Long 	bus_dmamap_sync(dma_tag, dmamap, op)
240b0a2fdeeSScott Long 
241fa80feeeSMatt Jacob #if __FreeBSD_version < 600000
242fa80feeeSMatt Jacob #define	bus_get_dma_tag(x)	NULL
243fa80feeeSMatt Jacob #endif
244b0a2fdeeSScott Long #if __FreeBSD_version >= 501102
245b0a2fdeeSScott Long #define mpt_dma_tag_create(mpt, parent_tag, alignment, boundary,	\
246b0a2fdeeSScott Long 			   lowaddr, highaddr, filter, filterarg,	\
247b0a2fdeeSScott Long 			   maxsize, nsegments, maxsegsz, flags,		\
248b0a2fdeeSScott Long 			   dma_tagp)					\
249b0a2fdeeSScott Long 	bus_dma_tag_create(parent_tag, alignment, boundary,		\
250b0a2fdeeSScott Long 			   lowaddr, highaddr, filter, filterarg,	\
251b0a2fdeeSScott Long 			   maxsize, nsegments, maxsegsz, flags,		\
252d0a68c27SMatt Jacob 			   busdma_lock_mutex, &(mpt)->mpt_lock,		\
253b0a2fdeeSScott Long 			   dma_tagp)
254b0a2fdeeSScott Long #else
255b0a2fdeeSScott Long #define mpt_dma_tag_create(mpt, parent_tag, alignment, boundary,	\
256b0a2fdeeSScott Long 			   lowaddr, highaddr, filter, filterarg,	\
257b0a2fdeeSScott Long 			   maxsize, nsegments, maxsegsz, flags,		\
258b0a2fdeeSScott Long 			   dma_tagp)					\
259b0a2fdeeSScott Long 	bus_dma_tag_create(parent_tag, alignment, boundary,		\
260b0a2fdeeSScott Long 			   lowaddr, highaddr, filter, filterarg,	\
261b0a2fdeeSScott Long 			   maxsize, nsegments, maxsegsz, flags,		\
262b0a2fdeeSScott Long 			   dma_tagp)
263b0a2fdeeSScott Long #endif
264b0a2fdeeSScott Long 
265b0a2fdeeSScott Long struct mpt_map_info {
266b0a2fdeeSScott Long 	struct mpt_softc *mpt;
267b0a2fdeeSScott Long 	int		  error;
268b0a2fdeeSScott Long 	uint32_t	  phys;
269b0a2fdeeSScott Long };
270b0a2fdeeSScott Long 
271b0a2fdeeSScott Long void mpt_map_rquest(void *, bus_dma_segment_t *, int, int);
2725f538376SMatt Jacob /* **************************** NewBUS interrupt Crock ************************/
2735f538376SMatt Jacob #if __FreeBSD_version < 700031
2745f538376SMatt Jacob #define	mpt_setup_intr(d, i, f, U, if, ifa, hp)	\
2755f538376SMatt Jacob 	bus_setup_intr(d, i, f, if, ifa, hp)
2765f538376SMatt Jacob #else
2775f538376SMatt Jacob #define	mpt_setup_intr	bus_setup_intr
2785f538376SMatt Jacob #endif
279b0a2fdeeSScott Long 
280a41aabe2SJung-uk Kim /* **************************** NewBUS CAM Support ****************************/
281a41aabe2SJung-uk Kim #if __FreeBSD_version < 700049
282a41aabe2SJung-uk Kim #define mpt_xpt_bus_register(sim, parent, bus)	\
283a41aabe2SJung-uk Kim 	xpt_bus_register(sim, bus)
284a41aabe2SJung-uk Kim #else
285a41aabe2SJung-uk Kim #define mpt_xpt_bus_register	xpt_bus_register
286a41aabe2SJung-uk Kim #endif
287a41aabe2SJung-uk Kim 
288b0a2fdeeSScott Long /**************************** Kernel Thread Support ***************************/
289e1ff3d50SJulian Elischer #if __FreeBSD_version > 800001
290b0a2fdeeSScott Long #define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \
2913745c395SJulian Elischer 	kproc_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg)
292a41aabe2SJung-uk Kim #define	mpt_kthread_exit(status)	\
293a41aabe2SJung-uk Kim 	kproc_exit(status)
294a41aabe2SJung-uk Kim #elif __FreeBSD_version > 500005
295b0a2fdeeSScott Long #define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \
296e1ff3d50SJulian Elischer 	kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg)
297a41aabe2SJung-uk Kim #define	mpt_kthread_exit(status)	\
298a41aabe2SJung-uk Kim 	kthread_exit(status)
299e1ff3d50SJulian Elischer #else
300e1ff3d50SJulian Elischer #define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \
301e1ff3d50SJulian Elischer 	kthread_create(func, farg, proc_ptr, fmtstr, arg)
302a41aabe2SJung-uk Kim #define	mpt_kthread_exit(status)	\
303a41aabe2SJung-uk Kim 	kthread_exit(status)
304b0a2fdeeSScott Long #endif
305b0a2fdeeSScott Long 
306b0a2fdeeSScott Long /********************************** Endianess *********************************/
3070e0521a1SMatt Jacob #define	MPT_2_HOST64(ptr, tag)	ptr->tag = le64toh(ptr->tag)
3080e0521a1SMatt Jacob #define	MPT_2_HOST32(ptr, tag)	ptr->tag = le32toh(ptr->tag)
3090e0521a1SMatt Jacob #define	MPT_2_HOST16(ptr, tag)	ptr->tag = le16toh(ptr->tag)
310b0a2fdeeSScott Long 
3110e0521a1SMatt Jacob #define	HOST_2_MPT64(ptr, tag)	ptr->tag = htole64(ptr->tag)
3120e0521a1SMatt Jacob #define	HOST_2_MPT32(ptr, tag)	ptr->tag = htole32(ptr->tag)
3130e0521a1SMatt Jacob #define	HOST_2_MPT16(ptr, tag)	ptr->tag = htole16(ptr->tag)
3140e0521a1SMatt Jacob 
3157185cd36SMatt Jacob #if	_BYTE_ORDER == _BIG_ENDIAN
3160e0521a1SMatt Jacob void mpt2host_sge_simple_union(SGE_SIMPLE_UNION *);
3170e0521a1SMatt Jacob void mpt2host_iocfacts_reply(MSG_IOC_FACTS_REPLY *);
3180e0521a1SMatt Jacob void mpt2host_portfacts_reply(MSG_PORT_FACTS_REPLY *);
3190e0521a1SMatt Jacob void mpt2host_config_page_ioc2(CONFIG_PAGE_IOC_2 *);
3207ee37807SMarius Strobl void mpt2host_config_page_ioc3(CONFIG_PAGE_IOC_3 *);
3217ee37807SMarius Strobl void mpt2host_config_page_scsi_port_0(CONFIG_PAGE_SCSI_PORT_0 *);
3227ee37807SMarius Strobl void mpt2host_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *);
3237ee37807SMarius Strobl void host2mpt_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *);
3247ee37807SMarius Strobl void mpt2host_config_page_scsi_port_2(CONFIG_PAGE_SCSI_PORT_2 *);
3257ee37807SMarius Strobl void mpt2host_config_page_scsi_device_0(CONFIG_PAGE_SCSI_DEVICE_0 *);
3267ee37807SMarius Strobl void mpt2host_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *);
3277ee37807SMarius Strobl void host2mpt_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *);
3287ee37807SMarius Strobl void mpt2host_config_page_fc_port_0(CONFIG_PAGE_FC_PORT_0 *);
3297ee37807SMarius Strobl void mpt2host_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *);
3307ee37807SMarius Strobl void host2mpt_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *);
3310e0521a1SMatt Jacob void mpt2host_config_page_raid_vol_0(CONFIG_PAGE_RAID_VOL_0 *);
3327ee37807SMarius Strobl void mpt2host_config_page_raid_phys_disk_0(CONFIG_PAGE_RAID_PHYS_DISK_0 *);
3330e0521a1SMatt Jacob void mpt2host_mpi_raid_vol_indicator(MPI_RAID_VOL_INDICATOR *);
3347185cd36SMatt Jacob #else
3357185cd36SMatt Jacob #define	mpt2host_sge_simple_union(x)		do { ; } while (0)
3367185cd36SMatt Jacob #define	mpt2host_iocfacts_reply(x)		do { ; } while (0)
3377185cd36SMatt Jacob #define	mpt2host_portfacts_reply(x)		do { ; } while (0)
3387185cd36SMatt Jacob #define	mpt2host_config_page_ioc2(x)		do { ; } while (0)
3397ee37807SMarius Strobl #define	mpt2host_config_page_ioc3(x)		do { ; } while (0)
3407ee37807SMarius Strobl #define	mpt2host_config_page_scsi_port_0(x)	do { ; } while (0)
3417ee37807SMarius Strobl #define	mpt2host_config_page_scsi_port_1(x)	do { ; } while (0)
3427ee37807SMarius Strobl #define	host2mpt_config_page_scsi_port_1(x)	do { ; } while (0)
3437ee37807SMarius Strobl #define	mpt2host_config_page_scsi_port_2(x)	do { ; } while (0)
3447ee37807SMarius Strobl #define	mpt2host_config_page_scsi_device_0(x)	do { ; } while (0)
3457ee37807SMarius Strobl #define	mpt2host_config_page_scsi_device_1(x)	do { ; } while (0)
3467ee37807SMarius Strobl #define	host2mpt_config_page_scsi_device_1(x)	do { ; } while (0)
3477ee37807SMarius Strobl #define	mpt2host_config_page_fc_port_0(x)	do { ; } while (0)
3487ee37807SMarius Strobl #define	mpt2host_config_page_fc_port_1(x)	do { ; } while (0)
3497ee37807SMarius Strobl #define	host2mpt_config_page_fc_port_1(x)	do { ; } while (0)
3507185cd36SMatt Jacob #define	mpt2host_config_page_raid_vol_0(x)	do { ; } while (0)
3517ee37807SMarius Strobl #define	mpt2host_config_page_raid_phys_disk_0(x)			\
3527ee37807SMarius Strobl 	do { ; } while (0)
3537185cd36SMatt Jacob #define	mpt2host_mpi_raid_vol_indicator(x)	do { ; } while (0)
3540e0521a1SMatt Jacob #endif
355b0a2fdeeSScott Long 
356b0a2fdeeSScott Long /**************************** MPI Transaction State ***************************/
357b0a2fdeeSScott Long typedef enum {
3585e073106SMatt Jacob 	REQ_STATE_NIL		= 0x00,
3595e073106SMatt Jacob 	REQ_STATE_FREE		= 0x01,
3605e073106SMatt Jacob 	REQ_STATE_ALLOCATED	= 0x02,
3615e073106SMatt Jacob 	REQ_STATE_QUEUED	= 0x04,
3625e073106SMatt Jacob 	REQ_STATE_DONE		= 0x08,
3635e073106SMatt Jacob 	REQ_STATE_TIMEDOUT	= 0x10,
3645e073106SMatt Jacob 	REQ_STATE_NEED_WAKEUP	= 0x20,
3655e073106SMatt Jacob 	REQ_STATE_LOCKED	= 0x80,	/* can't be freed */
366b0a2fdeeSScott Long 	REQ_STATE_MASK		= 0xFF
367b0a2fdeeSScott Long } mpt_req_state_t;
368b0a2fdeeSScott Long 
369b0a2fdeeSScott Long struct req_entry {
370b0a2fdeeSScott Long 	TAILQ_ENTRY(req_entry) links;	/* Pointer to next in list */
371b0a2fdeeSScott Long 	mpt_req_state_t	state;		/* Request State Information */
372b0a2fdeeSScott Long 	uint16_t	index;		/* Index of this entry */
373b0a2fdeeSScott Long 	uint16_t	IOCStatus;	/* Completion status */
3745089bd63SMatt Jacob 	uint16_t	ResponseCode;	/* TMF Reponse Code */
3755089bd63SMatt Jacob 	uint16_t	serno;		/* serial number */
376b0a2fdeeSScott Long 	union ccb      *ccb;		/* CAM request */
377b0a2fdeeSScott Long 	void	       *req_vbuf;	/* Virtual Address of Entry */
378b0a2fdeeSScott Long 	void	       *sense_vbuf;	/* Virtual Address of sense data */
379b0a2fdeeSScott Long 	bus_addr_t	req_pbuf;	/* Physical Address of Entry */
380b0a2fdeeSScott Long 	bus_addr_t	sense_pbuf;	/* Physical Address of sense data */
381fcd9a16bSMatt Jacob 	bus_dmamap_t	dmap;		/* DMA map for data buffers */
382444dd2b6SMatt Jacob 	struct req_entry *chain;	/* for SGE overallocations */
383d0a68c27SMatt Jacob 	struct callout  callout;	/* Timeout for the request */
384b0a2fdeeSScott Long };
385b0a2fdeeSScott Long 
3861d558d6aSScott Long typedef struct mpt_config_params {
3871d558d6aSScott Long 	u_int		Action;
3881d558d6aSScott Long 	u_int		PageVersion;
3891d558d6aSScott Long 	u_int		PageLength;
3901d558d6aSScott Long 	u_int		PageNumber;
3911d558d6aSScott Long 	u_int		PageType;
3921d558d6aSScott Long 	u_int		PageAddress;
3931d558d6aSScott Long 	u_int		ExtPageLength;
3941d558d6aSScott Long 	u_int		ExtPageType;
3951d558d6aSScott Long } cfgparms_t;
3961d558d6aSScott Long 
397c87e3f83SMatt Jacob /**************************** MPI Target State Info ***************************/
398c87e3f83SMatt Jacob 
399c87e3f83SMatt Jacob typedef struct {
400c87e3f83SMatt Jacob 	uint32_t reply_desc;	/* current reply descriptor */
401c87e3f83SMatt Jacob 	uint32_t resid;		/* current data residual */
402c87e3f83SMatt Jacob 	uint32_t bytes_xfered;	/* current relative offset */
403c87e3f83SMatt Jacob 	union ccb *ccb;		/* pointer to currently active ccb */
404c87e3f83SMatt Jacob 	request_t *req;		/* pointer to currently active assist request */
40573651fd1SMatt Jacob 	uint32_t
40673651fd1SMatt Jacob 		is_local : 1,
40773651fd1SMatt Jacob 		nxfers	 : 31;
4085e073106SMatt Jacob 	uint32_t tag_id;
409c87e3f83SMatt Jacob 	enum {
410c87e3f83SMatt Jacob 		TGT_STATE_NIL,
4115e073106SMatt Jacob 		TGT_STATE_LOADING,
412c87e3f83SMatt Jacob 		TGT_STATE_LOADED,
413c87e3f83SMatt Jacob 		TGT_STATE_IN_CAM,
414c87e3f83SMatt Jacob                 TGT_STATE_SETTING_UP_FOR_DATA,
415c87e3f83SMatt Jacob                 TGT_STATE_MOVING_DATA,
416c87e3f83SMatt Jacob                 TGT_STATE_MOVING_DATA_AND_STATUS,
417c87e3f83SMatt Jacob                 TGT_STATE_SENDING_STATUS
418c87e3f83SMatt Jacob 	} state;
419c87e3f83SMatt Jacob } mpt_tgt_state_t;
420c87e3f83SMatt Jacob 
421c87e3f83SMatt Jacob /*
422c87e3f83SMatt Jacob  * When we get an incoming command it has its own tag which is called the
423c87e3f83SMatt Jacob  * IoIndex. This is the value we gave that particular command buffer when
424c87e3f83SMatt Jacob  * we originally assigned it. It's just a number, really. The FC card uses
425c87e3f83SMatt Jacob  * it as an RX_ID. We can use it to index into mpt->tgt_cmd_ptrs, which
426c87e3f83SMatt Jacob  * contains pointers the request_t structures related to that IoIndex.
427c87e3f83SMatt Jacob  *
428c87e3f83SMatt Jacob  * What *we* do is construct a tag out of the index for the target command
429c87e3f83SMatt Jacob  * which owns the incoming ATIO plus a rolling sequence number.
430c87e3f83SMatt Jacob  */
431c87e3f83SMatt Jacob #define	MPT_MAKE_TAGID(mpt, req, ioindex)	\
4325e073106SMatt Jacob  ((ioindex << 18) | (((mpt->sequence++) & 0x3f) << 12) | (req->index & 0xfff))
433c87e3f83SMatt Jacob 
434c87e3f83SMatt Jacob #ifdef	INVARIANTS
435c87e3f83SMatt Jacob #define	MPT_TAG_2_REQ(a, b)		mpt_tag_2_req(a, (uint32_t) b)
436c87e3f83SMatt Jacob #else
4375e073106SMatt Jacob #define	MPT_TAG_2_REQ(mpt, tag)		mpt->tgt_cmd_ptrs[tag >> 18]
438c87e3f83SMatt Jacob #endif
439c87e3f83SMatt Jacob 
440c87e3f83SMatt Jacob #define	MPT_TGT_STATE(mpt, req) ((mpt_tgt_state_t *) \
441c87e3f83SMatt Jacob     (&((uint8_t *)req->req_vbuf)[MPT_RQSL(mpt) - sizeof (mpt_tgt_state_t)]))
442c87e3f83SMatt Jacob 
443c87e3f83SMatt Jacob STAILQ_HEAD(mpt_hdr_stailq, ccb_hdr);
444c87e3f83SMatt Jacob #define	MPT_MAX_LUNS	256
445c87e3f83SMatt Jacob typedef struct {
446c87e3f83SMatt Jacob 	struct mpt_hdr_stailq	atios;
447c87e3f83SMatt Jacob 	struct mpt_hdr_stailq	inots;
448c87e3f83SMatt Jacob 	int enabled;
449c87e3f83SMatt Jacob } tgt_resource_t;
4505089bd63SMatt Jacob #define	MPT_MAX_ELS	64
451c87e3f83SMatt Jacob 
452b0a2fdeeSScott Long /**************************** Handler Registration ****************************/
453b0a2fdeeSScott Long /*
454b0a2fdeeSScott Long  * Global table of registered reply handlers.  The
455b0a2fdeeSScott Long  * handler is indicated by byte 3 of the request
456b0a2fdeeSScott Long  * index submitted to the IOC.  This allows the
457b0a2fdeeSScott Long  * driver core to perform generic processing without
458b0a2fdeeSScott Long  * any knowledge of per-personality behavior.
459b0a2fdeeSScott Long  *
460b0a2fdeeSScott Long  * MPT_NUM_REPLY_HANDLERS must be a power of 2
461b0a2fdeeSScott Long  * to allow the easy generation of a mask.
462b0a2fdeeSScott Long  *
463b0a2fdeeSScott Long  * The handler offsets used by the core are hard coded
464b0a2fdeeSScott Long  * allowing faster code generation when assigning a handler
465b0a2fdeeSScott Long  * to a request.  All "personalities" must use the
466b0a2fdeeSScott Long  * the handler registration mechanism.
467b0a2fdeeSScott Long  *
468b0a2fdeeSScott Long  * The IOC handlers that are rarely executed are placed
469b0a2fdeeSScott Long  * at the tail of the table to make it more likely that
470b0a2fdeeSScott Long  * all commonly executed handlers fit in a single cache
471b0a2fdeeSScott Long  * line.
472b0a2fdeeSScott Long  */
473c87e3f83SMatt Jacob #define MPT_NUM_REPLY_HANDLERS		(32)
474b0a2fdeeSScott Long #define MPT_REPLY_HANDLER_EVENTS	MPT_CBI_TO_HID(0)
475b0a2fdeeSScott Long #define MPT_REPLY_HANDLER_CONFIG	MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-1)
476b0a2fdeeSScott Long #define MPT_REPLY_HANDLER_HANDSHAKE	MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-2)
477b0a2fdeeSScott Long typedef int mpt_reply_handler_t(struct mpt_softc *mpt, request_t *request,
478c87e3f83SMatt Jacob     uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame);
479b0a2fdeeSScott Long typedef union {
480b0a2fdeeSScott Long 	mpt_reply_handler_t	*reply_handler;
481b0a2fdeeSScott Long } mpt_handler_t;
482b0a2fdeeSScott Long 
483b0a2fdeeSScott Long typedef enum {
484b0a2fdeeSScott Long 	MPT_HANDLER_REPLY,
485b0a2fdeeSScott Long 	MPT_HANDLER_EVENT,
486b0a2fdeeSScott Long 	MPT_HANDLER_RESET,
487b0a2fdeeSScott Long 	MPT_HANDLER_SHUTDOWN
488b0a2fdeeSScott Long } mpt_handler_type;
489b0a2fdeeSScott Long 
490b0a2fdeeSScott Long struct mpt_handler_record
491b0a2fdeeSScott Long {
492b0a2fdeeSScott Long 	LIST_ENTRY(mpt_handler_record)	links;
493b0a2fdeeSScott Long 	mpt_handler_t			handler;
494b0a2fdeeSScott Long };
495b0a2fdeeSScott Long 
496b0a2fdeeSScott Long LIST_HEAD(mpt_handler_list, mpt_handler_record);
4979b631363SMatt Jacob 
4989b631363SMatt Jacob /*
499b0a2fdeeSScott Long  * The handler_id is currently unused but would contain the
500b0a2fdeeSScott Long  * handler ID used in the MsgContext field to allow direction
501b0a2fdeeSScott Long  * of replies to the handler.  Registrations that don't require
502b0a2fdeeSScott Long  * a handler id can pass in NULL for the handler_id.
503b0a2fdeeSScott Long  *
504b0a2fdeeSScott Long  * Deregistrations for handlers without a handler id should
505b0a2fdeeSScott Long  * pass in MPT_HANDLER_ID_NONE.
5069b631363SMatt Jacob  */
507b0a2fdeeSScott Long #define MPT_HANDLER_ID_NONE		(0xFFFFFFFF)
508b0a2fdeeSScott Long int mpt_register_handler(struct mpt_softc *, mpt_handler_type,
509b0a2fdeeSScott Long 			 mpt_handler_t, uint32_t *);
510b0a2fdeeSScott Long int mpt_deregister_handler(struct mpt_softc *, mpt_handler_type,
511b0a2fdeeSScott Long 			   mpt_handler_t, uint32_t);
5129b631363SMatt Jacob 
513b0a2fdeeSScott Long /******************* Per-Controller Instance Data Structures ******************/
514b0a2fdeeSScott Long TAILQ_HEAD(req_queue, req_entry);
5159b631363SMatt Jacob 
516b0a2fdeeSScott Long /* Structure for saving proper values for modifyable PCI config registers */
517b0a2fdeeSScott Long struct mpt_pci_cfg {
518b0a2fdeeSScott Long 	uint16_t Command;
519b0a2fdeeSScott Long 	uint16_t LatencyTimer_LineSize;
520b0a2fdeeSScott Long 	uint32_t IO_BAR;
521b0a2fdeeSScott Long 	uint32_t Mem0_BAR[2];
522b0a2fdeeSScott Long 	uint32_t Mem1_BAR[2];
523b0a2fdeeSScott Long 	uint32_t ROM_BAR;
524b0a2fdeeSScott Long 	uint8_t  IntLine;
525b0a2fdeeSScott Long 	uint32_t PMCSR;
5269b631363SMatt Jacob };
5279b631363SMatt Jacob 
528b0a2fdeeSScott Long typedef enum {
529b0a2fdeeSScott Long 	MPT_RVF_NONE		= 0x0,
530b0a2fdeeSScott Long 	MPT_RVF_ACTIVE		= 0x1,
531b0a2fdeeSScott Long 	MPT_RVF_ANNOUNCED	= 0x2,
532b0a2fdeeSScott Long 	MPT_RVF_UP2DATE		= 0x4,
533b0a2fdeeSScott Long 	MPT_RVF_REFERENCED	= 0x8,
534b0a2fdeeSScott Long 	MPT_RVF_WCE_CHANGED	= 0x10
535b0a2fdeeSScott Long } mpt_raid_volume_flags;
536b0a2fdeeSScott Long 
537b0a2fdeeSScott Long struct mpt_raid_volume {
538b0a2fdeeSScott Long 	CONFIG_PAGE_RAID_VOL_0	       *config_page;
539b0a2fdeeSScott Long 	MPI_RAID_VOL_INDICATOR		sync_progress;
540b0a2fdeeSScott Long 	mpt_raid_volume_flags		flags;
5410e3b145eSMatt Jacob 	u_int				quiesced_disks;
5429b631363SMatt Jacob };
5439b631363SMatt Jacob 
544b0a2fdeeSScott Long typedef enum {
545b0a2fdeeSScott Long 	MPT_RDF_NONE		= 0x00,
546b0a2fdeeSScott Long 	MPT_RDF_ACTIVE		= 0x01,
547b0a2fdeeSScott Long 	MPT_RDF_ANNOUNCED	= 0x02,
548b0a2fdeeSScott Long 	MPT_RDF_UP2DATE		= 0x04,
549b0a2fdeeSScott Long 	MPT_RDF_REFERENCED	= 0x08,
550b0a2fdeeSScott Long 	MPT_RDF_QUIESCING	= 0x10,
551b0a2fdeeSScott Long 	MPT_RDF_QUIESCED	= 0x20
552b0a2fdeeSScott Long } mpt_raid_disk_flags;
5539b631363SMatt Jacob 
554b0a2fdeeSScott Long struct mpt_raid_disk {
555b0a2fdeeSScott Long 	CONFIG_PAGE_RAID_PHYS_DISK_0	config_page;
556b0a2fdeeSScott Long 	struct mpt_raid_volume	       *volume;
557b0a2fdeeSScott Long 	u_int				member_number;
558b0a2fdeeSScott Long 	u_int				pass_thru_active;
559b0a2fdeeSScott Long 	mpt_raid_disk_flags		flags;
5609b631363SMatt Jacob };
5619b631363SMatt Jacob 
562b0a2fdeeSScott Long struct mpt_evtf_record {
563b0a2fdeeSScott Long 	MSG_EVENT_NOTIFY_REPLY		reply;
564b0a2fdeeSScott Long 	uint32_t			context;
565b0a2fdeeSScott Long 	LIST_ENTRY(mpt_evtf_record)	links;
5669b631363SMatt Jacob };
5679b631363SMatt Jacob 
568b0a2fdeeSScott Long LIST_HEAD(mpt_evtf_list, mpt_evtf_record);
5699b631363SMatt Jacob 
5701d558d6aSScott Long struct mptsas_devinfo {
5711d558d6aSScott Long 	uint16_t	dev_handle;
5721d558d6aSScott Long 	uint16_t	parent_dev_handle;
5731d558d6aSScott Long 	uint16_t	enclosure_handle;
5741d558d6aSScott Long 	uint16_t	slot;
5751d558d6aSScott Long 	uint8_t		phy_num;
5761d558d6aSScott Long 	uint8_t		physical_port;
5771d558d6aSScott Long 	uint8_t		target_id;
5781d558d6aSScott Long 	uint8_t		bus;
5791d558d6aSScott Long 	uint64_t	sas_address;
5801d558d6aSScott Long 	uint32_t	device_info;
5811d558d6aSScott Long };
5821d558d6aSScott Long 
5831d558d6aSScott Long struct mptsas_phyinfo {
5841d558d6aSScott Long 	uint16_t	handle;
5851d558d6aSScott Long 	uint8_t		phy_num;
5861d558d6aSScott Long 	uint8_t		port_id;
5871d558d6aSScott Long 	uint8_t		negotiated_link_rate;
5881d558d6aSScott Long 	uint8_t		hw_link_rate;
5891d558d6aSScott Long 	uint8_t		programmed_link_rate;
5901d558d6aSScott Long 	uint8_t		sas_port_add_phy;
5911d558d6aSScott Long 	struct mptsas_devinfo identify;
5921d558d6aSScott Long 	struct mptsas_devinfo attached;
5931d558d6aSScott Long };
5941d558d6aSScott Long 
5951d558d6aSScott Long struct mptsas_portinfo {
5961d558d6aSScott Long 	uint16_t			num_phys;
5971d558d6aSScott Long 	struct mptsas_phyinfo		*phy_info;
5981d558d6aSScott Long };
5991d558d6aSScott Long 
600b0a2fdeeSScott Long struct mpt_softc {
601b0a2fdeeSScott Long 	device_t		dev;
602b0a2fdeeSScott Long #if __FreeBSD_version < 500000
603b0a2fdeeSScott Long 	uint32_t		mpt_islocked;
6045089bd63SMatt Jacob 	int			mpt_splsaved;
605b0a2fdeeSScott Long #else
606b0a2fdeeSScott Long 	struct mtx		mpt_lock;
6075089bd63SMatt Jacob 	int			mpt_locksetup;
608b0a2fdeeSScott Long #endif
609b0a2fdeeSScott Long 	uint32_t		mpt_pers_mask;
610b4c618c0SMatt Jacob 	uint32_t
6110e0521a1SMatt Jacob 				: 8,
612c87e3f83SMatt Jacob 		unit		: 8,
613a2baed97SMatt Jacob 		ready		: 1,
6140e0521a1SMatt Jacob 		fw_uploaded	: 1,
615804625eeSMatt Jacob 		msi_enable	: 1,
616c87e3f83SMatt Jacob 		twildcard	: 1,
617c87e3f83SMatt Jacob 		tenabled	: 1,
618b4c618c0SMatt Jacob 		do_cfg_role	: 1,
6191d79ca0eSMatt Jacob 		raid_enabled	: 1,
620b0a2fdeeSScott Long 		raid_mwce_set	: 1,
621b0a2fdeeSScott Long 		getreqwaiter	: 1,
622b0a2fdeeSScott Long 		shutdwn_raid    : 1,
623b0a2fdeeSScott Long 		shutdwn_recovery: 1,
624b0a2fdeeSScott Long 		outofbeer	: 1,
625b0a2fdeeSScott Long 		disabled	: 1,
6265580ce96SMatt Jacob 		is_spi		: 1,
627c87e3f83SMatt Jacob 		is_sas		: 1,
628c87e3f83SMatt Jacob 		is_fc		: 1;
6299b631363SMatt Jacob 
630b4c618c0SMatt Jacob 	u_int			cfg_role;
631b4c618c0SMatt Jacob 	u_int			role;	/* role: none, ini, target, both */
632b4c618c0SMatt Jacob 
633b0a2fdeeSScott Long 	u_int			verbose;
634a2baed97SMatt Jacob #ifdef	MPT_TEST_MULTIPATH
635a2baed97SMatt Jacob 	int			failure_id;
636a2baed97SMatt Jacob #endif
6379b631363SMatt Jacob 
638b0a2fdeeSScott Long 	/*
639b0a2fdeeSScott Long 	 * IOC Facts
640b0a2fdeeSScott Long 	 */
6410e0521a1SMatt Jacob 	MSG_IOC_FACTS_REPLY	ioc_facts;
6429b631363SMatt Jacob 
643b0a2fdeeSScott Long 	/*
644b0a2fdeeSScott Long 	 * Port Facts
645b0a2fdeeSScott Long 	 */
6460e0521a1SMatt Jacob 	MSG_PORT_FACTS_REPLY *	port_facts;
6470e0521a1SMatt Jacob #define	mpt_max_tgtcmds	port_facts[0].MaxPostedCmdBuffers
6489b631363SMatt Jacob 
649b0a2fdeeSScott Long 	/*
650b0a2fdeeSScott Long 	 * Device Configuration Information
651b0a2fdeeSScott Long 	 */
652b0a2fdeeSScott Long 	union {
653b0a2fdeeSScott Long 		struct mpt_spi_cfg {
654b0a2fdeeSScott Long 			CONFIG_PAGE_SCSI_PORT_0		_port_page0;
655b0a2fdeeSScott Long 			CONFIG_PAGE_SCSI_PORT_1		_port_page1;
656b0a2fdeeSScott Long 			CONFIG_PAGE_SCSI_PORT_2		_port_page2;
657b0a2fdeeSScott Long 			CONFIG_PAGE_SCSI_DEVICE_0	_dev_page0[16];
658b0a2fdeeSScott Long 			CONFIG_PAGE_SCSI_DEVICE_1	_dev_page1[16];
6598ba5efbdSMarius Strobl 			int				_ini_id;
660b0a2fdeeSScott Long 			uint16_t			_tag_enable;
661b0a2fdeeSScott Long 			uint16_t			_disc_enable;
662b0a2fdeeSScott Long 		} spi;
663b0a2fdeeSScott Long #define	mpt_port_page0		cfg.spi._port_page0
664b0a2fdeeSScott Long #define	mpt_port_page1		cfg.spi._port_page1
665b0a2fdeeSScott Long #define	mpt_port_page2		cfg.spi._port_page2
666b0a2fdeeSScott Long #define	mpt_dev_page0		cfg.spi._dev_page0
667b0a2fdeeSScott Long #define	mpt_dev_page1		cfg.spi._dev_page1
6688ba5efbdSMarius Strobl #define	mpt_ini_id		cfg.spi._ini_id
669b0a2fdeeSScott Long #define	mpt_tag_enable		cfg.spi._tag_enable
670b0a2fdeeSScott Long #define	mpt_disc_enable		cfg.spi._disc_enable
671b0a2fdeeSScott Long 		struct mpi_fc_cfg {
672c87e3f83SMatt Jacob 			CONFIG_PAGE_FC_PORT_0 _port_page0;
6739fe6d254SMatt Jacob 			uint32_t _port_speed;
674c87e3f83SMatt Jacob #define	mpt_fcport_page0	cfg.fc._port_page0
6759fe6d254SMatt Jacob #define	mpt_fcport_speed	cfg.fc._port_speed
676b0a2fdeeSScott Long 		} fc;
677b0a2fdeeSScott Long 	} cfg;
678970043d7SMatt Jacob #if __FreeBSD_version >= 500000
679970043d7SMatt Jacob 	/*
680970043d7SMatt Jacob 	 * Device config information stored up for sysctl to access
681970043d7SMatt Jacob 	 */
682970043d7SMatt Jacob 	union {
683970043d7SMatt Jacob 		struct {
684970043d7SMatt Jacob 			unsigned int initiator_id;
685970043d7SMatt Jacob 		} spi;
686970043d7SMatt Jacob 		struct {
687970043d7SMatt Jacob 			char wwnn[19];
688970043d7SMatt Jacob 			char wwpn[19];
689970043d7SMatt Jacob 		} fc;
690970043d7SMatt Jacob 	} scinfo;
691970043d7SMatt Jacob #endif
692b0a2fdeeSScott Long 
6931d79ca0eSMatt Jacob 	/* Controller Info for RAID information */
694b0a2fdeeSScott Long 	CONFIG_PAGE_IOC_2 *	ioc_page2;
695b0a2fdeeSScott Long 	CONFIG_PAGE_IOC_3 *	ioc_page3;
696b0a2fdeeSScott Long 
697b0a2fdeeSScott Long 	/* Raid Data */
698b0a2fdeeSScott Long 	struct mpt_raid_volume* raid_volumes;
699b0a2fdeeSScott Long 	struct mpt_raid_disk*	raid_disks;
700b0a2fdeeSScott Long 	u_int			raid_max_volumes;
701b0a2fdeeSScott Long 	u_int			raid_max_disks;
702b0a2fdeeSScott Long 	u_int			raid_page0_len;
703b0a2fdeeSScott Long 	u_int			raid_wakeup;
704b0a2fdeeSScott Long 	u_int			raid_rescan;
705b0a2fdeeSScott Long 	u_int			raid_resync_rate;
706b0a2fdeeSScott Long 	u_int			raid_mwce_setting;
707b0a2fdeeSScott Long 	u_int			raid_queue_depth;
7085cc0208aSAlexander Kabaev 	u_int			raid_nonopt_volumes;
709b0a2fdeeSScott Long 	struct proc	       *raid_thread;
710b0a2fdeeSScott Long 	struct callout		raid_timer;
711b0a2fdeeSScott Long 
712b0a2fdeeSScott Long 	/*
713b0a2fdeeSScott Long 	 * PCI Hardware info
714b0a2fdeeSScott Long 	 */
715280388afSJohn Baldwin 	int			pci_msi_count;
716b0a2fdeeSScott Long 	struct resource *	pci_irq;	/* Interrupt map for chip */
717b0a2fdeeSScott Long 	void *			ih;		/* Interupt handle */
718b0a2fdeeSScott Long 	struct mpt_pci_cfg	pci_cfg;	/* saved PCI conf registers */
719b0a2fdeeSScott Long 
720b0a2fdeeSScott Long 	/*
721b0a2fdeeSScott Long 	 * DMA Mapping Stuff
722b0a2fdeeSScott Long 	 */
723b0a2fdeeSScott Long 	struct resource *	pci_reg;	/* Register map for chip */
724b0a2fdeeSScott Long 	int			pci_mem_rid;	/* Resource ID */
725b0a2fdeeSScott Long 	bus_space_tag_t		pci_st;		/* Bus tag for registers */
726b0a2fdeeSScott Long 	bus_space_handle_t	pci_sh;		/* Bus handle for registers */
727b0a2fdeeSScott Long 	/* PIO versions of above. */
728b0a2fdeeSScott Long 	int			pci_pio_rid;
729b0a2fdeeSScott Long 	struct resource *	pci_pio_reg;
730b0a2fdeeSScott Long 	bus_space_tag_t		pci_pio_st;
731b0a2fdeeSScott Long 	bus_space_handle_t	pci_pio_sh;
732b0a2fdeeSScott Long 
733b0a2fdeeSScott Long 	bus_dma_tag_t		parent_dmat;	/* DMA tag for parent PCI bus */
734b0a2fdeeSScott Long 	bus_dma_tag_t		reply_dmat;	/* DMA tag for reply memory */
735b0a2fdeeSScott Long 	bus_dmamap_t		reply_dmap;	/* DMA map for reply memory */
736b0a2fdeeSScott Long 	uint8_t		       *reply;		/* KVA of reply memory */
737b0a2fdeeSScott Long 	bus_addr_t		reply_phys;	/* BusAddr of reply memory */
738b0a2fdeeSScott Long 
739b0a2fdeeSScott Long 	bus_dma_tag_t		buffer_dmat;	/* DMA tag for buffers */
740b0a2fdeeSScott Long 	bus_dma_tag_t		request_dmat;	/* DMA tag for request memroy */
741b0a2fdeeSScott Long 	bus_dmamap_t		request_dmap;	/* DMA map for request memroy */
742b0a2fdeeSScott Long 	uint8_t		       *request;	/* KVA of Request memory */
743c87e3f83SMatt Jacob 	bus_addr_t		request_phys;	/* BusAddr of request memory */
744b0a2fdeeSScott Long 
745444dd2b6SMatt Jacob 	uint32_t		max_seg_cnt;	/* calculated after IOC facts */
7464201341fSKenneth D. Merry 	uint32_t		max_cam_seg_cnt;/* calculated from MAXPHYS*/
747444dd2b6SMatt Jacob 
748444dd2b6SMatt Jacob 	/*
749444dd2b6SMatt Jacob 	 * Hardware management
750444dd2b6SMatt Jacob 	 */
751b0a2fdeeSScott Long 	u_int			reset_cnt;
752b0a2fdeeSScott Long 
753b0a2fdeeSScott Long 	/*
754b0a2fdeeSScott Long 	 * CAM && Software Management
755b0a2fdeeSScott Long 	 */
756b0a2fdeeSScott Long 	request_t	       *request_pool;
757b0a2fdeeSScott Long 	struct req_queue	request_free_list;
758b0a2fdeeSScott Long 	struct req_queue	request_pending_list;
759b0a2fdeeSScott Long 	struct req_queue	request_timeout_list;
760b0a2fdeeSScott Long 
761b0a2fdeeSScott Long 
762b0a2fdeeSScott Long 	struct cam_sim	       *sim;
763b0a2fdeeSScott Long 	struct cam_path	       *path;
764b0a2fdeeSScott Long 
765b0a2fdeeSScott Long 	struct cam_sim	       *phydisk_sim;
766b0a2fdeeSScott Long 	struct cam_path	       *phydisk_path;
767b0a2fdeeSScott Long 
768b0a2fdeeSScott Long 	struct proc	       *recovery_thread;
769b0a2fdeeSScott Long 	request_t	       *tmf_req;
770b0a2fdeeSScott Long 
771c87e3f83SMatt Jacob 	/*
7725e073106SMatt Jacob 	 * Deferred frame acks due to resource shortage.
7735e073106SMatt Jacob 	 */
7745e073106SMatt Jacob 	struct mpt_evtf_list	ack_frames;
775fcd9a16bSMatt Jacob 
7765e073106SMatt Jacob 	/*
777c87e3f83SMatt Jacob 	 * Target Mode Support
778c87e3f83SMatt Jacob 	 */
779c87e3f83SMatt Jacob 	uint32_t		scsi_tgt_handler_id;
780c87e3f83SMatt Jacob 	request_t **		tgt_cmd_ptrs;
7815089bd63SMatt Jacob 	request_t **		els_cmd_ptrs;	/* FC only */
782c87e3f83SMatt Jacob 
783c87e3f83SMatt Jacob 	/*
784c87e3f83SMatt Jacob 	 * *snork*- this is chosen to be here *just in case* somebody
785c87e3f83SMatt Jacob 	 * forgets to point to it exactly and we index off of trt with
786c87e3f83SMatt Jacob 	 * CAM_LUN_WILDCARD.
787c87e3f83SMatt Jacob 	 */
788c87e3f83SMatt Jacob 	tgt_resource_t		trt_wildcard;		/* wildcard luns */
789c87e3f83SMatt Jacob 	tgt_resource_t		trt[MPT_MAX_LUNS];
790c87e3f83SMatt Jacob 	uint16_t		tgt_cmds_allocated;
7915089bd63SMatt Jacob 	uint16_t		els_cmds_allocated;	/* FC only */
792c87e3f83SMatt Jacob 
793c87e3f83SMatt Jacob 	uint16_t		timeouts;	/* timeout count */
794c87e3f83SMatt Jacob 	uint16_t		success;	/* successes afer timeout */
7955089bd63SMatt Jacob 	uint16_t		sequence;	/* Sequence Number */
7965089bd63SMatt Jacob 	uint16_t		pad3;
797c87e3f83SMatt Jacob 
798b0a2fdeeSScott Long 
799fcd9a16bSMatt Jacob 	/* Paired port in some dual adapters configurations */
800b0a2fdeeSScott Long 	struct mpt_softc *	mpt2;
801b0a2fdeeSScott Long 
802b0a2fdeeSScott Long 	/* FW Image management */
803b0a2fdeeSScott Long 	uint32_t		fw_image_size;
804b0a2fdeeSScott Long 	uint8_t		       *fw_image;
805b0a2fdeeSScott Long 	bus_dma_tag_t		fw_dmat;	/* DMA tag for firmware image */
806b0a2fdeeSScott Long 	bus_dmamap_t		fw_dmap;	/* DMA map for firmware image */
8075580ce96SMatt Jacob 	bus_addr_t		fw_phys;	/* BusAddr of firmware image */
808b0a2fdeeSScott Long 
8091d558d6aSScott Long 	/* SAS Topology */
8101d558d6aSScott Long 	struct mptsas_portinfo	*sas_portinfo;
8111d558d6aSScott Long 
812b0a2fdeeSScott Long 	/* Shutdown Event Handler. */
813b0a2fdeeSScott Long 	eventhandler_tag         eh;
814b0a2fdeeSScott Long 
815ee98c4a5SJohn Baldwin 	/* Userland management interface. */
816ee98c4a5SJohn Baldwin 	struct cdev		*cdev;
817ee98c4a5SJohn Baldwin 
818b0a2fdeeSScott Long 	TAILQ_ENTRY(mpt_softc)	links;
819b0a2fdeeSScott Long };
820b0a2fdeeSScott Long 
8215089bd63SMatt Jacob static __inline void mpt_assign_serno(struct mpt_softc *, request_t *);
8225089bd63SMatt Jacob 
8235089bd63SMatt Jacob static __inline void
8245089bd63SMatt Jacob mpt_assign_serno(struct mpt_softc *mpt, request_t *req)
8255089bd63SMatt Jacob {
8265089bd63SMatt Jacob 	if ((req->serno = mpt->sequence++) == 0) {
8275089bd63SMatt Jacob 		req->serno = mpt->sequence++;
8285089bd63SMatt Jacob 	}
8295089bd63SMatt Jacob }
8305089bd63SMatt Jacob 
831c87e3f83SMatt Jacob /***************************** Locking Primitives *****************************/
832b0a2fdeeSScott Long #if __FreeBSD_version < 500000
833b0a2fdeeSScott Long #define	MPT_IFLAGS		INTR_TYPE_CAM
834b0a2fdeeSScott Long #define	MPT_LOCK(mpt)		mpt_lockspl(mpt)
835b0a2fdeeSScott Long #define	MPT_UNLOCK(mpt)		mpt_unlockspl(mpt)
8365089bd63SMatt Jacob #define	MPT_OWNED(mpt)		mpt->mpt_islocked
837d0a68c27SMatt Jacob #define	MPT_LOCK_ASSERT(mpt)
838b0a2fdeeSScott Long #define	MPTLOCK_2_CAMLOCK	MPT_UNLOCK
839b0a2fdeeSScott Long #define	CAMLOCK_2_MPTLOCK	MPT_LOCK
840b0a2fdeeSScott Long #define	MPT_LOCK_SETUP(mpt)
841b0a2fdeeSScott Long #define	MPT_LOCK_DESTROY(mpt)
842b0a2fdeeSScott Long 
843b0a2fdeeSScott Long static __inline void mpt_lockspl(struct mpt_softc *mpt);
844b0a2fdeeSScott Long static __inline void mpt_unlockspl(struct mpt_softc *mpt);
845b0a2fdeeSScott Long 
846b0a2fdeeSScott Long static __inline void
847b0a2fdeeSScott Long mpt_lockspl(struct mpt_softc *mpt)
848b0a2fdeeSScott Long {
849b0a2fdeeSScott Long        int s;
850b0a2fdeeSScott Long 
851b0a2fdeeSScott Long        s = splcam();
852b0a2fdeeSScott Long        if (mpt->mpt_islocked++ == 0) {
853b0a2fdeeSScott Long                mpt->mpt_splsaved = s;
854b0a2fdeeSScott Long        } else {
855b0a2fdeeSScott Long                splx(s);
856b0a2fdeeSScott Long 	       panic("Recursed lock with mask: 0x%x\n", s);
857b0a2fdeeSScott Long        }
858b0a2fdeeSScott Long }
859b0a2fdeeSScott Long 
860b0a2fdeeSScott Long static __inline void
861b0a2fdeeSScott Long mpt_unlockspl(struct mpt_softc *mpt)
862b0a2fdeeSScott Long {
863b0a2fdeeSScott Long        if (mpt->mpt_islocked) {
864b0a2fdeeSScott Long                if (--mpt->mpt_islocked == 0) {
865b0a2fdeeSScott Long                        splx(mpt->mpt_splsaved);
866b0a2fdeeSScott Long                }
867b0a2fdeeSScott Long        } else
868b0a2fdeeSScott Long 	       panic("Negative lock count\n");
869b0a2fdeeSScott Long }
870b0a2fdeeSScott Long 
871b0a2fdeeSScott Long static __inline int
872b0a2fdeeSScott Long mpt_sleep(struct mpt_softc *mpt, void *ident, int priority,
873b0a2fdeeSScott Long 	   const char *wmesg, int timo)
874b0a2fdeeSScott Long {
875b0a2fdeeSScott Long 	int saved_cnt;
876b0a2fdeeSScott Long 	int saved_spl;
877b0a2fdeeSScott Long 	int error;
878b0a2fdeeSScott Long 
879b0a2fdeeSScott Long 	KASSERT(mpt->mpt_islocked <= 1, ("Invalid lock count on tsleep"));
880b0a2fdeeSScott Long 	saved_cnt = mpt->mpt_islocked;
881b0a2fdeeSScott Long 	saved_spl = mpt->mpt_splsaved;
882b0a2fdeeSScott Long 	mpt->mpt_islocked = 0;
883b0a2fdeeSScott Long 	error = tsleep(ident, priority, wmesg, timo);
884c87e3f83SMatt Jacob 	KASSERT(mpt->mpt_islocked == 0, ("Invalid lock count on wakeup"));
885b0a2fdeeSScott Long 	mpt->mpt_islocked = saved_cnt;
886b0a2fdeeSScott Long 	mpt->mpt_splsaved = saved_spl;
887b0a2fdeeSScott Long 	return (error);
888b0a2fdeeSScott Long }
889b0a2fdeeSScott Long 
890d0a68c27SMatt Jacob #define mpt_req_timeout(req, ticks, func, arg) \
891d0a68c27SMatt Jacob 	callout_reset(&(req)->callout, (ticks), (func), (arg));
892d0a68c27SMatt Jacob #define mpt_req_untimeout(req, func, arg) \
893d0a68c27SMatt Jacob 	callout_stop(&(req)->callout)
894363b8ed7SAlexander Kabaev #define mpt_callout_init(mpt, c) \
895363b8ed7SAlexander Kabaev 	callout_init(c)
896363b8ed7SAlexander Kabaev #define mpt_callout_drain(mpt, c) \
897363b8ed7SAlexander Kabaev 	callout_stop(c)
898d0a68c27SMatt Jacob 
899b0a2fdeeSScott Long #else
900d0a68c27SMatt Jacob #if 1
901b0a2fdeeSScott Long #define	MPT_IFLAGS		INTR_TYPE_CAM | INTR_ENTROPY | INTR_MPSAFE
902b0a2fdeeSScott Long #define	MPT_LOCK_SETUP(mpt)						\
903b0a2fdeeSScott Long 		mtx_init(&mpt->mpt_lock, "mpt", NULL, MTX_DEF);		\
904b0a2fdeeSScott Long 		mpt->mpt_locksetup = 1
905b0a2fdeeSScott Long #define	MPT_LOCK_DESTROY(mpt)						\
906b0a2fdeeSScott Long 	if (mpt->mpt_locksetup) {					\
907b0a2fdeeSScott Long 		mtx_destroy(&mpt->mpt_lock);				\
908b0a2fdeeSScott Long 		mpt->mpt_locksetup = 0;					\
909b0a2fdeeSScott Long 	}
910b0a2fdeeSScott Long 
911b0a2fdeeSScott Long #define	MPT_LOCK(mpt)		mtx_lock(&(mpt)->mpt_lock)
912b0a2fdeeSScott Long #define	MPT_UNLOCK(mpt)		mtx_unlock(&(mpt)->mpt_lock)
9135089bd63SMatt Jacob #define	MPT_OWNED(mpt)		mtx_owned(&(mpt)->mpt_lock)
914d0a68c27SMatt Jacob #define	MPT_LOCK_ASSERT(mpt)	mtx_assert(&(mpt)->mpt_lock, MA_OWNED)
915d0a68c27SMatt Jacob #define	MPTLOCK_2_CAMLOCK(mpt)
916d0a68c27SMatt Jacob #define	CAMLOCK_2_MPTLOCK(mpt)
917b0a2fdeeSScott Long #define mpt_sleep(mpt, ident, priority, wmesg, timo) \
918b0a2fdeeSScott Long 	msleep(ident, &(mpt)->mpt_lock, priority, wmesg, timo)
919d0a68c27SMatt Jacob #define mpt_req_timeout(req, ticks, func, arg) \
920363b8ed7SAlexander Kabaev 	callout_reset(&(req)->callout, (ticks), (func), (arg))
921d0a68c27SMatt Jacob #define mpt_req_untimeout(req, func, arg) \
922d0a68c27SMatt Jacob 	callout_stop(&(req)->callout)
923363b8ed7SAlexander Kabaev #define mpt_callout_init(mpt, c) \
924363b8ed7SAlexander Kabaev 	callout_init_mtx(c, &(mpt)->mpt_lock, 0)
925363b8ed7SAlexander Kabaev #define mpt_callout_drain(mpt, c) \
926363b8ed7SAlexander Kabaev 	callout_drain(c)
9275089bd63SMatt Jacob 
928b0a2fdeeSScott Long #else
9295089bd63SMatt Jacob 
930b0a2fdeeSScott Long #define	MPT_IFLAGS		INTR_TYPE_CAM | INTR_ENTROPY
931b0a2fdeeSScott Long #define	MPT_LOCK_SETUP(mpt)	do { } while (0)
932b0a2fdeeSScott Long #define	MPT_LOCK_DESTROY(mpt)	do { } while (0)
933d0a68c27SMatt Jacob #define	MPT_LOCK_ASSERT(mpt)	mtx_assert(&Giant, MA_OWNED)
934d0a68c27SMatt Jacob #define	MPT_LOCK(mpt)		mtx_lock(&Giant)
935d0a68c27SMatt Jacob #define	MPT_UNLOCK(mpt)		mtx_unlock(&Giant)
936d0a68c27SMatt Jacob #define	MPTLOCK_2_CAMLOCK(mpt)
937d0a68c27SMatt Jacob #define	CAMLOCK_2_MPTLOCK(mpt)
9385089bd63SMatt Jacob 
939363b8ed7SAlexander Kabaev #define mpt_req_timeout(req, ticks, func, arg) \
940363b8ed7SAlexander Kabaev 	callout_reset(&(req)->callout, (ticks), (func), (arg))
941363b8ed7SAlexander Kabaev #define mpt_req_untimeout(req, func, arg) \
942363b8ed7SAlexander Kabaev 	callout_stop(&(req)->callout)
943363b8ed7SAlexander Kabaev #define mpt_callout_init(mpt, c) \
944363b8ed7SAlexander Kabaev 	callout_init(c, 0)
945363b8ed7SAlexander Kabaev #define mpt_callout_drain(mpt, c) \
946363b8ed7SAlexander Kabaev 	callout_drain(c)
947363b8ed7SAlexander Kabaev 
9485089bd63SMatt Jacob static __inline int
9495089bd63SMatt Jacob mpt_sleep(struct mpt_softc *, void *, int, const char *, int);
9505089bd63SMatt Jacob 
9515089bd63SMatt Jacob static __inline int
9525089bd63SMatt Jacob mpt_sleep(struct mpt_softc *mpt, void *i, int p, const char *w, int t)
9535089bd63SMatt Jacob {
9545089bd63SMatt Jacob 	int r;
9555089bd63SMatt Jacob 	r = tsleep(i, p, w, t);
9565089bd63SMatt Jacob 	return (r);
9575089bd63SMatt Jacob }
958b0a2fdeeSScott Long #endif
959b0a2fdeeSScott Long #endif
960b0a2fdeeSScott Long 
961b0a2fdeeSScott Long /******************************* Register Access ******************************/
962b0a2fdeeSScott Long static __inline void mpt_write(struct mpt_softc *, size_t, uint32_t);
963b0a2fdeeSScott Long static __inline uint32_t mpt_read(struct mpt_softc *, int);
964b0a2fdeeSScott Long static __inline void mpt_pio_write(struct mpt_softc *, size_t, uint32_t);
965b0a2fdeeSScott Long static __inline uint32_t mpt_pio_read(struct mpt_softc *, int);
966b0a2fdeeSScott Long 
967b0a2fdeeSScott Long static __inline void
968b0a2fdeeSScott Long mpt_write(struct mpt_softc *mpt, size_t offset, uint32_t val)
969b0a2fdeeSScott Long {
970b0a2fdeeSScott Long 	bus_space_write_4(mpt->pci_st, mpt->pci_sh, offset, val);
971b0a2fdeeSScott Long }
972b0a2fdeeSScott Long 
973b0a2fdeeSScott Long static __inline uint32_t
974b0a2fdeeSScott Long mpt_read(struct mpt_softc *mpt, int offset)
975b0a2fdeeSScott Long {
976b0a2fdeeSScott Long 	return (bus_space_read_4(mpt->pci_st, mpt->pci_sh, offset));
977b0a2fdeeSScott Long }
978b0a2fdeeSScott Long 
979b0a2fdeeSScott Long /*
980b0a2fdeeSScott Long  * Some operations (e.g. diagnostic register writes while the ARM proccessor
981b0a2fdeeSScott Long  * is disabled), must be performed using "PCI pio" operations.  On non-PCI
982b0a2fdeeSScott Long  * busses, these operations likely map to normal register accesses.
983b0a2fdeeSScott Long  */
984b0a2fdeeSScott Long static __inline void
985b0a2fdeeSScott Long mpt_pio_write(struct mpt_softc *mpt, size_t offset, uint32_t val)
986b0a2fdeeSScott Long {
987b0a2fdeeSScott Long 	bus_space_write_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset, val);
988b0a2fdeeSScott Long }
989b0a2fdeeSScott Long 
990b0a2fdeeSScott Long static __inline uint32_t
991b0a2fdeeSScott Long mpt_pio_read(struct mpt_softc *mpt, int offset)
992b0a2fdeeSScott Long {
993b0a2fdeeSScott Long 	return (bus_space_read_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset));
994b0a2fdeeSScott Long }
995b0a2fdeeSScott Long /*********************** Reply Frame/Request Management ***********************/
996b0a2fdeeSScott Long /* Max MPT Reply we are willing to accept (must be power of 2) */
997444dd2b6SMatt Jacob #define MPT_REPLY_SIZE   	256
998b0a2fdeeSScott Long 
999c87e3f83SMatt Jacob /*
1000c87e3f83SMatt Jacob  * Must be less than 16384 in order for target mode to work
1001c87e3f83SMatt Jacob  */
1002444dd2b6SMatt Jacob #define MPT_MAX_REQUESTS(mpt)	512
1003b0a2fdeeSScott Long #define MPT_REQUEST_AREA	512
1004444dd2b6SMatt Jacob #define MPT_SENSE_SIZE		32	/* included in MPT_REQUEST_AREA */
1005b0a2fdeeSScott Long #define MPT_REQ_MEM_SIZE(mpt)	(MPT_MAX_REQUESTS(mpt) * MPT_REQUEST_AREA)
1006b0a2fdeeSScott Long 
10075e073106SMatt Jacob #define MPT_CONTEXT_CB_SHIFT	(16)
1008b0a2fdeeSScott Long #define MPT_CBI(handle)		(handle >> MPT_CONTEXT_CB_SHIFT)
1009b0a2fdeeSScott Long #define MPT_CBI_TO_HID(cbi)	((cbi) << MPT_CONTEXT_CB_SHIFT)
1010b0a2fdeeSScott Long #define MPT_CONTEXT_TO_CBI(x)	\
1011b0a2fdeeSScott Long     (((x) >> MPT_CONTEXT_CB_SHIFT) & (MPT_NUM_REPLY_HANDLERS - 1))
10125e073106SMatt Jacob #define MPT_CONTEXT_REQI_MASK	0xFFFF
1013c87e3f83SMatt Jacob #define MPT_CONTEXT_TO_REQI(x)	((x) & MPT_CONTEXT_REQI_MASK)
1014b0a2fdeeSScott Long 
1015b0a2fdeeSScott Long /*
1016b0a2fdeeSScott Long  * Convert a 32bit physical address returned from IOC to an
1017b0a2fdeeSScott Long  * offset into our reply frame memory or the kvm address needed
1018b0a2fdeeSScott Long  * to access the data.  The returned address is only the low
1019b0a2fdeeSScott Long  * 32 bits, so mask our base physical address accordingly.
1020b0a2fdeeSScott Long  */
1021b0a2fdeeSScott Long #define MPT_REPLY_BADDR(x)		\
1022b0a2fdeeSScott Long 	(x << 1)
1023b0a2fdeeSScott Long #define MPT_REPLY_OTOV(m, i) 		\
1024b0a2fdeeSScott Long 	((void *)(&m->reply[i]))
1025b0a2fdeeSScott Long 
1026b0a2fdeeSScott Long #define	MPT_DUMP_REPLY_FRAME(mpt, reply_frame)		\
1027b0a2fdeeSScott Long do {							\
10281d79ca0eSMatt Jacob 	if (mpt->verbose > MPT_PRT_DEBUG)		\
1029b0a2fdeeSScott Long 		mpt_dump_reply_frame(mpt, reply_frame);	\
1030b0a2fdeeSScott Long } while(0)
1031b0a2fdeeSScott Long 
1032b0a2fdeeSScott Long static __inline uint32_t mpt_pop_reply_queue(struct mpt_softc *mpt);
1033b0a2fdeeSScott Long static __inline void mpt_free_reply(struct mpt_softc *mpt, uint32_t ptr);
1034b0a2fdeeSScott Long 
1035b0a2fdeeSScott Long /*
1036b0a2fdeeSScott Long  * Give the reply buffer back to the IOC after we have
1037b0a2fdeeSScott Long  * finished processing it.
1038b0a2fdeeSScott Long  */
1039b0a2fdeeSScott Long static __inline void
1040b0a2fdeeSScott Long mpt_free_reply(struct mpt_softc *mpt, uint32_t ptr)
1041b0a2fdeeSScott Long {
1042b0a2fdeeSScott Long      mpt_write(mpt, MPT_OFFSET_REPLY_Q, ptr);
1043b0a2fdeeSScott Long }
1044b0a2fdeeSScott Long 
1045b0a2fdeeSScott Long /* Get a reply from the IOC */
1046b0a2fdeeSScott Long static __inline uint32_t
1047b0a2fdeeSScott Long mpt_pop_reply_queue(struct mpt_softc *mpt)
1048b0a2fdeeSScott Long {
1049b0a2fdeeSScott Long      return mpt_read(mpt, MPT_OFFSET_REPLY_Q);
1050b0a2fdeeSScott Long }
1051b0a2fdeeSScott Long 
10525e073106SMatt Jacob void
10535e073106SMatt Jacob mpt_complete_request_chain(struct mpt_softc *, struct req_queue *, u_int);
10545e073106SMatt Jacob 
1055b0a2fdeeSScott Long /************************** Scatter Gather Managment **************************/
1056444dd2b6SMatt Jacob /* MPT_RQSL- size of request frame, in bytes */
10570e0521a1SMatt Jacob #define	MPT_RQSL(mpt)		(mpt->ioc_facts.RequestFrameSize << 2)
1058b0a2fdeeSScott Long 
1059444dd2b6SMatt Jacob /* MPT_NSGL- how many SG entries can fit in a request frame size */
1060444dd2b6SMatt Jacob #define	MPT_NSGL(mpt)		(MPT_RQSL(mpt) / sizeof (SGE_IO_UNION))
1061444dd2b6SMatt Jacob 
1062444dd2b6SMatt Jacob /* MPT_NRFM- how many request frames can fit in each request alloc we make */
1063444dd2b6SMatt Jacob #define	MPT_NRFM(mpt)		(MPT_REQUEST_AREA / MPT_RQSL(mpt))
1064444dd2b6SMatt Jacob 
1065444dd2b6SMatt Jacob /*
1066444dd2b6SMatt Jacob  * MPT_NSGL_FIRST- # of SG elements that can fit after
1067444dd2b6SMatt Jacob  * an I/O request but still within the request frame.
1068444dd2b6SMatt Jacob  * Do this safely based upon SGE_IO_UNION.
1069444dd2b6SMatt Jacob  *
1070444dd2b6SMatt Jacob  * Note that the first element is *within* the SCSI request.
1071444dd2b6SMatt Jacob  */
1072b0a2fdeeSScott Long #define	MPT_NSGL_FIRST(mpt)	\
1073444dd2b6SMatt Jacob     ((MPT_RQSL(mpt) - sizeof (MSG_SCSI_IO_REQUEST) + sizeof (SGE_IO_UNION)) / \
1074444dd2b6SMatt Jacob     sizeof (SGE_IO_UNION))
1075b0a2fdeeSScott Long 
1076b0a2fdeeSScott Long /***************************** IOC Initialization *****************************/
1077b0a2fdeeSScott Long int mpt_reset(struct mpt_softc *, int /*reinit*/);
1078b0a2fdeeSScott Long 
1079c87e3f83SMatt Jacob /****************************** Debugging ************************************/
1080b0a2fdeeSScott Long typedef struct mpt_decode_entry {
1081b0a2fdeeSScott Long 	char    *name;
1082b0a2fdeeSScott Long 	u_int	 value;
1083b0a2fdeeSScott Long 	u_int	 mask;
1084b0a2fdeeSScott Long } mpt_decode_entry_t;
1085b0a2fdeeSScott Long 
1086b0a2fdeeSScott Long int mpt_decode_value(mpt_decode_entry_t *table, u_int num_entries,
1087b0a2fdeeSScott Long 		     const char *name, u_int value, u_int *cur_column,
1088b0a2fdeeSScott Long 		     u_int wrap_point);
1089b0a2fdeeSScott Long 
1090b4c618c0SMatt Jacob void mpt_dump_data(struct mpt_softc *, const char *, void *, int);
10910e3b145eSMatt Jacob void mpt_dump_request(struct mpt_softc *, request_t *);
10920e3b145eSMatt Jacob 
1093b0a2fdeeSScott Long enum {
1094b0a2fdeeSScott Long 	MPT_PRT_ALWAYS,
1095b0a2fdeeSScott Long 	MPT_PRT_FATAL,
1096b0a2fdeeSScott Long 	MPT_PRT_ERROR,
1097b0a2fdeeSScott Long 	MPT_PRT_WARN,
1098b0a2fdeeSScott Long 	MPT_PRT_INFO,
1099ac219b98SMatt Jacob 	MPT_PRT_NEGOTIATION,
1100b0a2fdeeSScott Long 	MPT_PRT_DEBUG,
1101c87e3f83SMatt Jacob 	MPT_PRT_DEBUG1,
1102c87e3f83SMatt Jacob 	MPT_PRT_DEBUG2,
1103c87e3f83SMatt Jacob 	MPT_PRT_DEBUG3,
1104444dd2b6SMatt Jacob 	MPT_PRT_TRACE,
1105444dd2b6SMatt Jacob 	MPT_PRT_NONE=100
1106b0a2fdeeSScott Long };
1107b0a2fdeeSScott Long 
1108c87e3f83SMatt Jacob #if __FreeBSD_version > 500000
1109b0a2fdeeSScott Long #define mpt_lprt(mpt, level, ...)		\
1110b0a2fdeeSScott Long do {						\
1111b0a2fdeeSScott Long 	if (level <= (mpt)->verbose)		\
1112b0a2fdeeSScott Long 		mpt_prt(mpt, __VA_ARGS__);	\
1113b0a2fdeeSScott Long } while (0)
1114b0a2fdeeSScott Long 
1115b0a2fdeeSScott Long #define mpt_lprtc(mpt, level, ...)		 \
1116b0a2fdeeSScott Long do {						 \
1117b0a2fdeeSScott Long 	if (level <= (mpt)->debug_level)	 \
1118b0a2fdeeSScott Long 		mpt_prtc(mpt, __VA_ARGS__);	 \
1119b0a2fdeeSScott Long } while (0)
1120c87e3f83SMatt Jacob #else
1121c87e3f83SMatt Jacob void mpt_lprt(struct mpt_softc *, int, const char *, ...)
1122c87e3f83SMatt Jacob 	__printflike(3, 4);
1123c87e3f83SMatt Jacob void mpt_lprtc(struct mpt_softc *, int, const char *, ...)
1124c87e3f83SMatt Jacob 	__printflike(3, 4);
1125c87e3f83SMatt Jacob #endif
1126c87e3f83SMatt Jacob void mpt_prt(struct mpt_softc *, const char *, ...)
1127c87e3f83SMatt Jacob 	__printflike(2, 3);
1128c87e3f83SMatt Jacob void mpt_prtc(struct mpt_softc *, const char *, ...)
1129c87e3f83SMatt Jacob 	__printflike(2, 3);
1130b0a2fdeeSScott Long 
1131c87e3f83SMatt Jacob /**************************** Target Mode Related ***************************/
1132c87e3f83SMatt Jacob static __inline int mpt_cdblen(uint8_t, int);
1133c87e3f83SMatt Jacob static __inline int
1134c87e3f83SMatt Jacob mpt_cdblen(uint8_t cdb0, int maxlen)
1135c87e3f83SMatt Jacob {
1136c87e3f83SMatt Jacob 	int group = cdb0 >> 5;
1137c87e3f83SMatt Jacob 	switch (group) {
1138c87e3f83SMatt Jacob 	case 0:
1139c87e3f83SMatt Jacob 		return (6);
1140c87e3f83SMatt Jacob 	case 1:
1141c87e3f83SMatt Jacob 		return (10);
1142c87e3f83SMatt Jacob 	case 4:
1143c87e3f83SMatt Jacob 	case 5:
1144c87e3f83SMatt Jacob 		return (12);
1145c87e3f83SMatt Jacob 	default:
1146c87e3f83SMatt Jacob 		return (16);
1147c87e3f83SMatt Jacob 	}
1148c87e3f83SMatt Jacob }
1149c87e3f83SMatt Jacob #ifdef	INVARIANTS
1150c87e3f83SMatt Jacob static __inline request_t * mpt_tag_2_req(struct mpt_softc *, uint32_t);
1151c87e3f83SMatt Jacob static __inline request_t *
1152c87e3f83SMatt Jacob mpt_tag_2_req(struct mpt_softc *mpt, uint32_t tag)
1153c87e3f83SMatt Jacob {
11545e073106SMatt Jacob 	uint16_t rtg = (tag >> 18);
1155c87e3f83SMatt Jacob 	KASSERT(rtg < mpt->tgt_cmds_allocated, ("bad tag %d\n", tag));
1156c87e3f83SMatt Jacob 	KASSERT(mpt->tgt_cmd_ptrs, ("no cmd backpointer array"));
1157c87e3f83SMatt Jacob 	KASSERT(mpt->tgt_cmd_ptrs[rtg], ("no cmd backpointer"));
1158c87e3f83SMatt Jacob 	return (mpt->tgt_cmd_ptrs[rtg]);
1159c87e3f83SMatt Jacob }
1160*cd23a6e0SMarius Strobl #endif
11615089bd63SMatt Jacob 
11625089bd63SMatt Jacob static __inline int
11635089bd63SMatt Jacob mpt_req_on_free_list(struct mpt_softc *, request_t *);
11645089bd63SMatt Jacob static __inline int
11655089bd63SMatt Jacob mpt_req_on_pending_list(struct mpt_softc *, request_t *);
11665089bd63SMatt Jacob 
11675089bd63SMatt Jacob /*
11685089bd63SMatt Jacob  * Is request on freelist?
11695089bd63SMatt Jacob  */
11705089bd63SMatt Jacob static __inline int
11715089bd63SMatt Jacob mpt_req_on_free_list(struct mpt_softc *mpt, request_t *req)
11725089bd63SMatt Jacob {
11735089bd63SMatt Jacob 	request_t *lrq;
11745089bd63SMatt Jacob 
11755089bd63SMatt Jacob 	TAILQ_FOREACH(lrq, &mpt->request_free_list, links) {
11765089bd63SMatt Jacob 		if (lrq == req) {
11775089bd63SMatt Jacob 			return (1);
11785089bd63SMatt Jacob 		}
11795089bd63SMatt Jacob 	}
11805089bd63SMatt Jacob 	return (0);
11815089bd63SMatt Jacob }
11825089bd63SMatt Jacob 
11835089bd63SMatt Jacob /*
11845089bd63SMatt Jacob  * Is request on pending list?
11855089bd63SMatt Jacob  */
11865089bd63SMatt Jacob static __inline int
11875089bd63SMatt Jacob mpt_req_on_pending_list(struct mpt_softc *mpt, request_t *req)
11885089bd63SMatt Jacob {
11895089bd63SMatt Jacob 	request_t *lrq;
11905089bd63SMatt Jacob 
11915089bd63SMatt Jacob 	TAILQ_FOREACH(lrq, &mpt->request_pending_list, links) {
11925089bd63SMatt Jacob 		if (lrq == req) {
11935089bd63SMatt Jacob 			return (1);
11945089bd63SMatt Jacob 		}
11955089bd63SMatt Jacob 	}
11965089bd63SMatt Jacob 	return (0);
11975089bd63SMatt Jacob }
11985089bd63SMatt Jacob 
1199*cd23a6e0SMarius Strobl #ifdef	INVARIANTS
1200*cd23a6e0SMarius Strobl static __inline void
1201*cd23a6e0SMarius Strobl mpt_req_spcl(struct mpt_softc *, request_t *, const char *, int);
1202*cd23a6e0SMarius Strobl static __inline void
1203*cd23a6e0SMarius Strobl mpt_req_not_spcl(struct mpt_softc *, request_t *, const char *, int);
1204*cd23a6e0SMarius Strobl 
12055089bd63SMatt Jacob /*
12065089bd63SMatt Jacob  * Make sure that req *is* part of one of the special lists
12075089bd63SMatt Jacob  */
12085089bd63SMatt Jacob static __inline void
12095089bd63SMatt Jacob mpt_req_spcl(struct mpt_softc *mpt, request_t *req, const char *s, int line)
12105089bd63SMatt Jacob {
12115089bd63SMatt Jacob 	int i;
12125089bd63SMatt Jacob 	for (i = 0; i < mpt->els_cmds_allocated; i++) {
12135089bd63SMatt Jacob 		if (req == mpt->els_cmd_ptrs[i]) {
12145089bd63SMatt Jacob 			return;
12155089bd63SMatt Jacob 		}
12165089bd63SMatt Jacob 	}
12175089bd63SMatt Jacob 	for (i = 0; i < mpt->tgt_cmds_allocated; i++) {
12185089bd63SMatt Jacob 		if (req == mpt->tgt_cmd_ptrs[i]) {
12195089bd63SMatt Jacob 			return;
12205089bd63SMatt Jacob 		}
12215089bd63SMatt Jacob 	}
12225089bd63SMatt Jacob 	panic("%s(%d): req %p:%u function %x not in els or tgt ptrs\n",
12235089bd63SMatt Jacob 	    s, line, req, req->serno,
12245089bd63SMatt Jacob 	    ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function);
12255089bd63SMatt Jacob }
12265089bd63SMatt Jacob 
12275089bd63SMatt Jacob /*
12285089bd63SMatt Jacob  * Make sure that req is *not* part of one of the special lists.
12295089bd63SMatt Jacob  */
12305089bd63SMatt Jacob static __inline void
12315089bd63SMatt Jacob mpt_req_not_spcl(struct mpt_softc *mpt, request_t *req, const char *s, int line)
12325089bd63SMatt Jacob {
12335089bd63SMatt Jacob 	int i;
12345089bd63SMatt Jacob 	for (i = 0; i < mpt->els_cmds_allocated; i++) {
12355089bd63SMatt Jacob 		KASSERT(req != mpt->els_cmd_ptrs[i],
12365089bd63SMatt Jacob 		    ("%s(%d): req %p:%u func %x in els ptrs at ioindex %d\n",
12375089bd63SMatt Jacob 		    s, line, req, req->serno,
12385089bd63SMatt Jacob 		    ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function, i));
12395089bd63SMatt Jacob 	}
12405089bd63SMatt Jacob 	for (i = 0; i < mpt->tgt_cmds_allocated; i++) {
12415089bd63SMatt Jacob 		KASSERT(req != mpt->tgt_cmd_ptrs[i],
12425089bd63SMatt Jacob 		    ("%s(%d): req %p:%u func %x in tgt ptrs at ioindex %d\n",
12435089bd63SMatt Jacob 		    s, line, req, req->serno,
12445089bd63SMatt Jacob 		    ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function, i));
12455089bd63SMatt Jacob 	}
12465089bd63SMatt Jacob }
1247c87e3f83SMatt Jacob #endif
1248c87e3f83SMatt Jacob 
124973651fd1SMatt Jacob /*
125073651fd1SMatt Jacob  * Task Management Types, purely for internal consumption
125173651fd1SMatt Jacob  */
1252c87e3f83SMatt Jacob typedef enum {
1253c87e3f83SMatt Jacob 	MPT_ABORT_TASK_SET=1234,
1254c87e3f83SMatt Jacob 	MPT_CLEAR_TASK_SET,
1255c87e3f83SMatt Jacob 	MPT_TARGET_RESET,
1256c87e3f83SMatt Jacob 	MPT_CLEAR_ACA,
1257c87e3f83SMatt Jacob 	MPT_TERMINATE_TASK,
1258c87e3f83SMatt Jacob 	MPT_NIL_TMT_VALUE=5678
1259c87e3f83SMatt Jacob } mpt_task_mgmt_t;
1260b0a2fdeeSScott Long 
1261b0a2fdeeSScott Long /**************************** Unclassified Routines ***************************/
1262b0a2fdeeSScott Long void		mpt_send_cmd(struct mpt_softc *mpt, request_t *req);
1263b0a2fdeeSScott Long int		mpt_recv_handshake_reply(struct mpt_softc *mpt,
1264b0a2fdeeSScott Long 					 size_t reply_len, void *reply);
1265b0a2fdeeSScott Long int		mpt_wait_req(struct mpt_softc *mpt, request_t *req,
1266b0a2fdeeSScott Long 			     mpt_req_state_t state, mpt_req_state_t mask,
1267b0a2fdeeSScott Long 			     int sleep_ok, int time_ms);
1268b0a2fdeeSScott Long void		mpt_enable_ints(struct mpt_softc *mpt);
1269b0a2fdeeSScott Long void		mpt_disable_ints(struct mpt_softc *mpt);
1270b0a2fdeeSScott Long int		mpt_attach(struct mpt_softc *mpt);
1271b0a2fdeeSScott Long int		mpt_shutdown(struct mpt_softc *mpt);
1272b0a2fdeeSScott Long int		mpt_detach(struct mpt_softc *mpt);
1273b0a2fdeeSScott Long int		mpt_send_handshake_cmd(struct mpt_softc *mpt,
1274b0a2fdeeSScott Long 				       size_t len, void *cmd);
1275b0a2fdeeSScott Long request_t *	mpt_get_request(struct mpt_softc *mpt, int sleep_ok);
1276b0a2fdeeSScott Long void		mpt_free_request(struct mpt_softc *mpt, request_t *req);
1277b0a2fdeeSScott Long void		mpt_intr(void *arg);
1278b0a2fdeeSScott Long void		mpt_check_doorbell(struct mpt_softc *mpt);
1279b0a2fdeeSScott Long void		mpt_dump_reply_frame(struct mpt_softc *mpt,
1280b0a2fdeeSScott Long 				     MSG_DEFAULT_REPLY *reply_frame);
1281b0a2fdeeSScott Long 
1282b0a2fdeeSScott Long void		mpt_set_config_regs(struct mpt_softc *);
1283b0a2fdeeSScott Long int		mpt_issue_cfg_req(struct mpt_softc */*mpt*/, request_t */*req*/,
12841d558d6aSScott Long 				  cfgparms_t *params,
1285b0a2fdeeSScott Long 				  bus_addr_t /*addr*/, bus_size_t/*len*/,
1286b0a2fdeeSScott Long 				  int /*sleep_ok*/, int /*timeout_ms*/);
12871d558d6aSScott Long int		mpt_read_extcfg_header(struct mpt_softc *mpt, int PageVersion,
12881d558d6aSScott Long 				       int PageNumber, uint32_t PageAddress,
12891d558d6aSScott Long 				       int ExtPageType,
12901d558d6aSScott Long 				       CONFIG_EXTENDED_PAGE_HEADER *rslt,
12911d558d6aSScott Long 				       int sleep_ok, int timeout_ms);
12921d558d6aSScott Long int		mpt_read_extcfg_page(struct mpt_softc *mpt, int Action,
12931d558d6aSScott Long 				     uint32_t PageAddress,
12941d558d6aSScott Long 				     CONFIG_EXTENDED_PAGE_HEADER *hdr,
12951d558d6aSScott Long 				     void *buf, size_t len, int sleep_ok,
12961d558d6aSScott Long 				     int timeout_ms);
1297b0a2fdeeSScott Long int		mpt_read_cfg_header(struct mpt_softc *, int /*PageType*/,
1298b0a2fdeeSScott Long 				    int /*PageNumber*/,
1299b0a2fdeeSScott Long 				    uint32_t /*PageAddress*/,
1300b0a2fdeeSScott Long 				    CONFIG_PAGE_HEADER *,
1301b0a2fdeeSScott Long 				    int /*sleep_ok*/, int /*timeout_ms*/);
1302b0a2fdeeSScott Long int		mpt_read_cfg_page(struct mpt_softc *t, int /*Action*/,
1303b0a2fdeeSScott Long 				  uint32_t /*PageAddress*/,
1304b0a2fdeeSScott Long 				  CONFIG_PAGE_HEADER *, size_t /*len*/,
1305b0a2fdeeSScott Long 				  int /*sleep_ok*/, int /*timeout_ms*/);
1306b0a2fdeeSScott Long int		mpt_write_cfg_page(struct mpt_softc *, int /*Action*/,
1307b0a2fdeeSScott Long 				   uint32_t /*PageAddress*/,
1308b0a2fdeeSScott Long 				   CONFIG_PAGE_HEADER *, size_t /*len*/,
1309b0a2fdeeSScott Long 				   int /*sleep_ok*/, int /*timeout_ms*/);
1310b0a2fdeeSScott Long static __inline int
1311b0a2fdeeSScott Long mpt_read_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress,
1312b0a2fdeeSScott Long 		      CONFIG_PAGE_HEADER *hdr, size_t len,
1313b0a2fdeeSScott Long 		      int sleep_ok, int timeout_ms)
1314b0a2fdeeSScott Long {
1315b0a2fdeeSScott Long 	return (mpt_read_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_READ_CURRENT,
1316b0a2fdeeSScott Long 				  PageAddress, hdr, len, sleep_ok, timeout_ms));
1317b0a2fdeeSScott Long }
1318b0a2fdeeSScott Long 
1319b0a2fdeeSScott Long static __inline int
1320b0a2fdeeSScott Long mpt_write_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress,
1321b0a2fdeeSScott Long 		       CONFIG_PAGE_HEADER *hdr, size_t len, int sleep_ok,
1322b0a2fdeeSScott Long 		       int timeout_ms)
1323b0a2fdeeSScott Long {
1324b0a2fdeeSScott Long 	return (mpt_write_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT,
1325b0a2fdeeSScott Long 				   PageAddress, hdr, len, sleep_ok,
1326b0a2fdeeSScott Long 				   timeout_ms));
1327b0a2fdeeSScott Long }
13289b631363SMatt Jacob /* mpt_debug.c functions */
13299b631363SMatt Jacob void mpt_print_reply(void *vmsg);
1330b0a2fdeeSScott Long void mpt_print_db(uint32_t mb);
13319b631363SMatt Jacob void mpt_print_config_reply(void *vmsg);
1332b0a2fdeeSScott Long char *mpt_ioc_diag(uint32_t diag);
1333b0a2fdeeSScott Long void mpt_req_state(mpt_req_state_t state);
13349b631363SMatt Jacob void mpt_print_config_request(void *vmsg);
13359b631363SMatt Jacob void mpt_print_request(void *vmsg);
1336b0a2fdeeSScott Long void mpt_print_scsi_io_request(MSG_SCSI_IO_REQUEST *msg);
1337444dd2b6SMatt Jacob void mpt_dump_sgl(SGE_IO_UNION *se, int offset);
13389b631363SMatt Jacob #endif /* _MPT_H_ */
1339