c3c2720766a0db8274f563addda3270d1da48a21
[dragonfly.git] / sys / dev / disk / mpt / mpt.h
1 /* $FreeBSD: src/sys/dev/mpt/mpt.h,v 1.60 2012/03/24 00:30:17 marius Exp $ */
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 #include <sys/kernel.h>
109 #include <sys/queue.h>
110 #include <sys/malloc.h>
111 #include <sys/proc.h>
112 #include <sys/bus.h>
113 #include <sys/module.h>
114 #include <sys/thread2.h>
115 #include <sys/mplock2.h>
116
117 #include <sys/rman.h>
118 #include <sys/sysctl.h>
119
120 #include <bus/pci/pcireg.h>
121 #include <bus/pci/pcivar.h>
122
123 /**************************** Register Definitions ****************************/
124 #include <dev/disk/mpt/mpt_reg.h>
125
126 /******************************* MPI Definitions ******************************/
127 #include <dev/disk/mpt/mpilib/mpi_type.h>
128 #include <dev/disk/mpt/mpilib/mpi.h>
129 #include <dev/disk/mpt/mpilib/mpi_cnfg.h>
130 #include <dev/disk/mpt/mpilib/mpi_ioc.h>
131 #include <dev/disk/mpt/mpilib/mpi_raid.h>
132
133 /* XXX For mpt_debug.c */
134 #include <dev/disk/mpt/mpilib/mpi_init.h>
135
136 #define MPT_S64_2_SCALAR(y)     ((((int64_t)y.High) << 32) | (y.Low))
137 #define MPT_U64_2_SCALAR(y)     ((((uint64_t)y.High) << 32) | (y.Low))
138
139 /****************************** Misc Definitions ******************************/
140 /* #define MPT_TEST_MULTIPATH   1 */
141 #define MPT_OK (0)
142 #define MPT_FAIL (0x10000)
143
144 #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array))
145
146 #define MPT_ROLE_NONE           0
147 #define MPT_ROLE_INITIATOR      1
148 #define MPT_ROLE_TARGET         2
149 #define MPT_ROLE_BOTH           3
150 #define MPT_ROLE_DEFAULT        MPT_ROLE_INITIATOR
151
152 #define MPT_INI_ID_NONE         -1
153
154 /**************************** Forward Declarations ****************************/
155 struct mpt_softc;
156 struct mpt_personality;
157 typedef struct req_entry request_t;
158
159 /************************* Personality Module Support *************************/
160 typedef int mpt_load_handler_t(struct mpt_personality *);
161 typedef int mpt_probe_handler_t(struct mpt_softc *);
162 typedef int mpt_attach_handler_t(struct mpt_softc *);
163 typedef int mpt_enable_handler_t(struct mpt_softc *);
164 typedef void mpt_ready_handler_t(struct mpt_softc *);
165 typedef int mpt_event_handler_t(struct mpt_softc *, request_t *,
166                                 MSG_EVENT_NOTIFY_REPLY *);
167 typedef void mpt_reset_handler_t(struct mpt_softc *, int /*type*/);
168 /* XXX Add return value and use for veto? */
169 typedef void mpt_shutdown_handler_t(struct mpt_softc *);
170 typedef void mpt_detach_handler_t(struct mpt_softc *);
171 typedef int mpt_unload_handler_t(struct mpt_personality *);
172
173 struct mpt_personality
174 {
175         const char              *name;
176         uint32_t                 id;            /* Assigned identifier. */
177         u_int                    use_count;     /* Instances using personality*/
178         mpt_load_handler_t      *load;          /* configure personailty */
179 #define MPT_PERS_FIRST_HANDLER(pers) (&(pers)->load)
180         mpt_probe_handler_t     *probe;         /* configure personailty */
181         mpt_attach_handler_t    *attach;        /* initialize device instance */
182         mpt_enable_handler_t    *enable;        /* enable device */
183         mpt_ready_handler_t     *ready;         /* final open for business */
184         mpt_event_handler_t     *event;         /* Handle MPI event. */
185         mpt_reset_handler_t     *reset;         /* Re-init after reset. */
186         mpt_shutdown_handler_t  *shutdown;      /* Shutdown instance. */
187         mpt_detach_handler_t    *detach;        /* release device instance */
188         mpt_unload_handler_t    *unload;        /* Shutdown personality */
189 #define MPT_PERS_LAST_HANDLER(pers) (&(pers)->unload)
190 };
191
192 int mpt_modevent(module_t, int, void *);
193
194 /* Maximum supported number of personalities. */
195 #define MPT_MAX_PERSONALITIES   (15)
196
197 #define MPT_PERSONALITY_DEPEND(name, dep, vmin, vpref, vmax) \
198         MODULE_DEPEND(name, dep, vmin, vpref, vmax)
199
200 #define DECLARE_MPT_PERSONALITY(name, order)                              \
201         static moduledata_t name##_mod = {                                \
202                 #name, mpt_modevent, &name##_personality                  \
203         };                                                                \
204         DECLARE_MODULE(name, name##_mod, SI_SUB_DRIVERS, order);          \
205         MODULE_VERSION(name, 1);                                          \
206         MPT_PERSONALITY_DEPEND(name, mpt_core, 1, 1, 1)
207
208 /******************************* Bus DMA Support ******************************/
209 /* XXX Need to update bus_dmamap_sync to take a range argument. */
210 #define bus_dmamap_sync_range(dma_tag, dmamap, offset, len, op) \
211         bus_dmamap_sync(dma_tag, dmamap, op)
212
213 #define mpt_dma_tag_create(mpt, parent_tag, alignment, boundary,        \
214                            lowaddr, highaddr, filter, filterarg,        \
215                            maxsize, nsegments, maxsegsz, flags,         \
216                            dma_tagp)                                    \
217         bus_dma_tag_create(parent_tag, alignment, boundary,             \
218                            lowaddr, highaddr, filter, filterarg,        \
219                            maxsize, nsegments, maxsegsz, flags,         \
220                            dma_tagp)
221
222 struct mpt_map_info {
223         struct mpt_softc *mpt;
224         int               error;
225         uint32_t          phys;
226 };
227
228 void mpt_map_rquest(void *, bus_dma_segment_t *, int, int);
229 /* **************************** NewBUS interrupt Crock ************************/
230 #define mpt_setup_intr(d, i, f, U, if, ifa, hp) \
231         bus_setup_intr(d, i, f, if, ifa, hp, NULL)
232
233 /* **************************** NewBUS CAM Support ****************************/
234 #define mpt_xpt_bus_register(sim, parent, bus)  \
235         xpt_bus_register(sim, bus)
236
237 /**************************** Kernel Thread Support ***************************/
238 #define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \
239         kthread_create(func, farg, proc_ptr, fmtstr, arg)
240 #define mpt_kthread_exit(status)        \
241         kthread_exit()
242
243 /********************************** Endianess *********************************/
244 #define MPT_2_HOST64(ptr, tag)  ptr->tag = le64toh(ptr->tag)
245 #define MPT_2_HOST32(ptr, tag)  ptr->tag = le32toh(ptr->tag)
246 #define MPT_2_HOST16(ptr, tag)  ptr->tag = le16toh(ptr->tag)
247
248 #define HOST_2_MPT64(ptr, tag)  ptr->tag = htole64(ptr->tag)
249 #define HOST_2_MPT32(ptr, tag)  ptr->tag = htole32(ptr->tag)
250 #define HOST_2_MPT16(ptr, tag)  ptr->tag = htole16(ptr->tag)
251
252 #if     _BYTE_ORDER == _BIG_ENDIAN
253 void mpt2host_sge_simple_union(SGE_SIMPLE_UNION *);
254 void mpt2host_iocfacts_reply(MSG_IOC_FACTS_REPLY *);
255 void mpt2host_portfacts_reply(MSG_PORT_FACTS_REPLY *);
256 void mpt2host_config_page_ioc2(CONFIG_PAGE_IOC_2 *);
257 void mpt2host_config_page_ioc3(CONFIG_PAGE_IOC_3 *);
258 void mpt2host_config_page_scsi_port_0(CONFIG_PAGE_SCSI_PORT_0 *);
259 void mpt2host_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *);
260 void host2mpt_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *);
261 void mpt2host_config_page_scsi_port_2(CONFIG_PAGE_SCSI_PORT_2 *);
262 void mpt2host_config_page_scsi_device_0(CONFIG_PAGE_SCSI_DEVICE_0 *);
263 void mpt2host_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *);
264 void host2mpt_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *);
265 void mpt2host_config_page_fc_port_0(CONFIG_PAGE_FC_PORT_0 *);
266 void mpt2host_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *);
267 void host2mpt_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *);
268 void mpt2host_config_page_raid_vol_0(CONFIG_PAGE_RAID_VOL_0 *);
269 void mpt2host_config_page_raid_phys_disk_0(CONFIG_PAGE_RAID_PHYS_DISK_0 *);
270 void mpt2host_mpi_raid_vol_indicator(MPI_RAID_VOL_INDICATOR *);
271 #else
272 #define mpt2host_sge_simple_union(x)            do { ; } while (0)
273 #define mpt2host_iocfacts_reply(x)              do { ; } while (0)
274 #define mpt2host_portfacts_reply(x)             do { ; } while (0)
275 #define mpt2host_config_page_ioc2(x)            do { ; } while (0)
276 #define mpt2host_config_page_ioc3(x)            do { ; } while (0)
277 #define mpt2host_config_page_scsi_port_0(x)     do { ; } while (0)
278 #define mpt2host_config_page_scsi_port_1(x)     do { ; } while (0)
279 #define host2mpt_config_page_scsi_port_1(x)     do { ; } while (0)
280 #define mpt2host_config_page_scsi_port_2(x)     do { ; } while (0)
281 #define mpt2host_config_page_scsi_device_0(x)   do { ; } while (0)
282 #define mpt2host_config_page_scsi_device_1(x)   do { ; } while (0)
283 #define host2mpt_config_page_scsi_device_1(x)   do { ; } while (0)
284 #define mpt2host_config_page_fc_port_0(x)       do { ; } while (0)
285 #define mpt2host_config_page_fc_port_1(x)       do { ; } while (0)
286 #define host2mpt_config_page_fc_port_1(x)       do { ; } while (0)
287 #define mpt2host_config_page_raid_vol_0(x)      do { ; } while (0)
288 #define mpt2host_config_page_raid_phys_disk_0(x)                        \
289         do { ; } while (0)
290 #define mpt2host_mpi_raid_vol_indicator(x)      do { ; } while (0)
291 #endif
292
293 /**************************** MPI Transaction State ***************************/
294 typedef enum {
295         REQ_STATE_NIL           = 0x00,
296         REQ_STATE_FREE          = 0x01,
297         REQ_STATE_ALLOCATED     = 0x02,
298         REQ_STATE_QUEUED        = 0x04,
299         REQ_STATE_DONE          = 0x08,
300         REQ_STATE_TIMEDOUT      = 0x10,
301         REQ_STATE_NEED_WAKEUP   = 0x20,
302         REQ_STATE_LOCKED        = 0x80, /* can't be freed */
303         REQ_STATE_MASK          = 0xFF
304 } mpt_req_state_t;
305
306 struct req_entry {
307         TAILQ_ENTRY(req_entry) links;   /* Pointer to next in list */
308         mpt_req_state_t state;          /* Request State Information */
309         uint16_t        index;          /* Index of this entry */
310         uint16_t        IOCStatus;      /* Completion status */
311         uint16_t        ResponseCode;   /* TMF Response Code */
312         uint16_t        serno;          /* serial number */
313         union ccb      *ccb;            /* CAM request */
314         void           *req_vbuf;       /* Virtual Address of Entry */
315         void           *sense_vbuf;     /* Virtual Address of sense data */
316         bus_addr_t      req_pbuf;       /* Physical Address of Entry */
317         bus_addr_t      sense_pbuf;     /* Physical Address of sense data */
318         bus_dmamap_t    dmap;           /* DMA map for data buffers */
319         struct req_entry *chain;        /* for SGE overallocations */
320         struct callout  callout;        /* Timeout for the request */
321 };
322
323 typedef struct mpt_config_params {
324         u_int           Action;
325         u_int           PageVersion;
326         u_int           PageLength;
327         u_int           PageNumber;
328         u_int           PageType;
329         u_int           PageAddress;
330         u_int           ExtPageLength;
331         u_int           ExtPageType;
332 } cfgparms_t;
333
334 /**************************** MPI Target State Info ***************************/
335
336 typedef struct {
337         uint32_t reply_desc;    /* current reply descriptor */
338         uint32_t resid;         /* current data residual */
339         uint32_t bytes_xfered;  /* current relative offset */
340         union ccb *ccb;         /* pointer to currently active ccb */
341         request_t *req;         /* pointer to currently active assist request */
342         uint32_t
343                 is_local : 1,
344                 nxfers   : 31;
345         uint32_t tag_id;
346         enum {
347                 TGT_STATE_NIL,
348                 TGT_STATE_LOADING,
349                 TGT_STATE_LOADED,
350                 TGT_STATE_IN_CAM,
351                 TGT_STATE_SETTING_UP_FOR_DATA,
352                 TGT_STATE_MOVING_DATA,
353                 TGT_STATE_MOVING_DATA_AND_STATUS,
354                 TGT_STATE_SENDING_STATUS
355         } state;
356 } mpt_tgt_state_t;
357
358 /*
359  * When we get an incoming command it has its own tag which is called the
360  * IoIndex. This is the value we gave that particular command buffer when
361  * we originally assigned it. It's just a number, really. The FC card uses
362  * it as an RX_ID. We can use it to index into mpt->tgt_cmd_ptrs, which
363  * contains pointers the request_t structures related to that IoIndex.
364  *
365  * What *we* do is construct a tag out of the index for the target command
366  * which owns the incoming ATIO plus a rolling sequence number.
367  */
368 #define MPT_MAKE_TAGID(mpt, req, ioindex)       \
369  ((ioindex << 18) | (((mpt->sequence++) & 0x3f) << 12) | (req->index & 0xfff))
370
371 #ifdef  INVARIANTS
372 #define MPT_TAG_2_REQ(a, b)             mpt_tag_2_req(a, (uint32_t) b)
373 #else
374 #define MPT_TAG_2_REQ(mpt, tag)         mpt->tgt_cmd_ptrs[tag >> 18]
375 #endif
376
377 #define MPT_TGT_STATE(mpt, req) ((mpt_tgt_state_t *) \
378     (&((uint8_t *)req->req_vbuf)[MPT_RQSL(mpt) - sizeof (mpt_tgt_state_t)]))
379
380 STAILQ_HEAD(mpt_hdr_stailq, ccb_hdr);
381 #define MPT_MAX_LUNS    256
382 typedef struct {
383         struct mpt_hdr_stailq   atios;
384         struct mpt_hdr_stailq   inots;
385         int enabled;
386 } tgt_resource_t;
387 #define MPT_MAX_ELS     64
388
389 /**************************** Handler Registration ****************************/
390 /*
391  * Global table of registered reply handlers.  The
392  * handler is indicated by byte 3 of the request
393  * index submitted to the IOC.  This allows the
394  * driver core to perform generic processing without
395  * any knowledge of per-personality behavior.
396  *
397  * MPT_NUM_REPLY_HANDLERS must be a power of 2
398  * to allow the easy generation of a mask.
399  *
400  * The handler offsets used by the core are hard coded
401  * allowing faster code generation when assigning a handler
402  * to a request.  All "personalities" must use the
403  * the handler registration mechanism.
404  *
405  * The IOC handlers that are rarely executed are placed
406  * at the tail of the table to make it more likely that
407  * all commonly executed handlers fit in a single cache
408  * line.
409  */
410 #define MPT_NUM_REPLY_HANDLERS          (32)
411 #define MPT_REPLY_HANDLER_EVENTS        MPT_CBI_TO_HID(0)
412 #define MPT_REPLY_HANDLER_CONFIG        MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-1)
413 #define MPT_REPLY_HANDLER_HANDSHAKE     MPT_CBI_TO_HID(MPT_NUM_REPLY_HANDLERS-2)
414 typedef int mpt_reply_handler_t(struct mpt_softc *mpt, request_t *request,
415     uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame);
416 typedef union {
417         mpt_reply_handler_t     *reply_handler;
418 } mpt_handler_t;
419
420 typedef enum {
421         MPT_HANDLER_REPLY,
422         MPT_HANDLER_EVENT,
423         MPT_HANDLER_RESET,
424         MPT_HANDLER_SHUTDOWN
425 } mpt_handler_type;
426
427 struct mpt_handler_record
428 {
429         LIST_ENTRY(mpt_handler_record)  links;
430         mpt_handler_t                   handler;
431 };
432
433 LIST_HEAD(mpt_handler_list, mpt_handler_record);
434
435 /*
436  * The handler_id is currently unused but would contain the
437  * handler ID used in the MsgContext field to allow direction
438  * of replies to the handler.  Registrations that don't require
439  * a handler id can pass in NULL for the handler_id.
440  *
441  * Deregistrations for handlers without a handler id should
442  * pass in MPT_HANDLER_ID_NONE.
443  */
444 #define MPT_HANDLER_ID_NONE             (0xFFFFFFFF)
445 int mpt_register_handler(struct mpt_softc *, mpt_handler_type,
446                          mpt_handler_t, uint32_t *);
447 int mpt_deregister_handler(struct mpt_softc *, mpt_handler_type,
448                            mpt_handler_t, uint32_t);
449
450 /******************* Per-Controller Instance Data Structures ******************/
451 TAILQ_HEAD(req_queue, req_entry);
452
453 /* Structure for saving proper values for modifyable PCI config registers */
454 struct mpt_pci_cfg {
455         uint16_t Command;
456         uint16_t LatencyTimer_LineSize;
457         uint32_t IO_BAR;
458         uint32_t Mem0_BAR[2];
459         uint32_t Mem1_BAR[2];
460         uint32_t ROM_BAR;
461         uint8_t  IntLine;
462         uint32_t PMCSR;
463 };
464
465 typedef enum {
466         MPT_RVF_NONE            = 0x0,
467         MPT_RVF_ACTIVE          = 0x1,
468         MPT_RVF_ANNOUNCED       = 0x2,
469         MPT_RVF_UP2DATE         = 0x4,
470         MPT_RVF_REFERENCED      = 0x8,
471         MPT_RVF_WCE_CHANGED     = 0x10
472 } mpt_raid_volume_flags;
473
474 struct mpt_raid_volume {
475         CONFIG_PAGE_RAID_VOL_0         *config_page;
476         MPI_RAID_VOL_INDICATOR          sync_progress;
477         mpt_raid_volume_flags           flags;
478         u_int                           quiesced_disks;
479 };
480
481 typedef enum {
482         MPT_RDF_NONE            = 0x00,
483         MPT_RDF_ACTIVE          = 0x01,
484         MPT_RDF_ANNOUNCED       = 0x02,
485         MPT_RDF_UP2DATE         = 0x04,
486         MPT_RDF_REFERENCED      = 0x08,
487         MPT_RDF_QUIESCING       = 0x10,
488         MPT_RDF_QUIESCED        = 0x20
489 } mpt_raid_disk_flags;
490
491 struct mpt_raid_disk {
492         CONFIG_PAGE_RAID_PHYS_DISK_0    config_page;
493         struct mpt_raid_volume         *volume;
494         u_int                           member_number;
495         u_int                           pass_thru_active;
496         mpt_raid_disk_flags             flags;
497 };
498
499 struct mpt_evtf_record {
500         MSG_EVENT_NOTIFY_REPLY          reply;
501         uint32_t                        context;
502         LIST_ENTRY(mpt_evtf_record)     links;
503 };
504
505 LIST_HEAD(mpt_evtf_list, mpt_evtf_record);
506
507 struct mptsas_devinfo {
508         uint16_t        dev_handle;
509         uint16_t        parent_dev_handle;
510         uint16_t        enclosure_handle;
511         uint16_t        slot;
512         uint8_t         phy_num;
513         uint8_t         physical_port;
514         uint8_t         target_id;
515         uint8_t         bus;
516         uint64_t        sas_address;
517         uint32_t        device_info;
518 };
519
520 struct mptsas_phyinfo {
521         uint16_t        handle;
522         uint8_t         phy_num;
523         uint8_t         port_id;
524         uint8_t         negotiated_link_rate;
525         uint8_t         hw_link_rate;
526         uint8_t         programmed_link_rate;
527         uint8_t         sas_port_add_phy;
528         struct mptsas_devinfo identify;
529         struct mptsas_devinfo attached;
530 };
531
532 struct mptsas_portinfo {
533         uint16_t                        num_phys;
534         struct mptsas_phyinfo           *phy_info;
535 };
536
537 struct mpt_softc {
538         device_t                dev;
539         struct lock             mpt_lock;
540         int                     mpt_locksetup;
541         uint32_t                mpt_pers_mask;
542         uint32_t
543                                 : 7,
544                 unit            : 8,
545                 ready           : 1,
546                 fw_uploaded     : 1,
547                 msi_enable      : 1,
548                 twildcard       : 1,
549                 tenabled        : 1,
550                 do_cfg_role     : 1,
551                 raid_enabled    : 1,
552                 raid_mwce_set   : 1,
553                 getreqwaiter    : 1,
554                 shutdwn_raid    : 1,
555                 shutdwn_recovery: 1,
556                 outofbeer       : 1,
557                 disabled        : 1,
558                 is_spi          : 1,
559                 is_sas          : 1,
560                 is_fc           : 1,
561                 is_1078         : 1;
562
563         u_int                   cfg_role;
564         u_int                   role;   /* role: none, ini, target, both */
565
566         u_int                   verbose;
567 #ifdef  MPT_TEST_MULTIPATH
568         int                     failure_id;
569 #endif
570
571         /*
572          * IOC Facts
573          */
574         MSG_IOC_FACTS_REPLY     ioc_facts;
575
576         /*
577          * Port Facts
578          */
579         MSG_PORT_FACTS_REPLY *  port_facts;
580 #define mpt_max_tgtcmds port_facts[0].MaxPostedCmdBuffers
581
582         /*
583          * Device Configuration Information
584          */
585         union {
586                 struct mpt_spi_cfg {
587                         CONFIG_PAGE_SCSI_PORT_0         _port_page0;
588                         CONFIG_PAGE_SCSI_PORT_1         _port_page1;
589                         CONFIG_PAGE_SCSI_PORT_2         _port_page2;
590                         CONFIG_PAGE_SCSI_DEVICE_0       _dev_page0[16];
591                         CONFIG_PAGE_SCSI_DEVICE_1       _dev_page1[16];
592                         int                             _ini_id;
593                         uint16_t                        _tag_enable;
594                         uint16_t                        _disc_enable;
595                 } spi;
596 #define mpt_port_page0          cfg.spi._port_page0
597 #define mpt_port_page1          cfg.spi._port_page1
598 #define mpt_port_page2          cfg.spi._port_page2
599 #define mpt_dev_page0           cfg.spi._dev_page0
600 #define mpt_dev_page1           cfg.spi._dev_page1
601 #define mpt_ini_id              cfg.spi._ini_id
602 #define mpt_tag_enable          cfg.spi._tag_enable
603 #define mpt_disc_enable         cfg.spi._disc_enable
604                 struct mpi_fc_cfg {
605                         CONFIG_PAGE_FC_PORT_0 _port_page0;
606                         uint32_t _port_speed;
607 #define mpt_fcport_page0        cfg.fc._port_page0
608 #define mpt_fcport_speed        cfg.fc._port_speed
609                 } fc;
610         } cfg;
611         /*
612          * Device config information stored up for sysctl to access
613          */
614         union {
615                 struct {
616                         unsigned int initiator_id;
617                 } spi;
618                 struct {
619                         char wwnn[19];
620                         char wwpn[19];
621                 } fc;
622         } scinfo;
623
624         /* Controller Info for RAID information */
625         CONFIG_PAGE_IOC_2 *     ioc_page2;
626         CONFIG_PAGE_IOC_3 *     ioc_page3;
627
628         /* Raid Data */
629         struct mpt_raid_volume* raid_volumes;
630         struct mpt_raid_disk*   raid_disks;
631         u_int                   raid_max_volumes;
632         u_int                   raid_max_disks;
633         u_int                   raid_page0_len;
634         u_int                   raid_wakeup;
635         u_int                   raid_rescan;
636         u_int                   raid_resync_rate;
637         u_int                   raid_mwce_setting;
638         u_int                   raid_queue_depth;
639         u_int                   raid_nonopt_volumes;
640         thread_t                raid_thread;
641         struct callout          raid_timer;
642
643         /*
644          * PCI Hardware info
645          */
646 #ifdef OLD_MSI
647         int                     pci_msi_count;
648 #endif
649         int                     irq_type;       /* Interrupt type */
650         struct resource *       pci_irq;        /* Interrupt map for chip */
651         void *                  ih;             /* Interrupt handle */
652 #if 0
653         struct mpt_pci_cfg      pci_cfg;        /* saved PCI conf registers */
654 #endif
655
656         /*
657          * DMA Mapping Stuff
658          */
659         struct resource *       pci_reg;        /* Register map for chip */
660         bus_space_tag_t         pci_st;         /* Bus tag for registers */
661         bus_space_handle_t      pci_sh;         /* Bus handle for registers */
662         /* PIO versions of above. */
663         struct resource *       pci_pio_reg;
664         bus_space_tag_t         pci_pio_st;
665         bus_space_handle_t      pci_pio_sh;
666
667         bus_dma_tag_t           parent_dmat;    /* DMA tag for parent PCI bus */
668         bus_dma_tag_t           reply_dmat;     /* DMA tag for reply memory */
669         bus_dmamap_t            reply_dmap;     /* DMA map for reply memory */
670         uint8_t                *reply;          /* KVA of reply memory */
671         bus_addr_t              reply_phys;     /* BusAddr of reply memory */
672
673         bus_dma_tag_t           buffer_dmat;    /* DMA tag for buffers */
674         bus_dma_tag_t           request_dmat;   /* DMA tag for request memroy */
675         bus_dmamap_t            request_dmap;   /* DMA map for request memroy */
676         uint8_t                *request;        /* KVA of Request memory */
677         bus_addr_t              request_phys;   /* BusAddr of request memory */
678
679         uint32_t                max_seg_cnt;    /* calculated after IOC facts */
680         uint32_t                max_cam_seg_cnt;/* calculated from MAXPHYS*/
681
682         /*
683          * Hardware management
684          */
685         u_int                   reset_cnt;
686
687         /*
688          * CAM && Software Management
689          */
690         request_t              *request_pool;
691         struct req_queue        request_free_list;
692         struct req_queue        request_pending_list;
693         struct req_queue        request_timeout_list;
694
695
696         struct cam_sim         *sim;
697         struct cam_path        *path;
698
699         struct cam_sim         *phydisk_sim;
700         struct cam_path        *phydisk_path;
701
702         thread_t               recovery_thread;
703         request_t              *tmf_req;
704
705         /*
706          * Deferred frame acks due to resource shortage.
707          */
708         struct mpt_evtf_list    ack_frames;
709
710         /*
711          * Target Mode Support
712          */
713         uint32_t                scsi_tgt_handler_id;
714         request_t **            tgt_cmd_ptrs;
715         request_t **            els_cmd_ptrs;   /* FC only */
716
717         /*
718          * *snork*- this is chosen to be here *just in case* somebody
719          * forgets to point to it exactly and we index off of trt with
720          * CAM_LUN_WILDCARD.
721          */
722         tgt_resource_t          trt_wildcard;           /* wildcard luns */
723         tgt_resource_t          trt[MPT_MAX_LUNS];
724         uint16_t                tgt_cmds_allocated;
725         uint16_t                els_cmds_allocated;     /* FC only */
726
727         uint16_t                timeouts;       /* timeout count */
728         uint16_t                success;        /* successes afer timeout */
729         uint16_t                sequence;       /* Sequence Number */
730         uint16_t                pad3;
731
732
733         /* Paired port in some dual adapters configurations */
734         struct mpt_softc *      mpt2;
735
736         /* FW Image management */
737         uint32_t                fw_image_size;
738         uint8_t                *fw_image;
739         bus_dma_tag_t           fw_dmat;        /* DMA tag for firmware image */
740         bus_dmamap_t            fw_dmap;        /* DMA map for firmware image */
741         bus_addr_t              fw_phys;        /* BusAddr of firmware image */
742
743         /* SAS Topology */
744         struct mptsas_portinfo  *sas_portinfo;
745
746         /* Shutdown Event Handler. */
747         eventhandler_tag         eh;
748
749         /* Userland management interface. */
750         struct cdev             *cdev;
751
752         struct sysctl_ctx_list          mpt_sysctl_ctx;
753         struct sysctl_oid               *mpt_sysctl_tree;
754
755         TAILQ_ENTRY(mpt_softc)  links;
756 };
757
758 static __inline void mpt_assign_serno(struct mpt_softc *, request_t *);
759
760 static __inline void
761 mpt_assign_serno(struct mpt_softc *mpt, request_t *req)
762 {
763         if ((req->serno = mpt->sequence++) == 0) {
764                 req->serno = mpt->sequence++;
765         }
766 }
767
768 /***************************** Locking Primitives *****************************/
769 #define MPT_IFLAGS              INTR_MPSAFE
770 #define MPT_LOCK_SETUP(mpt)                                             \
771                 lockinit(&mpt->mpt_lock, "mpt", 0, LK_CANRECURSE);      \
772                 mpt->mpt_locksetup = 1
773 #define MPT_LOCK_DESTROY(mpt)                                           \
774         if (mpt->mpt_locksetup) {                                       \
775                 lockuninit(&mpt->mpt_lock);                             \
776                 mpt->mpt_locksetup = 0;                                 \
777         }
778
779 #define MPT_LOCK(mpt)           lockmgr(&(mpt)->mpt_lock, LK_EXCLUSIVE)
780 #define MPT_UNLOCK(mpt)         lockmgr(&(mpt)->mpt_lock, LK_RELEASE)
781 #define MPT_OWNED(mpt)          lockstatus(&(mpt)->mpt_lock, curthread)
782 #define MPT_LOCK_ASSERT(mpt)    KKASSERT(lockstatus(&(mpt)->mpt_lock, curthread) != 0)
783 #define mpt_sleep(mpt, ident, priority, wmesg, timo) \
784         lksleep(ident, &(mpt)->mpt_lock, priority, wmesg, timo)
785 #define mpt_req_timeout(req, ticks, func, arg) \
786         callout_reset(&(req)->callout, (ticks), (func), (arg))
787 #define mpt_req_untimeout(req, func, arg) \
788         callout_stop(&(req)->callout)
789 #define mpt_callout_init(mpt, c) \
790         callout_init(c)
791
792 /******************************* Register Access ******************************/
793 static __inline void mpt_write(struct mpt_softc *, size_t, uint32_t);
794 static __inline uint32_t mpt_read(struct mpt_softc *, int);
795 static __inline void mpt_pio_write(struct mpt_softc *, size_t, uint32_t);
796 static __inline uint32_t mpt_pio_read(struct mpt_softc *, int);
797
798 static __inline void
799 mpt_write(struct mpt_softc *mpt, size_t offset, uint32_t val)
800 {
801         bus_space_write_4(mpt->pci_st, mpt->pci_sh, offset, val);
802 }
803
804 static __inline uint32_t
805 mpt_read(struct mpt_softc *mpt, int offset)
806 {
807         return (bus_space_read_4(mpt->pci_st, mpt->pci_sh, offset));
808 }
809
810 /*
811  * Some operations (e.g. diagnostic register writes while the ARM proccessor
812  * is disabled), must be performed using "PCI pio" operations.  On non-PCI
813  * busses, these operations likely map to normal register accesses.
814  */
815 static __inline void
816 mpt_pio_write(struct mpt_softc *mpt, size_t offset, uint32_t val)
817 {
818         KASSERT(mpt->pci_pio_reg != NULL, ("no PIO resource"));
819         bus_space_write_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset, val);
820 }
821
822 static __inline uint32_t
823 mpt_pio_read(struct mpt_softc *mpt, int offset)
824 {
825         KASSERT(mpt->pci_pio_reg != NULL, ("no PIO resource"));
826         return (bus_space_read_4(mpt->pci_pio_st, mpt->pci_pio_sh, offset));
827 }
828 /*********************** Reply Frame/Request Management ***********************/
829 /* Max MPT Reply we are willing to accept (must be power of 2) */
830 #define MPT_REPLY_SIZE          256
831
832 /*
833  * Must be less than 16384 in order for target mode to work
834  */
835 #define MPT_MAX_REQUESTS(mpt)   512
836 #define MPT_REQUEST_AREA        512
837 #define MPT_SENSE_SIZE          32      /* included in MPT_REQUEST_AREA */
838 #define MPT_REQ_MEM_SIZE(mpt)   (MPT_MAX_REQUESTS(mpt) * MPT_REQUEST_AREA)
839
840 #define MPT_CONTEXT_CB_SHIFT    (16)
841 #define MPT_CBI(handle)         (handle >> MPT_CONTEXT_CB_SHIFT)
842 #define MPT_CBI_TO_HID(cbi)     ((cbi) << MPT_CONTEXT_CB_SHIFT)
843 #define MPT_CONTEXT_TO_CBI(x)   \
844     (((x) >> MPT_CONTEXT_CB_SHIFT) & (MPT_NUM_REPLY_HANDLERS - 1))
845 #define MPT_CONTEXT_REQI_MASK   0xFFFF
846 #define MPT_CONTEXT_TO_REQI(x)  ((x) & MPT_CONTEXT_REQI_MASK)
847
848 /*
849  * Convert a 32bit physical address returned from IOC to an
850  * offset into our reply frame memory or the kvm address needed
851  * to access the data.  The returned address is only the low
852  * 32 bits, so mask our base physical address accordingly.
853  */
854 #define MPT_REPLY_BADDR(x)              \
855         (x << 1)
856 #define MPT_REPLY_OTOV(m, i)            \
857         ((void *)(&m->reply[i]))
858
859 #define MPT_DUMP_REPLY_FRAME(mpt, reply_frame)          \
860 do {                                                    \
861         if (mpt->verbose > MPT_PRT_DEBUG)               \
862                 mpt_dump_reply_frame(mpt, reply_frame); \
863 } while(0)
864
865 static __inline uint32_t mpt_pop_reply_queue(struct mpt_softc *mpt);
866 static __inline void mpt_free_reply(struct mpt_softc *mpt, uint32_t ptr);
867
868 /*
869  * Give the reply buffer back to the IOC after we have
870  * finished processing it.
871  */
872 static __inline void
873 mpt_free_reply(struct mpt_softc *mpt, uint32_t ptr)
874 {
875      mpt_write(mpt, MPT_OFFSET_REPLY_Q, ptr);
876 }
877
878 /* Get a reply from the IOC */
879 static __inline uint32_t
880 mpt_pop_reply_queue(struct mpt_softc *mpt)
881 {
882      return mpt_read(mpt, MPT_OFFSET_REPLY_Q);
883 }
884
885 void
886 mpt_complete_request_chain(struct mpt_softc *, struct req_queue *, u_int);
887
888 /************************** Scatter Gather Management **************************/
889 /* MPT_RQSL- size of request frame, in bytes */
890 #define MPT_RQSL(mpt)           (mpt->ioc_facts.RequestFrameSize << 2)
891
892 /* MPT_NSGL- how many SG entries can fit in a request frame size */
893 #define MPT_NSGL(mpt)           (MPT_RQSL(mpt) / sizeof (SGE_IO_UNION))
894
895 /* MPT_NRFM- how many request frames can fit in each request alloc we make */
896 #define MPT_NRFM(mpt)           (MPT_REQUEST_AREA / MPT_RQSL(mpt))
897
898 /*
899  * MPT_NSGL_FIRST- # of SG elements that can fit after
900  * an I/O request but still within the request frame.
901  * Do this safely based upon SGE_IO_UNION.
902  *
903  * Note that the first element is *within* the SCSI request.
904  */
905 #define MPT_NSGL_FIRST(mpt)     \
906     ((MPT_RQSL(mpt) - sizeof (MSG_SCSI_IO_REQUEST) + sizeof (SGE_IO_UNION)) / \
907     sizeof (SGE_IO_UNION))
908
909 /***************************** IOC Initialization *****************************/
910 int mpt_reset(struct mpt_softc *, int /*reinit*/);
911
912 /****************************** Debugging ************************************/
913 void mpt_dump_data(struct mpt_softc *, const char *, void *, int);
914 void mpt_dump_request(struct mpt_softc *, request_t *);
915
916 enum {
917         MPT_PRT_ALWAYS,
918         MPT_PRT_FATAL,
919         MPT_PRT_ERROR,
920         MPT_PRT_WARN,
921         MPT_PRT_INFO,
922         MPT_PRT_NEGOTIATION,
923         MPT_PRT_DEBUG,
924         MPT_PRT_DEBUG1,
925         MPT_PRT_DEBUG2,
926         MPT_PRT_DEBUG3,
927         MPT_PRT_TRACE,
928         MPT_PRT_NONE=100
929 };
930
931 #define mpt_lprt(mpt, level, ...)               \
932 do {                                            \
933         if (level <= (mpt)->verbose)            \
934                 mpt_prt(mpt, __VA_ARGS__);      \
935 } while (0)
936
937 #if 0
938 #define mpt_lprtc(mpt, level, ...)              \
939 do {                                            \
940         if (level <= (mpt)->verbose)            \
941                 mpt_prtc(mpt, __VA_ARGS__);     \
942 } while (0)
943 #endif
944 void mpt_prt(struct mpt_softc *, const char *, ...)
945         __printflike(2, 3);
946 void mpt_prtc(struct mpt_softc *, const char *, ...)
947         __printflike(2, 3);
948
949 /**************************** Target Mode Related ***************************/
950 static __inline int mpt_cdblen(uint8_t, int);
951 static __inline int
952 mpt_cdblen(uint8_t cdb0, int maxlen)
953 {
954         int group = cdb0 >> 5;
955         switch (group) {
956         case 0:
957                 return (6);
958         case 1:
959                 return (10);
960         case 4:
961         case 5:
962                 return (12);
963         default:
964                 return (16);
965         }
966 }
967 #ifdef  INVARIANTS
968 static __inline request_t * mpt_tag_2_req(struct mpt_softc *, uint32_t);
969 static __inline request_t *
970 mpt_tag_2_req(struct mpt_softc *mpt, uint32_t tag)
971 {
972         uint16_t rtg = (tag >> 18);
973         KASSERT(rtg < mpt->tgt_cmds_allocated, ("bad tag %d", tag));
974         KASSERT(mpt->tgt_cmd_ptrs, ("no cmd backpointer array"));
975         KASSERT(mpt->tgt_cmd_ptrs[rtg], ("no cmd backpointer"));
976         return (mpt->tgt_cmd_ptrs[rtg]);
977 }
978 #endif
979
980 static __inline int
981 mpt_req_on_free_list(struct mpt_softc *, request_t *);
982 static __inline int
983 mpt_req_on_pending_list(struct mpt_softc *, request_t *);
984
985 /*
986  * Is request on freelist?
987  */
988 static __inline int
989 mpt_req_on_free_list(struct mpt_softc *mpt, request_t *req)
990 {
991         request_t *lrq;
992
993         TAILQ_FOREACH(lrq, &mpt->request_free_list, links) {
994                 if (lrq == req) {
995                         return (1);
996                 }
997         }
998         return (0);
999 }
1000
1001 /*
1002  * Is request on pending list?
1003  */
1004 static __inline int
1005 mpt_req_on_pending_list(struct mpt_softc *mpt, request_t *req)
1006 {
1007         request_t *lrq;
1008
1009         TAILQ_FOREACH(lrq, &mpt->request_pending_list, links) {
1010                 if (lrq == req) {
1011                         return (1);
1012                 }
1013         }
1014         return (0);
1015 }
1016
1017 #ifdef  INVARIANTS
1018 static __inline void
1019 mpt_req_spcl(struct mpt_softc *, request_t *, const char *, int);
1020 static __inline void
1021 mpt_req_not_spcl(struct mpt_softc *, request_t *, const char *, int);
1022
1023 /*
1024  * Make sure that req *is* part of one of the special lists
1025  */
1026 static __inline void
1027 mpt_req_spcl(struct mpt_softc *mpt, request_t *req, const char *s, int line)
1028 {
1029         int i;
1030         for (i = 0; i < mpt->els_cmds_allocated; i++) {
1031                 if (req == mpt->els_cmd_ptrs[i]) {
1032                         return;
1033                 }
1034         }
1035         for (i = 0; i < mpt->tgt_cmds_allocated; i++) {
1036                 if (req == mpt->tgt_cmd_ptrs[i]) {
1037                         return;
1038                 }
1039         }
1040         panic("%s(%d): req %p:%u function %x not in els or tgt ptrs",
1041             s, line, req, req->serno,
1042             ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function);
1043 }
1044
1045 /*
1046  * Make sure that req is *not* part of one of the special lists.
1047  */
1048 static __inline void
1049 mpt_req_not_spcl(struct mpt_softc *mpt, request_t *req, const char *s, int line)
1050 {
1051         int i;
1052         for (i = 0; i < mpt->els_cmds_allocated; i++) {
1053                 KASSERT(req != mpt->els_cmd_ptrs[i],
1054                     ("%s(%d): req %p:%u func %x in els ptrs at ioindex %d",
1055                     s, line, req, req->serno,
1056                     ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function, i));
1057         }
1058         for (i = 0; i < mpt->tgt_cmds_allocated; i++) {
1059                 KASSERT(req != mpt->tgt_cmd_ptrs[i],
1060                     ("%s(%d): req %p:%u func %x in tgt ptrs at ioindex %d",
1061                     s, line, req, req->serno,
1062                     ((PTR_MSG_REQUEST_HEADER)req->req_vbuf)->Function, i));
1063         }
1064 }
1065 #endif
1066
1067 /*
1068  * Task Management Types, purely for internal consumption
1069  */
1070 typedef enum {
1071         MPT_ABORT_TASK_SET=1234,
1072         MPT_CLEAR_TASK_SET,
1073         MPT_TARGET_RESET,
1074         MPT_CLEAR_ACA,
1075         MPT_TERMINATE_TASK,
1076         MPT_NIL_TMT_VALUE=5678
1077 } mpt_task_mgmt_t;
1078
1079 /**************************** Unclassified Routines ***************************/
1080 void            mpt_send_cmd(struct mpt_softc *mpt, request_t *req);
1081 int             mpt_recv_handshake_reply(struct mpt_softc *mpt,
1082                                          size_t reply_len, void *reply);
1083 int             mpt_wait_req(struct mpt_softc *mpt, request_t *req,
1084                              mpt_req_state_t state, mpt_req_state_t mask,
1085                              int sleep_ok, int time_ms);
1086 void            mpt_enable_ints(struct mpt_softc *mpt);
1087 void            mpt_disable_ints(struct mpt_softc *mpt);
1088 int             mpt_attach(struct mpt_softc *mpt);
1089 int             mpt_shutdown(struct mpt_softc *mpt);
1090 int             mpt_detach(struct mpt_softc *mpt);
1091 int             mpt_send_handshake_cmd(struct mpt_softc *mpt,
1092                                        size_t len, void *cmd);
1093 request_t *     mpt_get_request(struct mpt_softc *mpt, int sleep_ok);
1094 void            mpt_free_request(struct mpt_softc *mpt, request_t *req);
1095 void            mpt_intr(void *arg);
1096 void            mpt_check_doorbell(struct mpt_softc *mpt);
1097 void            mpt_dump_reply_frame(struct mpt_softc *mpt,
1098                                      MSG_DEFAULT_REPLY *reply_frame);
1099
1100 int             mpt_issue_cfg_req(struct mpt_softc */*mpt*/, request_t */*req*/,
1101                                   cfgparms_t *params,
1102                                   bus_addr_t /*addr*/, bus_size_t/*len*/,
1103                                   int /*sleep_ok*/, int /*timeout_ms*/);
1104 int             mpt_read_extcfg_header(struct mpt_softc *mpt, int PageVersion,
1105                                        int PageNumber, uint32_t PageAddress,
1106                                        int ExtPageType,
1107                                        CONFIG_EXTENDED_PAGE_HEADER *rslt,
1108                                        int sleep_ok, int timeout_ms);
1109 int             mpt_read_extcfg_page(struct mpt_softc *mpt, int Action,
1110                                      uint32_t PageAddress,
1111                                      CONFIG_EXTENDED_PAGE_HEADER *hdr,
1112                                      void *buf, size_t len, int sleep_ok,
1113                                      int timeout_ms);
1114 int             mpt_read_cfg_header(struct mpt_softc *, int /*PageType*/,
1115                                     int /*PageNumber*/,
1116                                     uint32_t /*PageAddress*/,
1117                                     CONFIG_PAGE_HEADER *,
1118                                     int /*sleep_ok*/, int /*timeout_ms*/);
1119 int             mpt_read_cfg_page(struct mpt_softc *t, int /*Action*/,
1120                                   uint32_t /*PageAddress*/,
1121                                   CONFIG_PAGE_HEADER *, size_t /*len*/,
1122                                   int /*sleep_ok*/, int /*timeout_ms*/);
1123 int             mpt_write_cfg_page(struct mpt_softc *, int /*Action*/,
1124                                    uint32_t /*PageAddress*/,
1125                                    CONFIG_PAGE_HEADER *, size_t /*len*/,
1126                                    int /*sleep_ok*/, int /*timeout_ms*/);
1127 static __inline int
1128 mpt_read_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress,
1129                       CONFIG_PAGE_HEADER *hdr, size_t len,
1130                       int sleep_ok, int timeout_ms)
1131 {
1132         return (mpt_read_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_READ_CURRENT,
1133                                   PageAddress, hdr, len, sleep_ok, timeout_ms));
1134 }
1135
1136 static __inline int
1137 mpt_write_cur_cfg_page(struct mpt_softc *mpt, uint32_t PageAddress,
1138                        CONFIG_PAGE_HEADER *hdr, size_t len, int sleep_ok,
1139                        int timeout_ms)
1140 {
1141         return (mpt_write_cfg_page(mpt, MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT,
1142                                    PageAddress, hdr, len, sleep_ok,
1143                                    timeout_ms));
1144 }
1145 /* mpt_debug.c functions */
1146 void mpt_print_reply(void *vmsg);
1147 void mpt_print_db(uint32_t mb);
1148 void mpt_print_config_reply(void *vmsg);
1149 char *mpt_ioc_diag(uint32_t diag);
1150 void mpt_req_state(mpt_req_state_t state);
1151 void mpt_print_config_request(void *vmsg);
1152 void mpt_print_request(void *vmsg);
1153 void mpt_dump_sgl(SGE_IO_UNION *se, int offset);
1154 #endif /* _MPT_H_ */