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