2 * Generic routines for LSI Fusion adapters.
5 * Copyright (c) 2000, 2001 by Greg Ansley
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice immediately at the beginning of the file, without modification,
12 * this list of conditions, and the following disclaimer.
13 * 2. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Copyright (c) 2002, 2006 by Matthew Jacob
30 * All rights reserved.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions are
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
38 * substantially similar to the "NO WARRANTY" disclaimer below
39 * ("Disclaimer") and any redistribution must be conditioned upon including
40 * a substantially similar Disclaimer requirement for further binary
42 * 3. Neither the names of the above listed copyright holders nor the names
43 * of any contributors may be used to endorse or promote products derived
44 * from this software without specific prior written permission.
46 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
47 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
50 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
51 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
52 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
53 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
54 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
55 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
56 * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58 * Support from Chris Ellsworth in order to make SAS adapters work
59 * is gratefully acknowledged.
62 * Support from LSI-Logic has also gone a great deal toward making this a
63 * workable subsystem and is gratefully acknowledged.
66 * Copyright (c) 2004, Avid Technology, Inc. and its contributors.
67 * Copyright (c) 2005, WHEEL Sp. z o.o.
68 * Copyright (c) 2004, 2005 Justin T. Gibbs
69 * All rights reserved.
71 * Redistribution and use in source and binary forms, with or without
72 * modification, are permitted provided that the following conditions are
74 * 1. Redistributions of source code must retain the above copyright
75 * notice, this list of conditions and the following disclaimer.
76 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
77 * substantially similar to the "NO WARRANTY" disclaimer below
78 * ("Disclaimer") and any redistribution must be conditioned upon including
79 * a substantially similar Disclaimer requirement for further binary
81 * 3. Neither the names of the above listed copyright holders nor the names
82 * of any contributors may be used to endorse or promote products derived
83 * from this software without specific prior written permission.
85 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
86 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
87 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
88 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
89 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
90 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
91 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
92 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
93 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
94 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT
95 * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
98 #include <sys/cdefs.h>
99 __FBSDID("$FreeBSD$");
101 #include <dev/mpt/mpt.h>
102 #include <dev/mpt/mpt_cam.h> /* XXX For static handler registration */
103 #include <dev/mpt/mpt_raid.h> /* XXX For static handler registration */
105 #include <dev/mpt/mpilib/mpi.h>
106 #include <dev/mpt/mpilib/mpi_ioc.h>
107 #include <dev/mpt/mpilib/mpi_fc.h>
108 #include <dev/mpt/mpilib/mpi_targ.h>
110 #include <sys/sysctl.h>
112 #define MPT_MAX_TRYS 3
113 #define MPT_MAX_WAIT 300000
115 static int maxwait_ack = 0;
116 static int maxwait_int = 0;
117 static int maxwait_state = 0;
119 static TAILQ_HEAD(, mpt_softc) mpt_tailq = TAILQ_HEAD_INITIALIZER(mpt_tailq);
120 mpt_reply_handler_t *mpt_reply_handlers[MPT_NUM_REPLY_HANDLERS];
122 static mpt_reply_handler_t mpt_default_reply_handler;
123 static mpt_reply_handler_t mpt_config_reply_handler;
124 static mpt_reply_handler_t mpt_handshake_reply_handler;
125 static mpt_reply_handler_t mpt_event_reply_handler;
126 static void mpt_send_event_ack(struct mpt_softc *mpt, request_t *ack_req,
127 MSG_EVENT_NOTIFY_REPLY *msg, uint32_t context);
128 static int mpt_send_event_request(struct mpt_softc *mpt, int onoff);
129 static int mpt_soft_reset(struct mpt_softc *mpt);
130 static void mpt_hard_reset(struct mpt_softc *mpt);
131 static int mpt_configure_ioc(struct mpt_softc *mpt, int, int);
132 static int mpt_enable_ioc(struct mpt_softc *mpt, int);
134 /************************* Personality Module Support *************************/
136 * We include one extra entry that is guaranteed to be NULL
137 * to simplify our itterator.
139 static struct mpt_personality *mpt_personalities[MPT_MAX_PERSONALITIES + 1];
140 static __inline struct mpt_personality*
141 mpt_pers_find(struct mpt_softc *, u_int);
142 static __inline struct mpt_personality*
143 mpt_pers_find_reverse(struct mpt_softc *, u_int);
145 static __inline struct mpt_personality *
146 mpt_pers_find(struct mpt_softc *mpt, u_int start_at)
148 KASSERT(start_at <= MPT_MAX_PERSONALITIES,
149 ("mpt_pers_find: starting position out of range\n"));
151 while (start_at < MPT_MAX_PERSONALITIES
152 && (mpt->mpt_pers_mask & (0x1 << start_at)) == 0) {
155 return (mpt_personalities[start_at]);
159 * Used infrequently, so no need to optimize like a forward
160 * traversal where we use the MAX+1 is guaranteed to be NULL
163 static __inline struct mpt_personality *
164 mpt_pers_find_reverse(struct mpt_softc *mpt, u_int start_at)
166 while (start_at < MPT_MAX_PERSONALITIES
167 && (mpt->mpt_pers_mask & (0x1 << start_at)) == 0) {
170 if (start_at < MPT_MAX_PERSONALITIES)
171 return (mpt_personalities[start_at]);
175 #define MPT_PERS_FOREACH(mpt, pers) \
176 for (pers = mpt_pers_find(mpt, /*start_at*/0); \
178 pers = mpt_pers_find(mpt, /*start_at*/pers->id+1))
180 #define MPT_PERS_FOREACH_REVERSE(mpt, pers) \
181 for (pers = mpt_pers_find_reverse(mpt, MPT_MAX_PERSONALITIES-1);\
183 pers = mpt_pers_find_reverse(mpt, /*start_at*/pers->id-1))
185 static mpt_load_handler_t mpt_stdload;
186 static mpt_probe_handler_t mpt_stdprobe;
187 static mpt_attach_handler_t mpt_stdattach;
188 static mpt_enable_handler_t mpt_stdenable;
189 static mpt_ready_handler_t mpt_stdready;
190 static mpt_event_handler_t mpt_stdevent;
191 static mpt_reset_handler_t mpt_stdreset;
192 static mpt_shutdown_handler_t mpt_stdshutdown;
193 static mpt_detach_handler_t mpt_stddetach;
194 static mpt_unload_handler_t mpt_stdunload;
195 static struct mpt_personality mpt_default_personality =
198 .probe = mpt_stdprobe,
199 .attach = mpt_stdattach,
200 .enable = mpt_stdenable,
201 .ready = mpt_stdready,
202 .event = mpt_stdevent,
203 .reset = mpt_stdreset,
204 .shutdown = mpt_stdshutdown,
205 .detach = mpt_stddetach,
206 .unload = mpt_stdunload
209 static mpt_load_handler_t mpt_core_load;
210 static mpt_attach_handler_t mpt_core_attach;
211 static mpt_enable_handler_t mpt_core_enable;
212 static mpt_reset_handler_t mpt_core_ioc_reset;
213 static mpt_event_handler_t mpt_core_event;
214 static mpt_shutdown_handler_t mpt_core_shutdown;
215 static mpt_shutdown_handler_t mpt_core_detach;
216 static mpt_unload_handler_t mpt_core_unload;
217 static struct mpt_personality mpt_core_personality =
220 .load = mpt_core_load,
221 // .attach = mpt_core_attach,
222 // .enable = mpt_core_enable,
223 .event = mpt_core_event,
224 .reset = mpt_core_ioc_reset,
225 .shutdown = mpt_core_shutdown,
226 .detach = mpt_core_detach,
227 .unload = mpt_core_unload,
231 * Manual declaration so that DECLARE_MPT_PERSONALITY doesn't need
232 * ordering information. We want the core to always register FIRST.
233 * other modules are set to SI_ORDER_SECOND.
235 static moduledata_t mpt_core_mod = {
236 "mpt_core", mpt_modevent, &mpt_core_personality
238 DECLARE_MODULE(mpt_core, mpt_core_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
239 MODULE_VERSION(mpt_core, 1);
241 #define MPT_PERS_ATTACHED(pers, mpt) ((mpt)->mpt_pers_mask & (0x1 << pers->id))
244 mpt_modevent(module_t mod, int type, void *data)
246 struct mpt_personality *pers;
249 pers = (struct mpt_personality *)data;
255 mpt_load_handler_t **def_handler;
256 mpt_load_handler_t **pers_handler;
259 for (i = 0; i < MPT_MAX_PERSONALITIES; i++) {
260 if (mpt_personalities[i] == NULL)
263 if (i >= MPT_MAX_PERSONALITIES) {
268 mpt_personalities[i] = pers;
270 /* Install standard/noop handlers for any NULL entries. */
271 def_handler = MPT_PERS_FIRST_HANDLER(&mpt_default_personality);
272 pers_handler = MPT_PERS_FIRST_HANDLER(pers);
273 while (pers_handler <= MPT_PERS_LAST_HANDLER(pers)) {
274 if (*pers_handler == NULL)
275 *pers_handler = *def_handler;
280 error = (pers->load(pers));
282 mpt_personalities[i] = NULL;
287 #if __FreeBSD_version >= 500000
292 error = pers->unload(pers);
293 mpt_personalities[pers->id] = NULL;
303 mpt_stdload(struct mpt_personality *pers)
305 /* Load is always successfull. */
310 mpt_stdprobe(struct mpt_softc *mpt)
312 /* Probe is always successfull. */
317 mpt_stdattach(struct mpt_softc *mpt)
319 /* Attach is always successfull. */
324 mpt_stdenable(struct mpt_softc *mpt)
326 /* Enable is always successfull. */
331 mpt_stdready(struct mpt_softc *mpt)
337 mpt_stdevent(struct mpt_softc *mpt, request_t *req, MSG_EVENT_NOTIFY_REPLY *msg)
339 mpt_lprt(mpt, MPT_PRT_DEBUG, "mpt_stdevent: 0x%x\n", msg->Event & 0xFF);
340 /* Event was not for us. */
345 mpt_stdreset(struct mpt_softc *mpt, int type)
350 mpt_stdshutdown(struct mpt_softc *mpt)
355 mpt_stddetach(struct mpt_softc *mpt)
360 mpt_stdunload(struct mpt_personality *pers)
362 /* Unload is always successfull. */
367 * Post driver attachment, we may want to perform some global actions.
368 * Here is the hook to do so.
372 mpt_postattach(void *unused)
374 struct mpt_softc *mpt;
375 struct mpt_personality *pers;
377 TAILQ_FOREACH(mpt, &mpt_tailq, links) {
378 MPT_PERS_FOREACH(mpt, pers)
382 SYSINIT(mptdev, SI_SUB_CONFIGURE, SI_ORDER_MIDDLE, mpt_postattach, NULL);
385 /******************************* Bus DMA Support ******************************/
387 mpt_map_rquest(void *arg, bus_dma_segment_t *segs, int nseg, int error)
389 struct mpt_map_info *map_info;
391 map_info = (struct mpt_map_info *)arg;
392 map_info->error = error;
393 map_info->phys = segs->ds_addr;
396 /**************************** Reply/Event Handling ****************************/
398 mpt_register_handler(struct mpt_softc *mpt, mpt_handler_type type,
399 mpt_handler_t handler, uint32_t *phandler_id)
403 case MPT_HANDLER_REPLY:
408 if (phandler_id == NULL)
411 free_cbi = MPT_HANDLER_ID_NONE;
412 for (cbi = 0; cbi < MPT_NUM_REPLY_HANDLERS; cbi++) {
414 * If the same handler is registered multiple
415 * times, don't error out. Just return the
416 * index of the original registration.
418 if (mpt_reply_handlers[cbi] == handler.reply_handler) {
419 *phandler_id = MPT_CBI_TO_HID(cbi);
424 * Fill from the front in the hope that
425 * all registered handlers consume only a
428 * We don't break on the first empty slot so
429 * that the full table is checked to see if
430 * this handler was previously registered.
432 if (free_cbi == MPT_HANDLER_ID_NONE &&
433 (mpt_reply_handlers[cbi]
434 == mpt_default_reply_handler))
437 if (free_cbi == MPT_HANDLER_ID_NONE) {
440 mpt_reply_handlers[free_cbi] = handler.reply_handler;
441 *phandler_id = MPT_CBI_TO_HID(free_cbi);
445 mpt_prt(mpt, "mpt_register_handler unknown type %d\n", type);
452 mpt_deregister_handler(struct mpt_softc *mpt, mpt_handler_type type,
453 mpt_handler_t handler, uint32_t handler_id)
457 case MPT_HANDLER_REPLY:
461 cbi = MPT_CBI(handler_id);
462 if (cbi >= MPT_NUM_REPLY_HANDLERS
463 || mpt_reply_handlers[cbi] != handler.reply_handler)
465 mpt_reply_handlers[cbi] = mpt_default_reply_handler;
469 mpt_prt(mpt, "mpt_deregister_handler unknown type %d\n", type);
476 mpt_default_reply_handler(struct mpt_softc *mpt, request_t *req,
477 uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame)
480 "Default Handler Called: req=%p:%u reply_descriptor=%x frame=%p\n",
481 req, req->serno, reply_desc, reply_frame);
483 if (reply_frame != NULL)
484 mpt_dump_reply_frame(mpt, reply_frame);
486 mpt_prt(mpt, "Reply Frame Ignored\n");
488 return (/*free_reply*/TRUE);
492 mpt_config_reply_handler(struct mpt_softc *mpt, request_t *req,
493 uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame)
497 if (reply_frame != NULL) {
499 MSG_CONFIG_REPLY *reply;
501 cfgp = (MSG_CONFIG *)req->req_vbuf;
502 reply = (MSG_CONFIG_REPLY *)reply_frame;
503 req->IOCStatus = le16toh(reply_frame->IOCStatus);
504 bcopy(&reply->Header, &cfgp->Header,
505 sizeof(cfgp->Header));
506 cfgp->ExtPageLength = reply->ExtPageLength;
507 cfgp->ExtPageType = reply->ExtPageType;
509 req->state &= ~REQ_STATE_QUEUED;
510 req->state |= REQ_STATE_DONE;
511 TAILQ_REMOVE(&mpt->request_pending_list, req, links);
512 if ((req->state & REQ_STATE_NEED_WAKEUP) != 0) {
514 } else if ((req->state & REQ_STATE_TIMEDOUT) != 0) {
516 * Whew- we can free this request (late completion)
518 mpt_free_request(mpt, req);
526 mpt_handshake_reply_handler(struct mpt_softc *mpt, request_t *req,
527 uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame)
529 /* Nothing to be done. */
534 mpt_event_reply_handler(struct mpt_softc *mpt, request_t *req,
535 uint32_t reply_desc, MSG_DEFAULT_REPLY *reply_frame)
539 KASSERT(reply_frame != NULL, ("null reply in mpt_event_reply_handler"));
540 KASSERT(req != NULL, ("null request in mpt_event_reply_handler"));
543 switch (reply_frame->Function) {
544 case MPI_FUNCTION_EVENT_NOTIFICATION:
546 MSG_EVENT_NOTIFY_REPLY *msg;
547 struct mpt_personality *pers;
551 msg = (MSG_EVENT_NOTIFY_REPLY *)reply_frame;
552 msg->EventDataLength = le16toh(msg->EventDataLength);
553 msg->IOCStatus = le16toh(msg->IOCStatus);
554 msg->IOCLogInfo = le32toh(msg->IOCLogInfo);
555 msg->Event = le32toh(msg->Event);
556 MPT_PERS_FOREACH(mpt, pers)
557 handled += pers->event(mpt, req, msg);
559 if (handled == 0 && mpt->mpt_pers_mask == 0) {
560 mpt_lprt(mpt, MPT_PRT_INFO,
561 "No Handlers For Any Event Notify Frames. "
562 "Event %#x (ACK %sequired).\n",
563 msg->Event, msg->AckRequired? "r" : "not r");
564 } else if (handled == 0) {
566 msg->AckRequired? MPT_PRT_WARN : MPT_PRT_INFO,
567 "Unhandled Event Notify Frame. Event %#x "
568 "(ACK %sequired).\n",
569 msg->Event, msg->AckRequired? "r" : "not r");
572 if (msg->AckRequired) {
576 context = req->index | MPT_REPLY_HANDLER_EVENTS;
577 ack_req = mpt_get_request(mpt, FALSE);
578 if (ack_req == NULL) {
579 struct mpt_evtf_record *evtf;
581 evtf = (struct mpt_evtf_record *)reply_frame;
582 evtf->context = context;
583 LIST_INSERT_HEAD(&mpt->ack_frames, evtf, links);
587 mpt_send_event_ack(mpt, ack_req, msg, context);
589 * Don't check for CONTINUATION_REPLY here
595 case MPI_FUNCTION_PORT_ENABLE:
596 mpt_lprt(mpt, MPT_PRT_DEBUG , "enable port reply\n");
598 case MPI_FUNCTION_EVENT_ACK:
601 mpt_prt(mpt, "unknown event function: %x\n",
602 reply_frame->Function);
607 * I'm not sure that this continuation stuff works as it should.
609 * I've had FC async events occur that free the frame up because
610 * the continuation bit isn't set, and then additional async events
611 * then occur using the same context. As you might imagine, this
612 * leads to Very Bad Thing.
614 * Let's just be safe for now and not free them up until we figure
615 * out what's actually happening here.
618 if ((reply_frame->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY) == 0) {
619 TAILQ_REMOVE(&mpt->request_pending_list, req, links);
620 mpt_free_request(mpt, req);
621 mpt_prt(mpt, "event_reply %x for req %p:%u NOT a continuation",
622 reply_frame->Function, req, req->serno);
623 if (reply_frame->Function == MPI_FUNCTION_EVENT_NOTIFICATION) {
624 MSG_EVENT_NOTIFY_REPLY *msg =
625 (MSG_EVENT_NOTIFY_REPLY *)reply_frame;
626 mpt_prtc(mpt, " Event=0x%x AckReq=%d",
627 msg->Event, msg->AckRequired);
630 mpt_prt(mpt, "event_reply %x for %p:%u IS a continuation",
631 reply_frame->Function, req, req->serno);
632 if (reply_frame->Function == MPI_FUNCTION_EVENT_NOTIFICATION) {
633 MSG_EVENT_NOTIFY_REPLY *msg =
634 (MSG_EVENT_NOTIFY_REPLY *)reply_frame;
635 mpt_prtc(mpt, " Event=0x%x AckReq=%d",
636 msg->Event, msg->AckRequired);
645 * Process an asynchronous event from the IOC.
648 mpt_core_event(struct mpt_softc *mpt, request_t *req,
649 MSG_EVENT_NOTIFY_REPLY *msg)
651 mpt_lprt(mpt, MPT_PRT_DEBUG, "mpt_core_event: 0x%x\n",
653 switch(msg->Event & 0xFF) {
656 case MPI_EVENT_LOG_DATA:
660 /* Some error occured that LSI wants logged */
661 mpt_prt(mpt, "EvtLogData: IOCLogInfo: 0x%08x\n",
663 mpt_prt(mpt, "\tEvtLogData: Event Data:");
664 for (i = 0; i < msg->EventDataLength; i++)
665 mpt_prtc(mpt, " %08x", msg->Data[i]);
669 case MPI_EVENT_EVENT_CHANGE:
671 * This is just an acknowledgement
672 * of our mpt_send_event_request.
675 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
685 mpt_send_event_ack(struct mpt_softc *mpt, request_t *ack_req,
686 MSG_EVENT_NOTIFY_REPLY *msg, uint32_t context)
690 ackp = (MSG_EVENT_ACK *)ack_req->req_vbuf;
691 memset(ackp, 0, sizeof (*ackp));
692 ackp->Function = MPI_FUNCTION_EVENT_ACK;
693 ackp->Event = htole32(msg->Event);
694 ackp->EventContext = htole32(msg->EventContext);
695 ackp->MsgContext = htole32(context);
696 mpt_check_doorbell(mpt);
697 mpt_send_cmd(mpt, ack_req);
700 /***************************** Interrupt Handling *****************************/
704 struct mpt_softc *mpt;
708 mpt = (struct mpt_softc *)arg;
709 mpt_lprt(mpt, MPT_PRT_DEBUG2, "enter mpt_intr\n");
710 MPT_LOCK_ASSERT(mpt);
712 while ((reply_desc = mpt_pop_reply_queue(mpt)) != MPT_REPLY_EMPTY) {
714 MSG_DEFAULT_REPLY *reply_frame;
715 uint32_t reply_baddr;
724 if ((reply_desc & MPI_ADDRESS_REPLY_A_BIT) != 0) {
727 * Insure that the reply frame is coherent.
729 reply_baddr = MPT_REPLY_BADDR(reply_desc);
730 offset = reply_baddr - (mpt->reply_phys & 0xFFFFFFFF);
731 bus_dmamap_sync_range(mpt->reply_dmat,
732 mpt->reply_dmap, offset, MPT_REPLY_SIZE,
733 BUS_DMASYNC_POSTREAD);
734 reply_frame = MPT_REPLY_OTOV(mpt, offset);
735 ctxt_idx = le32toh(reply_frame->MsgContext);
739 type = MPI_GET_CONTEXT_REPLY_TYPE(reply_desc);
740 ctxt_idx = reply_desc;
741 mpt_lprt(mpt, MPT_PRT_DEBUG1, "Context Reply: 0x%08x\n",
745 case MPI_CONTEXT_REPLY_TYPE_SCSI_INIT:
746 ctxt_idx &= MPI_CONTEXT_REPLY_CONTEXT_MASK;
748 case MPI_CONTEXT_REPLY_TYPE_SCSI_TARGET:
749 ctxt_idx = GET_IO_INDEX(reply_desc);
750 if (mpt->tgt_cmd_ptrs == NULL) {
752 "mpt_intr: no target cmd ptrs\n");
753 reply_desc = MPT_REPLY_EMPTY;
756 if (ctxt_idx >= mpt->tgt_cmds_allocated) {
758 "mpt_intr: bad tgt cmd ctxt %u\n",
760 reply_desc = MPT_REPLY_EMPTY;
764 req = mpt->tgt_cmd_ptrs[ctxt_idx];
766 mpt_prt(mpt, "no request backpointer "
767 "at index %u", ctxt_idx);
768 reply_desc = MPT_REPLY_EMPTY;
773 * Reformulate ctxt_idx to be just as if
774 * it were another type of context reply
775 * so the code below will find the request
776 * via indexing into the pool.
779 req->index | mpt->scsi_tgt_handler_id;
782 case MPI_CONTEXT_REPLY_TYPE_LAN:
783 mpt_prt(mpt, "LAN CONTEXT REPLY: 0x%08x\n",
785 reply_desc = MPT_REPLY_EMPTY;
788 mpt_prt(mpt, "Context Reply 0x%08x?\n", type);
789 reply_desc = MPT_REPLY_EMPTY;
792 if (reply_desc == MPT_REPLY_EMPTY) {
793 if (ntrips++ > 1000) {
800 cb_index = MPT_CONTEXT_TO_CBI(ctxt_idx);
801 req_index = MPT_CONTEXT_TO_REQI(ctxt_idx);
802 if (req_index < MPT_MAX_REQUESTS(mpt)) {
803 req = &mpt->request_pool[req_index];
805 mpt_prt(mpt, "WARN: mpt_intr index == %d (reply_desc =="
806 " 0x%x)\n", req_index, reply_desc);
809 free_rf = mpt_reply_handlers[cb_index](mpt, req,
810 reply_desc, reply_frame);
812 if (reply_frame != NULL && free_rf) {
813 mpt_free_reply(mpt, reply_baddr);
817 * If we got ourselves disabled, don't get stuck in a loop
820 mpt_disable_ints(mpt);
823 if (ntrips++ > 1000) {
827 mpt_lprt(mpt, MPT_PRT_DEBUG2, "exit mpt_intr\n");
830 /******************************* Error Recovery *******************************/
832 mpt_complete_request_chain(struct mpt_softc *mpt, struct req_queue *chain,
835 MSG_DEFAULT_REPLY ioc_status_frame;
838 memset(&ioc_status_frame, 0, sizeof(ioc_status_frame));
839 ioc_status_frame.MsgLength = roundup2(sizeof(ioc_status_frame), 4);
840 ioc_status_frame.IOCStatus = iocstatus;
841 while((req = TAILQ_FIRST(chain)) != NULL) {
842 MSG_REQUEST_HEADER *msg_hdr;
845 TAILQ_REMOVE(chain, req, links);
846 msg_hdr = (MSG_REQUEST_HEADER *)req->req_vbuf;
847 ioc_status_frame.Function = msg_hdr->Function;
848 ioc_status_frame.MsgContext = msg_hdr->MsgContext;
849 cb_index = MPT_CONTEXT_TO_CBI(le32toh(msg_hdr->MsgContext));
850 mpt_reply_handlers[cb_index](mpt, req, msg_hdr->MsgContext,
855 /********************************* Diagnostics ********************************/
857 * Perform a diagnostic dump of a reply frame.
860 mpt_dump_reply_frame(struct mpt_softc *mpt, MSG_DEFAULT_REPLY *reply_frame)
862 mpt_prt(mpt, "Address Reply:\n");
863 mpt_print_reply(reply_frame);
866 /******************************* Doorbell Access ******************************/
867 static __inline uint32_t mpt_rd_db(struct mpt_softc *mpt);
868 static __inline uint32_t mpt_rd_intr(struct mpt_softc *mpt);
870 static __inline uint32_t
871 mpt_rd_db(struct mpt_softc *mpt)
873 return mpt_read(mpt, MPT_OFFSET_DOORBELL);
876 static __inline uint32_t
877 mpt_rd_intr(struct mpt_softc *mpt)
879 return mpt_read(mpt, MPT_OFFSET_INTR_STATUS);
882 /* Busy wait for a door bell to be read by IOC */
884 mpt_wait_db_ack(struct mpt_softc *mpt)
887 for (i=0; i < MPT_MAX_WAIT; i++) {
888 if (!MPT_DB_IS_BUSY(mpt_rd_intr(mpt))) {
889 maxwait_ack = i > maxwait_ack ? i : maxwait_ack;
897 /* Busy wait for a door bell interrupt */
899 mpt_wait_db_int(struct mpt_softc *mpt)
902 for (i = 0; i < MPT_MAX_WAIT; i++) {
903 if (MPT_DB_INTR(mpt_rd_intr(mpt))) {
904 maxwait_int = i > maxwait_int ? i : maxwait_int;
912 /* Wait for IOC to transition to a give state */
914 mpt_check_doorbell(struct mpt_softc *mpt)
916 uint32_t db = mpt_rd_db(mpt);
917 if (MPT_STATE(db) != MPT_DB_STATE_RUNNING) {
918 mpt_prt(mpt, "Device not running\n");
923 /* Wait for IOC to transition to a give state */
925 mpt_wait_state(struct mpt_softc *mpt, enum DB_STATE_BITS state)
929 for (i = 0; i < MPT_MAX_WAIT; i++) {
930 uint32_t db = mpt_rd_db(mpt);
931 if (MPT_STATE(db) == state) {
932 maxwait_state = i > maxwait_state ? i : maxwait_state;
941 /************************* Intialization/Configuration ************************/
942 static int mpt_download_fw(struct mpt_softc *mpt);
944 /* Issue the reset COMMAND to the IOC */
946 mpt_soft_reset(struct mpt_softc *mpt)
948 mpt_lprt(mpt, MPT_PRT_DEBUG, "soft reset\n");
950 /* Have to use hard reset if we are not in Running state */
951 if (MPT_STATE(mpt_rd_db(mpt)) != MPT_DB_STATE_RUNNING) {
952 mpt_prt(mpt, "soft reset failed: device not running\n");
956 /* If door bell is in use we don't have a chance of getting
957 * a word in since the IOC probably crashed in message
958 * processing. So don't waste our time.
960 if (MPT_DB_IS_IN_USE(mpt_rd_db(mpt))) {
961 mpt_prt(mpt, "soft reset failed: doorbell wedged\n");
965 /* Send the reset request to the IOC */
966 mpt_write(mpt, MPT_OFFSET_DOORBELL,
967 MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET << MPI_DOORBELL_FUNCTION_SHIFT);
968 if (mpt_wait_db_ack(mpt) != MPT_OK) {
969 mpt_prt(mpt, "soft reset failed: ack timeout\n");
973 /* Wait for the IOC to reload and come out of reset state */
974 if (mpt_wait_state(mpt, MPT_DB_STATE_READY) != MPT_OK) {
975 mpt_prt(mpt, "soft reset failed: device did not restart\n");
983 mpt_enable_diag_mode(struct mpt_softc *mpt)
990 if ((mpt_read(mpt, MPT_OFFSET_DIAGNOSTIC) & MPI_DIAG_DRWE) != 0)
993 /* Enable diagnostic registers */
994 mpt_write(mpt, MPT_OFFSET_SEQUENCE, 0xFF);
995 mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_1ST_KEY_VALUE);
996 mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_2ND_KEY_VALUE);
997 mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_3RD_KEY_VALUE);
998 mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_4TH_KEY_VALUE);
999 mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_5TH_KEY_VALUE);
1009 mpt_disable_diag_mode(struct mpt_softc *mpt)
1011 mpt_write(mpt, MPT_OFFSET_SEQUENCE, 0xFFFFFFFF);
1014 /* This is a magic diagnostic reset that resets all the ARM
1015 * processors in the chip.
1018 mpt_hard_reset(struct mpt_softc *mpt)
1024 mpt_lprt(mpt, MPT_PRT_DEBUG, "hard reset\n");
1026 error = mpt_enable_diag_mode(mpt);
1028 mpt_prt(mpt, "WARNING - Could not enter diagnostic mode !\n");
1029 mpt_prt(mpt, "Trying to reset anyway.\n");
1032 diagreg = mpt_read(mpt, MPT_OFFSET_DIAGNOSTIC);
1035 * This appears to be a workaround required for some
1036 * firmware or hardware revs.
1038 mpt_write(mpt, MPT_OFFSET_DIAGNOSTIC, diagreg | MPI_DIAG_DISABLE_ARM);
1041 /* Diag. port is now active so we can now hit the reset bit */
1042 mpt_write(mpt, MPT_OFFSET_DIAGNOSTIC, diagreg | MPI_DIAG_RESET_ADAPTER);
1045 * Ensure that the reset has finished. We delay 1ms
1046 * prior to reading the register to make sure the chip
1047 * has sufficiently completed its reset to handle register
1053 diagreg = mpt_read(mpt, MPT_OFFSET_DIAGNOSTIC);
1054 } while (--wait && (diagreg & MPI_DIAG_RESET_ADAPTER) == 0);
1057 mpt_prt(mpt, "WARNING - Failed hard reset! "
1058 "Trying to initialize anyway.\n");
1062 * If we have firmware to download, it must be loaded before
1063 * the controller will become operational. Do so now.
1065 if (mpt->fw_image != NULL) {
1067 error = mpt_download_fw(mpt);
1070 mpt_prt(mpt, "WARNING - Firmware Download Failed!\n");
1071 mpt_prt(mpt, "Trying to initialize anyway.\n");
1076 * Reseting the controller should have disabled write
1077 * access to the diagnostic registers, but disable
1078 * manually to be sure.
1080 mpt_disable_diag_mode(mpt);
1084 mpt_core_ioc_reset(struct mpt_softc *mpt, int type)
1087 * Complete all pending requests with a status
1088 * appropriate for an IOC reset.
1090 mpt_complete_request_chain(mpt, &mpt->request_pending_list,
1091 MPI_IOCSTATUS_INVALID_STATE);
1096 * Reset the IOC when needed. Try software command first then if needed
1097 * poke at the magic diagnostic reset. Note that a hard reset resets
1098 * *both* IOCs on dual function chips (FC929 && LSI1030) as well as
1099 * fouls up the PCI configuration registers.
1102 mpt_reset(struct mpt_softc *mpt, int reinit)
1104 struct mpt_personality *pers;
1109 * Try a soft reset. If that fails, get out the big hammer.
1112 if ((ret = mpt_soft_reset(mpt)) != MPT_OK) {
1114 for (cnt = 0; cnt < 5; cnt++) {
1115 /* Failed; do a hard reset */
1116 mpt_hard_reset(mpt);
1119 * Wait for the IOC to reload
1120 * and come out of reset state
1122 ret = mpt_wait_state(mpt, MPT_DB_STATE_READY);
1123 if (ret == MPT_OK) {
1127 * Okay- try to check again...
1129 ret = mpt_wait_state(mpt, MPT_DB_STATE_READY);
1130 if (ret == MPT_OK) {
1133 mpt_prt(mpt, "mpt_reset: failed hard reset (%d:%d)\n",
1138 if (retry_cnt == 0) {
1140 * Invoke reset handlers. We bump the reset count so
1141 * that mpt_wait_req() understands that regardless of
1142 * the specified wait condition, it should stop its wait.
1145 MPT_PERS_FOREACH(mpt, pers)
1146 pers->reset(mpt, ret);
1150 ret = mpt_enable_ioc(mpt, 1);
1151 if (ret == MPT_OK) {
1152 mpt_enable_ints(mpt);
1155 if (ret != MPT_OK && retry_cnt++ < 2) {
1161 /* Return a command buffer to the free queue */
1163 mpt_free_request(struct mpt_softc *mpt, request_t *req)
1166 struct mpt_evtf_record *record;
1167 uint32_t reply_baddr;
1169 if (req == NULL || req != &mpt->request_pool[req->index]) {
1170 panic("mpt_free_request bad req ptr\n");
1173 if ((nxt = req->chain) != NULL) {
1175 mpt_free_request(mpt, nxt); /* NB: recursion */
1177 KASSERT(req->state != REQ_STATE_FREE, ("freeing free request"));
1178 KASSERT(!(req->state & REQ_STATE_LOCKED), ("freeing locked request"));
1179 MPT_LOCK_ASSERT(mpt);
1180 KASSERT(mpt_req_on_free_list(mpt, req) == 0,
1181 ("mpt_free_request: req %p:%u func %x already on freelist",
1182 req, req->serno, ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function));
1183 KASSERT(mpt_req_on_pending_list(mpt, req) == 0,
1184 ("mpt_free_request: req %p:%u func %x on pending list",
1185 req, req->serno, ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function));
1187 mpt_req_not_spcl(mpt, req, "mpt_free_request", __LINE__);
1191 if (LIST_EMPTY(&mpt->ack_frames)) {
1193 * Insert free ones at the tail
1196 req->state = REQ_STATE_FREE;
1198 memset(req->req_vbuf, 0xff, sizeof (MSG_REQUEST_HEADER));
1200 TAILQ_INSERT_TAIL(&mpt->request_free_list, req, links);
1201 if (mpt->getreqwaiter != 0) {
1202 mpt->getreqwaiter = 0;
1203 wakeup(&mpt->request_free_list);
1209 * Process an ack frame deferred due to resource shortage.
1211 record = LIST_FIRST(&mpt->ack_frames);
1212 LIST_REMOVE(record, links);
1213 req->state = REQ_STATE_ALLOCATED;
1214 mpt_assign_serno(mpt, req);
1215 mpt_send_event_ack(mpt, req, &record->reply, record->context);
1216 reply_baddr = (uint32_t)((uint8_t *)record - mpt->reply)
1217 + (mpt->reply_phys & 0xFFFFFFFF);
1218 mpt_free_reply(mpt, reply_baddr);
1221 /* Get a command buffer from the free queue */
1223 mpt_get_request(struct mpt_softc *mpt, int sleep_ok)
1228 MPT_LOCK_ASSERT(mpt);
1229 req = TAILQ_FIRST(&mpt->request_free_list);
1231 KASSERT(req == &mpt->request_pool[req->index],
1232 ("mpt_get_request: corrupted request free list\n"));
1233 KASSERT(req->state == REQ_STATE_FREE,
1234 ("req %p:%u not free on free list %x index %d function %x",
1235 req, req->serno, req->state, req->index,
1236 ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function));
1237 TAILQ_REMOVE(&mpt->request_free_list, req, links);
1238 req->state = REQ_STATE_ALLOCATED;
1240 mpt_assign_serno(mpt, req);
1241 } else if (sleep_ok != 0) {
1242 mpt->getreqwaiter = 1;
1243 mpt_sleep(mpt, &mpt->request_free_list, PUSER, "mptgreq", 0);
1249 /* Pass the command to the IOC */
1251 mpt_send_cmd(struct mpt_softc *mpt, request_t *req)
1253 if (mpt->verbose > MPT_PRT_DEBUG2) {
1254 mpt_dump_request(mpt, req);
1256 bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap,
1257 BUS_DMASYNC_PREWRITE);
1258 req->state |= REQ_STATE_QUEUED;
1259 KASSERT(mpt_req_on_free_list(mpt, req) == 0,
1260 ("req %p:%u func %x on freelist list in mpt_send_cmd",
1261 req, req->serno, ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function));
1262 KASSERT(mpt_req_on_pending_list(mpt, req) == 0,
1263 ("req %p:%u func %x already on pending list in mpt_send_cmd",
1264 req, req->serno, ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function));
1265 TAILQ_INSERT_HEAD(&mpt->request_pending_list, req, links);
1266 mpt_write(mpt, MPT_OFFSET_REQUEST_Q, (uint32_t) req->req_pbuf);
1270 * Wait for a request to complete.
1273 * mpt softc of controller executing request
1274 * req request to wait for
1275 * sleep_ok nonzero implies may sleep in this context
1276 * time_ms timeout in ms. 0 implies no timeout.
1279 * 0 Request completed
1280 * non-0 Timeout fired before request completion.
1283 mpt_wait_req(struct mpt_softc *mpt, request_t *req,
1284 mpt_req_state_t state, mpt_req_state_t mask,
1285 int sleep_ok, int time_ms)
1292 * timeout is in ms. 0 indicates infinite wait.
1293 * Convert to ticks or 500us units depending on
1296 if (sleep_ok != 0) {
1297 timeout = (time_ms * hz) / 1000;
1299 timeout = time_ms * 2;
1301 req->state |= REQ_STATE_NEED_WAKEUP;
1302 mask &= ~REQ_STATE_NEED_WAKEUP;
1303 saved_cnt = mpt->reset_cnt;
1304 while ((req->state & mask) != state && mpt->reset_cnt == saved_cnt) {
1305 if (sleep_ok != 0) {
1306 error = mpt_sleep(mpt, req, PUSER, "mptreq", timeout);
1307 if (error == EWOULDBLOCK) {
1312 if (time_ms != 0 && --timeout == 0) {
1319 req->state &= ~REQ_STATE_NEED_WAKEUP;
1320 if (mpt->reset_cnt != saved_cnt) {
1323 if (time_ms && timeout <= 0) {
1324 MSG_REQUEST_HEADER *msg_hdr = req->req_vbuf;
1325 req->state |= REQ_STATE_TIMEDOUT;
1326 mpt_prt(mpt, "mpt_wait_req(%x) timed out\n", msg_hdr->Function);
1333 * Send a command to the IOC via the handshake register.
1335 * Only done at initialization time and for certain unusual
1336 * commands such as device/bus reset as specified by LSI.
1339 mpt_send_handshake_cmd(struct mpt_softc *mpt, size_t len, void *cmd)
1342 uint32_t data, *data32;
1344 /* Check condition of the IOC */
1345 data = mpt_rd_db(mpt);
1346 if ((MPT_STATE(data) != MPT_DB_STATE_READY
1347 && MPT_STATE(data) != MPT_DB_STATE_RUNNING
1348 && MPT_STATE(data) != MPT_DB_STATE_FAULT)
1349 || MPT_DB_IS_IN_USE(data)) {
1350 mpt_prt(mpt, "handshake aborted - invalid doorbell state\n");
1355 /* We move things in 32 bit chunks */
1356 len = (len + 3) >> 2;
1359 /* Clear any left over pending doorbell interrupts */
1360 if (MPT_DB_INTR(mpt_rd_intr(mpt)))
1361 mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0);
1364 * Tell the handshake reg. we are going to send a command
1365 * and how long it is going to be.
1367 data = (MPI_FUNCTION_HANDSHAKE << MPI_DOORBELL_FUNCTION_SHIFT) |
1368 (len << MPI_DOORBELL_ADD_DWORDS_SHIFT);
1369 mpt_write(mpt, MPT_OFFSET_DOORBELL, data);
1371 /* Wait for the chip to notice */
1372 if (mpt_wait_db_int(mpt) != MPT_OK) {
1373 mpt_prt(mpt, "mpt_send_handshake_cmd: db ignored\n");
1377 /* Clear the interrupt */
1378 mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0);
1380 if (mpt_wait_db_ack(mpt) != MPT_OK) {
1381 mpt_prt(mpt, "mpt_send_handshake_cmd: db ack timed out\n");
1385 /* Send the command */
1386 for (i = 0; i < len; i++) {
1387 mpt_write(mpt, MPT_OFFSET_DOORBELL, htole32(*data32++));
1388 if (mpt_wait_db_ack(mpt) != MPT_OK) {
1390 "mpt_send_handshake_cmd: timeout @ index %d\n", i);
1397 /* Get the response from the handshake register */
1399 mpt_recv_handshake_reply(struct mpt_softc *mpt, size_t reply_len, void *reply)
1401 int left, reply_left;
1404 MSG_DEFAULT_REPLY *hdr;
1406 /* We move things out in 16 bit chunks */
1408 data16 = (u_int16_t *)reply;
1410 hdr = (MSG_DEFAULT_REPLY *)reply;
1412 /* Get first word */
1413 if (mpt_wait_db_int(mpt) != MPT_OK) {
1414 mpt_prt(mpt, "mpt_recv_handshake_cmd timeout1\n");
1417 data = mpt_read(mpt, MPT_OFFSET_DOORBELL);
1418 *data16++ = le16toh(data & MPT_DB_DATA_MASK);
1419 mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0);
1421 /* Get Second Word */
1422 if (mpt_wait_db_int(mpt) != MPT_OK) {
1423 mpt_prt(mpt, "mpt_recv_handshake_cmd timeout2\n");
1426 data = mpt_read(mpt, MPT_OFFSET_DOORBELL);
1427 *data16++ = le16toh(data & MPT_DB_DATA_MASK);
1428 mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0);
1431 * With the second word, we can now look at the length.
1432 * Warn about a reply that's too short (except for IOC FACTS REPLY)
1434 if ((reply_len >> 1) != hdr->MsgLength &&
1435 (hdr->Function != MPI_FUNCTION_IOC_FACTS)){
1436 #if __FreeBSD_version >= 500000
1437 mpt_prt(mpt, "reply length does not match message length: "
1438 "got %x; expected %zx for function %x\n",
1439 hdr->MsgLength << 2, reply_len << 1, hdr->Function);
1441 mpt_prt(mpt, "reply length does not match message length: "
1442 "got %x; expected %x for function %x\n",
1443 hdr->MsgLength << 2, reply_len << 1, hdr->Function);
1447 /* Get rest of the reply; but don't overflow the provided buffer */
1448 left = (hdr->MsgLength << 1) - 2;
1449 reply_left = reply_len - 2;
1453 if (mpt_wait_db_int(mpt) != MPT_OK) {
1454 mpt_prt(mpt, "mpt_recv_handshake_cmd timeout3\n");
1457 data = mpt_read(mpt, MPT_OFFSET_DOORBELL);
1458 datum = le16toh(data & MPT_DB_DATA_MASK);
1460 if (reply_left-- > 0)
1463 mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0);
1466 /* One more wait & clear at the end */
1467 if (mpt_wait_db_int(mpt) != MPT_OK) {
1468 mpt_prt(mpt, "mpt_recv_handshake_cmd timeout4\n");
1471 mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0);
1473 if ((hdr->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
1474 if (mpt->verbose >= MPT_PRT_TRACE)
1475 mpt_print_reply(hdr);
1476 return (MPT_FAIL | hdr->IOCStatus);
1483 mpt_get_iocfacts(struct mpt_softc *mpt, MSG_IOC_FACTS_REPLY *freplp)
1485 MSG_IOC_FACTS f_req;
1488 memset(&f_req, 0, sizeof f_req);
1489 f_req.Function = MPI_FUNCTION_IOC_FACTS;
1490 f_req.MsgContext = htole32(MPT_REPLY_HANDLER_HANDSHAKE);
1491 error = mpt_send_handshake_cmd(mpt, sizeof f_req, &f_req);
1495 error = mpt_recv_handshake_reply(mpt, sizeof (*freplp), freplp);
1500 mpt_get_portfacts(struct mpt_softc *mpt, U8 port, MSG_PORT_FACTS_REPLY *freplp)
1502 MSG_PORT_FACTS f_req;
1505 memset(&f_req, 0, sizeof f_req);
1506 f_req.Function = MPI_FUNCTION_PORT_FACTS;
1507 f_req.PortNumber = port;
1508 f_req.MsgContext = htole32(MPT_REPLY_HANDLER_HANDSHAKE);
1509 error = mpt_send_handshake_cmd(mpt, sizeof f_req, &f_req);
1513 error = mpt_recv_handshake_reply(mpt, sizeof (*freplp), freplp);
1518 * Send the initialization request. This is where we specify how many
1519 * SCSI busses and how many devices per bus we wish to emulate.
1520 * This is also the command that specifies the max size of the reply
1521 * frames from the IOC that we will be allocating.
1524 mpt_send_ioc_init(struct mpt_softc *mpt, uint32_t who)
1528 MSG_IOC_INIT_REPLY reply;
1530 memset(&init, 0, sizeof init);
1532 init.Function = MPI_FUNCTION_IOC_INIT;
1533 init.MaxDevices = 0; /* at least 256 devices per bus */
1534 init.MaxBuses = 16; /* at least 16 busses */
1536 init.MsgVersion = htole16(MPI_VERSION);
1537 init.HeaderVersion = htole16(MPI_HEADER_VERSION);
1538 init.ReplyFrameSize = htole16(MPT_REPLY_SIZE);
1539 init.MsgContext = htole32(MPT_REPLY_HANDLER_HANDSHAKE);
1541 if ((error = mpt_send_handshake_cmd(mpt, sizeof init, &init)) != 0) {
1545 error = mpt_recv_handshake_reply(mpt, sizeof reply, &reply);
1551 * Utiltity routine to read configuration headers and pages
1554 mpt_issue_cfg_req(struct mpt_softc *mpt, request_t *req, cfgparms_t *params,
1555 bus_addr_t addr, bus_size_t len, int sleep_ok, int timeout_ms)
1560 cfgp = req->req_vbuf;
1561 memset(cfgp, 0, sizeof *cfgp);
1562 cfgp->Action = params->Action;
1563 cfgp->Function = MPI_FUNCTION_CONFIG;
1564 cfgp->Header.PageVersion = params->PageVersion;
1565 cfgp->Header.PageNumber = params->PageNumber;
1566 cfgp->PageAddress = htole32(params->PageAddress);
1567 if ((params->PageType & MPI_CONFIG_PAGETYPE_MASK) ==
1568 MPI_CONFIG_PAGETYPE_EXTENDED) {
1569 cfgp->Header.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1570 cfgp->Header.PageLength = 0;
1571 cfgp->ExtPageLength = htole16(params->ExtPageLength);
1572 cfgp->ExtPageType = params->ExtPageType;
1574 cfgp->Header.PageType = params->PageType;
1575 cfgp->Header.PageLength = params->PageLength;
1577 se = (SGE_SIMPLE32 *)&cfgp->PageBufferSGE;
1578 se->Address = htole32(addr);
1579 MPI_pSGE_SET_LENGTH(se, len);
1580 MPI_pSGE_SET_FLAGS(se, (MPI_SGE_FLAGS_SIMPLE_ELEMENT |
1581 MPI_SGE_FLAGS_LAST_ELEMENT | MPI_SGE_FLAGS_END_OF_BUFFER |
1582 MPI_SGE_FLAGS_END_OF_LIST |
1583 ((params->Action == MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT
1584 || params->Action == MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM)
1585 ? MPI_SGE_FLAGS_HOST_TO_IOC : MPI_SGE_FLAGS_IOC_TO_HOST)));
1586 se->FlagsLength = htole32(se->FlagsLength);
1587 cfgp->MsgContext = htole32(req->index | MPT_REPLY_HANDLER_CONFIG);
1589 mpt_check_doorbell(mpt);
1590 mpt_send_cmd(mpt, req);
1591 return (mpt_wait_req(mpt, req, REQ_STATE_DONE, REQ_STATE_DONE,
1592 sleep_ok, timeout_ms));
1596 mpt_read_extcfg_header(struct mpt_softc *mpt, int PageVersion, int PageNumber,
1597 uint32_t PageAddress, int ExtPageType,
1598 CONFIG_EXTENDED_PAGE_HEADER *rslt,
1599 int sleep_ok, int timeout_ms)
1603 MSG_CONFIG_REPLY *cfgp;
1606 req = mpt_get_request(mpt, sleep_ok);
1608 mpt_prt(mpt, "mpt_extread_cfg_header: Get request failed!\n");
1612 params.Action = MPI_CONFIG_ACTION_PAGE_HEADER;
1613 params.PageVersion = PageVersion;
1614 params.PageLength = 0;
1615 params.PageNumber = PageNumber;
1616 params.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1617 params.PageAddress = PageAddress;
1618 params.ExtPageType = ExtPageType;
1619 params.ExtPageLength = 0;
1620 error = mpt_issue_cfg_req(mpt, req, ¶ms, /*addr*/0, /*len*/0,
1621 sleep_ok, timeout_ms);
1624 * Leave the request. Without resetting the chip, it's
1625 * still owned by it and we'll just get into trouble
1626 * freeing it now. Mark it as abandoned so that if it
1627 * shows up later it can be freed.
1629 mpt_prt(mpt, "read_extcfg_header timed out\n");
1633 switch (req->IOCStatus & MPI_IOCSTATUS_MASK) {
1634 case MPI_IOCSTATUS_SUCCESS:
1635 cfgp = req->req_vbuf;
1636 rslt->PageVersion = cfgp->Header.PageVersion;
1637 rslt->PageNumber = cfgp->Header.PageNumber;
1638 rslt->PageType = cfgp->Header.PageType;
1639 rslt->ExtPageLength = le16toh(cfgp->ExtPageLength);
1640 rslt->ExtPageType = cfgp->ExtPageType;
1643 case MPI_IOCSTATUS_CONFIG_INVALID_PAGE:
1644 mpt_lprt(mpt, MPT_PRT_DEBUG,
1645 "Invalid Page Type %d Number %d Addr 0x%0x\n",
1646 MPI_CONFIG_PAGETYPE_EXTENDED, PageNumber, PageAddress);
1650 mpt_prt(mpt, "mpt_read_extcfg_header: Config Info Status %x\n",
1655 mpt_free_request(mpt, req);
1660 mpt_read_extcfg_page(struct mpt_softc *mpt, int Action, uint32_t PageAddress,
1661 CONFIG_EXTENDED_PAGE_HEADER *hdr, void *buf, size_t len,
1662 int sleep_ok, int timeout_ms)
1668 req = mpt_get_request(mpt, sleep_ok);
1670 mpt_prt(mpt, "mpt_read_extcfg_page: Get request failed!\n");
1674 params.Action = Action;
1675 params.PageVersion = hdr->PageVersion;
1676 params.PageLength = 0;
1677 params.PageNumber = hdr->PageNumber;
1678 params.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1679 params.PageAddress = PageAddress;
1680 params.ExtPageType = hdr->ExtPageType;
1681 params.ExtPageLength = hdr->ExtPageLength;
1682 error = mpt_issue_cfg_req(mpt, req, ¶ms,
1683 req->req_pbuf + MPT_RQSL(mpt),
1684 len, sleep_ok, timeout_ms);
1686 mpt_prt(mpt, "read_extcfg_page(%d) timed out\n", Action);
1690 if ((req->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
1691 mpt_prt(mpt, "mpt_read_extcfg_page: Config Info Status %x\n",
1693 mpt_free_request(mpt, req);
1696 bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap,
1697 BUS_DMASYNC_POSTREAD);
1698 memcpy(buf, ((uint8_t *)req->req_vbuf)+MPT_RQSL(mpt), len);
1699 mpt_free_request(mpt, req);
1704 mpt_read_cfg_header(struct mpt_softc *mpt, int PageType, int PageNumber,
1705 uint32_t PageAddress, CONFIG_PAGE_HEADER *rslt,
1706 int sleep_ok, int timeout_ms)
1713 req = mpt_get_request(mpt, sleep_ok);
1715 mpt_prt(mpt, "mpt_read_cfg_header: Get request failed!\n");
1719 params.Action = MPI_CONFIG_ACTION_PAGE_HEADER;
1720 params.PageVersion = 0;
1721 params.PageLength = 0;
1722 params.PageNumber = PageNumber;
1723 params.PageType = PageType;
1724 params.PageAddress = PageAddress;
1725 error = mpt_issue_cfg_req(mpt, req, ¶ms, /*addr*/0, /*len*/0,
1726 sleep_ok, timeout_ms);
1729 * Leave the request. Without resetting the chip, it's
1730 * still owned by it and we'll just get into trouble
1731 * freeing it now. Mark it as abandoned so that if it
1732 * shows up later it can be freed.
1734 mpt_prt(mpt, "read_cfg_header timed out\n");
1738 switch (req->IOCStatus & MPI_IOCSTATUS_MASK) {
1739 case MPI_IOCSTATUS_SUCCESS:
1740 cfgp = req->req_vbuf;
1741 bcopy(&cfgp->Header, rslt, sizeof(*rslt));
1744 case MPI_IOCSTATUS_CONFIG_INVALID_PAGE:
1745 mpt_lprt(mpt, MPT_PRT_DEBUG,
1746 "Invalid Page Type %d Number %d Addr 0x%0x\n",
1747 PageType, PageNumber, PageAddress);
1751 mpt_prt(mpt, "mpt_read_cfg_header: Config Info Status %x\n",
1756 mpt_free_request(mpt, req);
1761 mpt_read_cfg_page(struct mpt_softc *mpt, int Action, uint32_t PageAddress,
1762 CONFIG_PAGE_HEADER *hdr, size_t len, int sleep_ok,
1769 req = mpt_get_request(mpt, sleep_ok);
1771 mpt_prt(mpt, "mpt_read_cfg_page: Get request failed!\n");
1775 params.Action = Action;
1776 params.PageVersion = hdr->PageVersion;
1777 params.PageLength = hdr->PageLength;
1778 params.PageNumber = hdr->PageNumber;
1779 params.PageType = hdr->PageType & MPI_CONFIG_PAGETYPE_MASK;
1780 params.PageAddress = PageAddress;
1781 error = mpt_issue_cfg_req(mpt, req, ¶ms,
1782 req->req_pbuf + MPT_RQSL(mpt),
1783 len, sleep_ok, timeout_ms);
1785 mpt_prt(mpt, "read_cfg_page(%d) timed out\n", Action);
1789 if ((req->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
1790 mpt_prt(mpt, "mpt_read_cfg_page: Config Info Status %x\n",
1792 mpt_free_request(mpt, req);
1795 bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap,
1796 BUS_DMASYNC_POSTREAD);
1797 memcpy(hdr, ((uint8_t *)req->req_vbuf)+MPT_RQSL(mpt), len);
1798 mpt_free_request(mpt, req);
1803 mpt_write_cfg_page(struct mpt_softc *mpt, int Action, uint32_t PageAddress,
1804 CONFIG_PAGE_HEADER *hdr, size_t len, int sleep_ok,
1812 hdr_attr = hdr->PageType & MPI_CONFIG_PAGEATTR_MASK;
1813 if (hdr_attr != MPI_CONFIG_PAGEATTR_CHANGEABLE &&
1814 hdr_attr != MPI_CONFIG_PAGEATTR_PERSISTENT) {
1815 mpt_prt(mpt, "page type 0x%x not changeable\n",
1816 hdr->PageType & MPI_CONFIG_PAGETYPE_MASK);
1822 * We shouldn't mask off other bits here.
1824 hdr->PageType &= MPI_CONFIG_PAGETYPE_MASK;
1827 req = mpt_get_request(mpt, sleep_ok);
1831 memcpy(((caddr_t)req->req_vbuf) + MPT_RQSL(mpt), hdr, len);
1834 * There isn't any point in restoring stripped out attributes
1835 * if you then mask them going down to issue the request.
1838 params.Action = Action;
1839 params.PageVersion = hdr->PageVersion;
1840 params.PageLength = hdr->PageLength;
1841 params.PageNumber = hdr->PageNumber;
1842 params.PageAddress = PageAddress;
1844 /* Restore stripped out attributes */
1845 hdr->PageType |= hdr_attr;
1846 params.PageType = hdr->PageType & MPI_CONFIG_PAGETYPE_MASK;
1848 params.PageType = hdr->PageType;
1850 error = mpt_issue_cfg_req(mpt, req, ¶ms,
1851 req->req_pbuf + MPT_RQSL(mpt),
1852 len, sleep_ok, timeout_ms);
1854 mpt_prt(mpt, "mpt_write_cfg_page timed out\n");
1858 if ((req->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
1859 mpt_prt(mpt, "mpt_write_cfg_page: Config Info Status %x\n",
1861 mpt_free_request(mpt, req);
1864 mpt_free_request(mpt, req);
1869 * Read IOC configuration information
1872 mpt_read_config_info_ioc(struct mpt_softc *mpt)
1874 CONFIG_PAGE_HEADER hdr;
1875 struct mpt_raid_volume *mpt_raid;
1880 rv = mpt_read_cfg_header(mpt, MPI_CONFIG_PAGETYPE_IOC,
1881 2, 0, &hdr, FALSE, 5000);
1883 * If it's an invalid page, so what? Not a supported function....
1892 mpt_lprt(mpt, MPT_PRT_DEBUG,
1893 "IOC Page 2 Header: Version %x len %x PageNumber %x PageType %x\n",
1894 hdr.PageVersion, hdr.PageLength << 2,
1895 hdr.PageNumber, hdr.PageType);
1897 len = hdr.PageLength * sizeof(uint32_t);
1898 mpt->ioc_page2 = malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO);
1899 if (mpt->ioc_page2 == NULL) {
1900 mpt_prt(mpt, "unable to allocate memory for IOC page 2\n");
1901 mpt_raid_free_mem(mpt);
1904 memcpy(&mpt->ioc_page2->Header, &hdr, sizeof(hdr));
1905 rv = mpt_read_cur_cfg_page(mpt, 0,
1906 &mpt->ioc_page2->Header, len, FALSE, 5000);
1908 mpt_prt(mpt, "failed to read IOC Page 2\n");
1909 mpt_raid_free_mem(mpt);
1912 mpt2host_config_page_ioc2(mpt->ioc_page2);
1914 if (mpt->ioc_page2->CapabilitiesFlags != 0) {
1917 mpt_prt(mpt, "Capabilities: (");
1918 for (mask = 1; mask != 0; mask <<= 1) {
1919 if ((mpt->ioc_page2->CapabilitiesFlags & mask) == 0) {
1923 case MPI_IOCPAGE2_CAP_FLAGS_IS_SUPPORT:
1924 mpt_prtc(mpt, " RAID-0");
1926 case MPI_IOCPAGE2_CAP_FLAGS_IME_SUPPORT:
1927 mpt_prtc(mpt, " RAID-1E");
1929 case MPI_IOCPAGE2_CAP_FLAGS_IM_SUPPORT:
1930 mpt_prtc(mpt, " RAID-1");
1932 case MPI_IOCPAGE2_CAP_FLAGS_SES_SUPPORT:
1933 mpt_prtc(mpt, " SES");
1935 case MPI_IOCPAGE2_CAP_FLAGS_SAFTE_SUPPORT:
1936 mpt_prtc(mpt, " SAFTE");
1938 case MPI_IOCPAGE2_CAP_FLAGS_CROSS_CHANNEL_SUPPORT:
1939 mpt_prtc(mpt, " Multi-Channel-Arrays");
1944 mpt_prtc(mpt, " )\n");
1945 if ((mpt->ioc_page2->CapabilitiesFlags
1946 & (MPI_IOCPAGE2_CAP_FLAGS_IS_SUPPORT
1947 | MPI_IOCPAGE2_CAP_FLAGS_IME_SUPPORT
1948 | MPI_IOCPAGE2_CAP_FLAGS_IM_SUPPORT)) != 0) {
1949 mpt_prt(mpt, "%d Active Volume%s(%d Max)\n",
1950 mpt->ioc_page2->NumActiveVolumes,
1951 mpt->ioc_page2->NumActiveVolumes != 1
1953 mpt->ioc_page2->MaxVolumes);
1954 mpt_prt(mpt, "%d Hidden Drive Member%s(%d Max)\n",
1955 mpt->ioc_page2->NumActivePhysDisks,
1956 mpt->ioc_page2->NumActivePhysDisks != 1
1958 mpt->ioc_page2->MaxPhysDisks);
1962 len = mpt->ioc_page2->MaxVolumes * sizeof(struct mpt_raid_volume);
1963 mpt->raid_volumes = malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO);
1964 if (mpt->raid_volumes == NULL) {
1965 mpt_prt(mpt, "Could not allocate RAID volume data\n");
1966 mpt_raid_free_mem(mpt);
1971 * Copy critical data out of ioc_page2 so that we can
1972 * safely refresh the page without windows of unreliable
1975 mpt->raid_max_volumes = mpt->ioc_page2->MaxVolumes;
1977 len = sizeof(*mpt->raid_volumes->config_page) +
1978 (sizeof (RAID_VOL0_PHYS_DISK) * (mpt->ioc_page2->MaxPhysDisks - 1));
1979 for (i = 0; i < mpt->ioc_page2->MaxVolumes; i++) {
1980 mpt_raid = &mpt->raid_volumes[i];
1981 mpt_raid->config_page =
1982 malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO);
1983 if (mpt_raid->config_page == NULL) {
1984 mpt_prt(mpt, "Could not allocate RAID page data\n");
1985 mpt_raid_free_mem(mpt);
1989 mpt->raid_page0_len = len;
1991 len = mpt->ioc_page2->MaxPhysDisks * sizeof(struct mpt_raid_disk);
1992 mpt->raid_disks = malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO);
1993 if (mpt->raid_disks == NULL) {
1994 mpt_prt(mpt, "Could not allocate RAID disk data\n");
1995 mpt_raid_free_mem(mpt);
1998 mpt->raid_max_disks = mpt->ioc_page2->MaxPhysDisks;
2003 rv = mpt_read_cfg_header(mpt, MPI_CONFIG_PAGETYPE_IOC,
2004 3, 0, &hdr, FALSE, 5000);
2006 mpt_raid_free_mem(mpt);
2010 mpt_lprt(mpt, MPT_PRT_DEBUG, "IOC Page 3 Header: %x %x %x %x\n",
2011 hdr.PageVersion, hdr.PageLength, hdr.PageNumber, hdr.PageType);
2013 len = hdr.PageLength * sizeof(uint32_t);
2014 mpt->ioc_page3 = malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO);
2015 if (mpt->ioc_page3 == NULL) {
2016 mpt_prt(mpt, "unable to allocate memory for IOC page 3\n");
2017 mpt_raid_free_mem(mpt);
2020 memcpy(&mpt->ioc_page3->Header, &hdr, sizeof(hdr));
2021 rv = mpt_read_cur_cfg_page(mpt, 0,
2022 &mpt->ioc_page3->Header, len, FALSE, 5000);
2024 mpt_raid_free_mem(mpt);
2027 mpt2host_config_page_ioc3(mpt->ioc_page3);
2028 mpt_raid_wakeup(mpt);
2036 mpt_send_port_enable(struct mpt_softc *mpt, int port)
2039 MSG_PORT_ENABLE *enable_req;
2042 req = mpt_get_request(mpt, /*sleep_ok*/FALSE);
2046 enable_req = req->req_vbuf;
2047 memset(enable_req, 0, MPT_RQSL(mpt));
2049 enable_req->Function = MPI_FUNCTION_PORT_ENABLE;
2050 enable_req->MsgContext = htole32(req->index | MPT_REPLY_HANDLER_CONFIG);
2051 enable_req->PortNumber = port;
2053 mpt_check_doorbell(mpt);
2054 mpt_lprt(mpt, MPT_PRT_DEBUG, "enabling port %d\n", port);
2056 mpt_send_cmd(mpt, req);
2057 error = mpt_wait_req(mpt, req, REQ_STATE_DONE, REQ_STATE_DONE,
2058 FALSE, (mpt->is_sas || mpt->is_fc)? 30000 : 3000);
2060 mpt_prt(mpt, "port %d enable timed out\n", port);
2063 mpt_free_request(mpt, req);
2064 mpt_lprt(mpt, MPT_PRT_DEBUG, "enabled port %d\n", port);
2069 * Enable/Disable asynchronous event reporting.
2072 mpt_send_event_request(struct mpt_softc *mpt, int onoff)
2075 MSG_EVENT_NOTIFY *enable_req;
2077 req = mpt_get_request(mpt, FALSE);
2081 enable_req = req->req_vbuf;
2082 memset(enable_req, 0, sizeof *enable_req);
2084 enable_req->Function = MPI_FUNCTION_EVENT_NOTIFICATION;
2085 enable_req->MsgContext = htole32(req->index | MPT_REPLY_HANDLER_EVENTS);
2086 enable_req->Switch = onoff;
2088 mpt_check_doorbell(mpt);
2089 mpt_lprt(mpt, MPT_PRT_DEBUG, "%sabling async events\n",
2090 onoff ? "en" : "dis");
2092 * Send the command off, but don't wait for it.
2094 mpt_send_cmd(mpt, req);
2099 * Un-mask the interrupts on the chip.
2102 mpt_enable_ints(struct mpt_softc *mpt)
2104 /* Unmask every thing except door bell int */
2105 mpt_write(mpt, MPT_OFFSET_INTR_MASK, MPT_INTR_DB_MASK);
2109 * Mask the interrupts on the chip.
2112 mpt_disable_ints(struct mpt_softc *mpt)
2114 /* Mask all interrupts */
2115 mpt_write(mpt, MPT_OFFSET_INTR_MASK,
2116 MPT_INTR_REPLY_MASK | MPT_INTR_DB_MASK);
2120 mpt_sysctl_attach(struct mpt_softc *mpt)
2122 #if __FreeBSD_version >= 500000
2123 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(mpt->dev);
2124 struct sysctl_oid *tree = device_get_sysctl_tree(mpt->dev);
2126 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
2127 "debug", CTLFLAG_RW, &mpt->verbose, 0,
2128 "Debugging/Verbose level");
2129 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
2130 "role", CTLFLAG_RD, &mpt->role, 0,
2132 #ifdef MPT_TEST_MULTIPATH
2133 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
2134 "failure_id", CTLFLAG_RW, &mpt->failure_id, -1,
2135 "Next Target to Fail");
2141 mpt_attach(struct mpt_softc *mpt)
2143 struct mpt_personality *pers;
2147 mpt_core_attach(mpt);
2148 mpt_core_enable(mpt);
2150 TAILQ_INSERT_TAIL(&mpt_tailq, mpt, links);
2151 for (i = 0; i < MPT_MAX_PERSONALITIES; i++) {
2152 pers = mpt_personalities[i];
2156 if (pers->probe(mpt) == 0) {
2157 error = pers->attach(mpt);
2162 mpt->mpt_pers_mask |= (0x1 << pers->id);
2168 * Now that we've attached everything, do the enable function
2169 * for all of the personalities. This allows the personalities
2170 * to do setups that are appropriate for them prior to enabling
2173 for (i = 0; i < MPT_MAX_PERSONALITIES; i++) {
2174 pers = mpt_personalities[i];
2175 if (pers != NULL && MPT_PERS_ATTACHED(pers, mpt) != 0) {
2176 error = pers->enable(mpt);
2178 mpt_prt(mpt, "personality %s attached but would"
2179 " not enable (%d)\n", pers->name, error);
2189 mpt_shutdown(struct mpt_softc *mpt)
2191 struct mpt_personality *pers;
2193 MPT_PERS_FOREACH_REVERSE(mpt, pers) {
2194 pers->shutdown(mpt);
2200 mpt_detach(struct mpt_softc *mpt)
2202 struct mpt_personality *pers;
2204 MPT_PERS_FOREACH_REVERSE(mpt, pers) {
2206 mpt->mpt_pers_mask &= ~(0x1 << pers->id);
2209 TAILQ_REMOVE(&mpt_tailq, mpt, links);
2214 mpt_core_load(struct mpt_personality *pers)
2219 * Setup core handlers and insert the default handler
2220 * into all "empty slots".
2222 for (i = 0; i < MPT_NUM_REPLY_HANDLERS; i++) {
2223 mpt_reply_handlers[i] = mpt_default_reply_handler;
2226 mpt_reply_handlers[MPT_CBI(MPT_REPLY_HANDLER_EVENTS)] =
2227 mpt_event_reply_handler;
2228 mpt_reply_handlers[MPT_CBI(MPT_REPLY_HANDLER_CONFIG)] =
2229 mpt_config_reply_handler;
2230 mpt_reply_handlers[MPT_CBI(MPT_REPLY_HANDLER_HANDSHAKE)] =
2231 mpt_handshake_reply_handler;
2236 * Initialize per-instance driver data and perform
2237 * initial controller configuration.
2240 mpt_core_attach(struct mpt_softc *mpt)
2244 LIST_INIT(&mpt->ack_frames);
2245 /* Put all request buffers on the free list */
2246 TAILQ_INIT(&mpt->request_pending_list);
2247 TAILQ_INIT(&mpt->request_free_list);
2248 TAILQ_INIT(&mpt->request_timeout_list);
2250 for (val = 0; val < MPT_MAX_REQUESTS(mpt); val++) {
2251 request_t *req = &mpt->request_pool[val];
2252 req->state = REQ_STATE_ALLOCATED;
2253 mpt_callout_init(mpt, &req->callout);
2254 mpt_free_request(mpt, req);
2257 for (val = 0; val < MPT_MAX_LUNS; val++) {
2258 STAILQ_INIT(&mpt->trt[val].atios);
2259 STAILQ_INIT(&mpt->trt[val].inots);
2261 STAILQ_INIT(&mpt->trt_wildcard.atios);
2262 STAILQ_INIT(&mpt->trt_wildcard.inots);
2263 #ifdef MPT_TEST_MULTIPATH
2264 mpt->failure_id = -1;
2266 mpt->scsi_tgt_handler_id = MPT_HANDLER_ID_NONE;
2267 mpt_sysctl_attach(mpt);
2268 mpt_lprt(mpt, MPT_PRT_DEBUG, "doorbell req = %s\n",
2269 mpt_ioc_diag(mpt_read(mpt, MPT_OFFSET_DOORBELL)));
2272 error = mpt_configure_ioc(mpt, 0, 0);
2279 mpt_core_enable(struct mpt_softc *mpt)
2282 * We enter with the IOC enabled, but async events
2283 * not enabled, ports not enabled and interrupts
2289 * Enable asynchronous event reporting- all personalities
2290 * have attached so that they should be able to now field
2293 mpt_send_event_request(mpt, 1);
2296 * Catch any pending interrupts
2298 * This seems to be crucial- otherwise
2299 * the portenable below times out.
2306 mpt_enable_ints(mpt);
2309 * Catch any pending interrupts
2311 * This seems to be crucial- otherwise
2312 * the portenable below times out.
2319 if (mpt_send_port_enable(mpt, 0) != MPT_OK) {
2320 mpt_prt(mpt, "failed to enable port 0\n");
2329 mpt_core_shutdown(struct mpt_softc *mpt)
2331 mpt_disable_ints(mpt);
2335 mpt_core_detach(struct mpt_softc *mpt)
2342 mpt_disable_ints(mpt);
2344 /* Make sure no request has pending timeouts. */
2345 for (val = 0; val < MPT_MAX_REQUESTS(mpt); val++) {
2346 request_t *req = &mpt->request_pool[val];
2347 mpt_callout_drain(mpt, &req->callout);
2352 mpt_core_unload(struct mpt_personality *pers)
2354 /* Unload is always successfull. */
2358 #define FW_UPLOAD_REQ_SIZE \
2359 (sizeof(MSG_FW_UPLOAD) - sizeof(SGE_MPI_UNION) \
2360 + sizeof(FW_UPLOAD_TCSGE) + sizeof(SGE_SIMPLE32))
2363 mpt_upload_fw(struct mpt_softc *mpt)
2365 uint8_t fw_req_buf[FW_UPLOAD_REQ_SIZE];
2366 MSG_FW_UPLOAD_REPLY fw_reply;
2367 MSG_FW_UPLOAD *fw_req;
2368 FW_UPLOAD_TCSGE *tsge;
2373 memset(&fw_req_buf, 0, sizeof(fw_req_buf));
2374 fw_req = (MSG_FW_UPLOAD *)fw_req_buf;
2375 fw_req->ImageType = MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM;
2376 fw_req->Function = MPI_FUNCTION_FW_UPLOAD;
2377 fw_req->MsgContext = htole32(MPT_REPLY_HANDLER_HANDSHAKE);
2378 tsge = (FW_UPLOAD_TCSGE *)&fw_req->SGL;
2379 tsge->DetailsLength = 12;
2380 tsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
2381 tsge->ImageSize = htole32(mpt->fw_image_size);
2382 sge = (SGE_SIMPLE32 *)(tsge + 1);
2383 flags = (MPI_SGE_FLAGS_LAST_ELEMENT | MPI_SGE_FLAGS_END_OF_BUFFER
2384 | MPI_SGE_FLAGS_END_OF_LIST | MPI_SGE_FLAGS_SIMPLE_ELEMENT
2385 | MPI_SGE_FLAGS_32_BIT_ADDRESSING | MPI_SGE_FLAGS_IOC_TO_HOST);
2386 flags <<= MPI_SGE_FLAGS_SHIFT;
2387 sge->FlagsLength = htole32(flags | mpt->fw_image_size);
2388 sge->Address = htole32(mpt->fw_phys);
2389 error = mpt_send_handshake_cmd(mpt, sizeof(fw_req_buf), &fw_req_buf);
2392 error = mpt_recv_handshake_reply(mpt, sizeof(fw_reply), &fw_reply);
2397 mpt_diag_outsl(struct mpt_softc *mpt, uint32_t addr,
2398 uint32_t *data, bus_size_t len)
2402 data_end = data + (roundup2(len, sizeof(uint32_t)) / 4);
2404 pci_enable_io(mpt->dev, SYS_RES_IOPORT);
2406 mpt_pio_write(mpt, MPT_OFFSET_DIAG_ADDR, addr);
2407 while (data != data_end) {
2408 mpt_pio_write(mpt, MPT_OFFSET_DIAG_DATA, *data);
2412 pci_disable_io(mpt->dev, SYS_RES_IOPORT);
2417 mpt_download_fw(struct mpt_softc *mpt)
2419 MpiFwHeader_t *fw_hdr;
2421 uint32_t ext_offset;
2424 mpt_prt(mpt, "Downloading Firmware - Image Size %d\n",
2425 mpt->fw_image_size);
2427 error = mpt_enable_diag_mode(mpt);
2429 mpt_prt(mpt, "Could not enter diagnostic mode!\n");
2433 mpt_write(mpt, MPT_OFFSET_DIAGNOSTIC,
2434 MPI_DIAG_RW_ENABLE|MPI_DIAG_DISABLE_ARM);
2436 fw_hdr = (MpiFwHeader_t *)mpt->fw_image;
2437 mpt_diag_outsl(mpt, fw_hdr->LoadStartAddress, (uint32_t*)fw_hdr,
2440 ext_offset = fw_hdr->NextImageHeaderOffset;
2441 while (ext_offset != 0) {
2442 MpiExtImageHeader_t *ext;
2444 ext = (MpiExtImageHeader_t *)((uintptr_t)fw_hdr + ext_offset);
2445 ext_offset = ext->NextImageHeaderOffset;
2447 mpt_diag_outsl(mpt, ext->LoadStartAddress, (uint32_t*)ext,
2452 pci_enable_io(mpt->dev, SYS_RES_IOPORT);
2454 /* Setup the address to jump to on reset. */
2455 mpt_pio_write(mpt, MPT_OFFSET_DIAG_ADDR, fw_hdr->IopResetRegAddr);
2456 mpt_pio_write(mpt, MPT_OFFSET_DIAG_DATA, fw_hdr->IopResetVectorValue);
2459 * The controller sets the "flash bad" status after attempting
2460 * to auto-boot from flash. Clear the status so that the controller
2461 * will continue the boot process with our newly installed firmware.
2463 mpt_pio_write(mpt, MPT_OFFSET_DIAG_ADDR, MPT_DIAG_MEM_CFG_BASE);
2464 data = mpt_pio_read(mpt, MPT_OFFSET_DIAG_DATA) | MPT_DIAG_MEM_CFG_BADFL;
2465 mpt_pio_write(mpt, MPT_OFFSET_DIAG_ADDR, MPT_DIAG_MEM_CFG_BASE);
2466 mpt_pio_write(mpt, MPT_OFFSET_DIAG_DATA, data);
2469 pci_disable_io(mpt->dev, SYS_RES_IOPORT);
2473 * Re-enable the processor and clear the boot halt flag.
2475 data = mpt_read(mpt, MPT_OFFSET_DIAGNOSTIC);
2476 data &= ~(MPI_DIAG_PREVENT_IOC_BOOT|MPI_DIAG_DISABLE_ARM);
2477 mpt_write(mpt, MPT_OFFSET_DIAGNOSTIC, data);
2479 mpt_disable_diag_mode(mpt);
2484 * Allocate/Initialize data structures for the controller. Called
2485 * once at instance startup.
2488 mpt_configure_ioc(struct mpt_softc *mpt, int tn, int needreset)
2490 PTR_MSG_PORT_FACTS_REPLY pfp;
2494 if (tn == MPT_MAX_TRYS) {
2499 * No need to reset if the IOC is already in the READY state.
2501 * Force reset if initialization failed previously.
2502 * Note that a hard_reset of the second channel of a '929
2503 * will stop operation of the first channel. Hopefully, if the
2504 * first channel is ok, the second will not require a hard
2507 if (needreset || MPT_STATE(mpt_rd_db(mpt)) != MPT_DB_STATE_READY) {
2508 if (mpt_reset(mpt, FALSE) != MPT_OK) {
2509 return (mpt_configure_ioc(mpt, tn++, 1));
2514 if (mpt_get_iocfacts(mpt, &mpt->ioc_facts) != MPT_OK) {
2515 mpt_prt(mpt, "mpt_get_iocfacts failed\n");
2516 return (mpt_configure_ioc(mpt, tn++, 1));
2518 mpt2host_iocfacts_reply(&mpt->ioc_facts);
2520 mpt_prt(mpt, "MPI Version=%d.%d.%d.%d\n",
2521 mpt->ioc_facts.MsgVersion >> 8,
2522 mpt->ioc_facts.MsgVersion & 0xFF,
2523 mpt->ioc_facts.HeaderVersion >> 8,
2524 mpt->ioc_facts.HeaderVersion & 0xFF);
2527 * Now that we know request frame size, we can calculate
2528 * the actual (reasonable) segment limit for read/write I/O.
2530 * This limit is constrained by:
2532 * + The size of each area we allocate per command (and how
2533 * many chain segments we can fit into it).
2534 * + The total number of areas we've set up.
2535 * + The actual chain depth the card will allow.
2537 * The first area's segment count is limited by the I/O request
2538 * at the head of it. We cannot allocate realistically more
2539 * than MPT_MAX_REQUESTS areas. Therefore, to account for both
2540 * conditions, we'll just start out with MPT_MAX_REQUESTS-2.
2543 /* total number of request areas we (can) allocate */
2544 mpt->max_seg_cnt = MPT_MAX_REQUESTS(mpt) - 2;
2546 /* converted to the number of chain areas possible */
2547 mpt->max_seg_cnt *= MPT_NRFM(mpt);
2549 /* limited by the number of chain areas the card will support */
2550 if (mpt->max_seg_cnt > mpt->ioc_facts.MaxChainDepth) {
2551 mpt_lprt(mpt, MPT_PRT_DEBUG,
2552 "chain depth limited to %u (from %u)\n",
2553 mpt->ioc_facts.MaxChainDepth, mpt->max_seg_cnt);
2554 mpt->max_seg_cnt = mpt->ioc_facts.MaxChainDepth;
2557 /* converted to the number of simple sges in chain segments. */
2558 mpt->max_seg_cnt *= (MPT_NSGL(mpt) - 1);
2560 mpt_lprt(mpt, MPT_PRT_DEBUG, "Maximum Segment Count: %u\n",
2562 mpt_lprt(mpt, MPT_PRT_DEBUG, "MsgLength=%u IOCNumber = %d\n",
2563 mpt->ioc_facts.MsgLength, mpt->ioc_facts.IOCNumber);
2564 mpt_lprt(mpt, MPT_PRT_DEBUG,
2565 "IOCFACTS: GlobalCredits=%d BlockSize=%u bytes "
2566 "Request Frame Size %u bytes Max Chain Depth %u\n",
2567 mpt->ioc_facts.GlobalCredits, mpt->ioc_facts.BlockSize,
2568 mpt->ioc_facts.RequestFrameSize << 2,
2569 mpt->ioc_facts.MaxChainDepth);
2570 mpt_lprt(mpt, MPT_PRT_DEBUG, "IOCFACTS: Num Ports %d, FWImageSize %d, "
2571 "Flags=%#x\n", mpt->ioc_facts.NumberOfPorts,
2572 mpt->ioc_facts.FWImageSize, mpt->ioc_facts.Flags);
2574 len = mpt->ioc_facts.NumberOfPorts * sizeof (MSG_PORT_FACTS_REPLY);
2575 mpt->port_facts = malloc(len, M_DEVBUF, M_NOWAIT | M_ZERO);
2576 if (mpt->port_facts == NULL) {
2577 mpt_prt(mpt, "unable to allocate memory for port facts\n");
2582 if ((mpt->ioc_facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT) &&
2583 (mpt->fw_uploaded == 0)) {
2584 struct mpt_map_info mi;
2587 * In some configurations, the IOC's firmware is
2588 * stored in a shared piece of system NVRAM that
2589 * is only accessable via the BIOS. In this
2590 * case, the firmware keeps a copy of firmware in
2591 * RAM until the OS driver retrieves it. Once
2592 * retrieved, we are responsible for re-downloading
2593 * the firmware after any hard-reset.
2595 mpt->fw_image_size = mpt->ioc_facts.FWImageSize;
2596 error = mpt_dma_tag_create(mpt, mpt->parent_dmat, 1, 0,
2597 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
2598 mpt->fw_image_size, 1, mpt->fw_image_size, 0,
2601 mpt_prt(mpt, "cannot create firmwarew dma tag\n");
2604 error = bus_dmamem_alloc(mpt->fw_dmat,
2605 (void **)&mpt->fw_image, BUS_DMA_NOWAIT, &mpt->fw_dmap);
2607 mpt_prt(mpt, "cannot allocate firmware memory\n");
2608 bus_dma_tag_destroy(mpt->fw_dmat);
2613 bus_dmamap_load(mpt->fw_dmat, mpt->fw_dmap,
2614 mpt->fw_image, mpt->fw_image_size, mpt_map_rquest, &mi, 0);
2615 mpt->fw_phys = mi.phys;
2617 error = mpt_upload_fw(mpt);
2619 mpt_prt(mpt, "firmware upload failed.\n");
2620 bus_dmamap_unload(mpt->fw_dmat, mpt->fw_dmap);
2621 bus_dmamem_free(mpt->fw_dmat, mpt->fw_image,
2623 bus_dma_tag_destroy(mpt->fw_dmat);
2624 mpt->fw_image = NULL;
2627 mpt->fw_uploaded = 1;
2630 for (port = 0; port < mpt->ioc_facts.NumberOfPorts; port++) {
2631 pfp = &mpt->port_facts[port];
2632 error = mpt_get_portfacts(mpt, 0, pfp);
2633 if (error != MPT_OK) {
2635 "mpt_get_portfacts on port %d failed\n", port);
2636 free(mpt->port_facts, M_DEVBUF);
2637 mpt->port_facts = NULL;
2638 return (mpt_configure_ioc(mpt, tn++, 1));
2640 mpt2host_portfacts_reply(pfp);
2643 error = MPT_PRT_INFO;
2645 error = MPT_PRT_DEBUG;
2647 mpt_lprt(mpt, error,
2648 "PORTFACTS[%d]: Type %x PFlags %x IID %d MaxDev %d\n",
2649 port, pfp->PortType, pfp->ProtocolFlags, pfp->PortSCSIID,
2655 * XXX: Not yet supporting more than port 0
2657 pfp = &mpt->port_facts[0];
2658 if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_FC) {
2662 } else if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_SAS) {
2666 } else if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_SCSI) {
2670 if (mpt->mpt_ini_id == MPT_INI_ID_NONE)
2671 mpt->mpt_ini_id = pfp->PortSCSIID;
2672 } else if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_ISCSI) {
2673 mpt_prt(mpt, "iSCSI not supported yet\n");
2675 } else if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_INACTIVE) {
2676 mpt_prt(mpt, "Inactive Port\n");
2679 mpt_prt(mpt, "unknown Port Type %#x\n", pfp->PortType);
2684 * Set our role with what this port supports.
2686 * Note this might be changed later in different modules
2687 * if this is different from what is wanted.
2689 mpt->role = MPT_ROLE_NONE;
2690 if (pfp->ProtocolFlags & MPI_PORTFACTS_PROTOCOL_INITIATOR) {
2691 mpt->role |= MPT_ROLE_INITIATOR;
2693 if (pfp->ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
2694 mpt->role |= MPT_ROLE_TARGET;
2700 if (mpt_enable_ioc(mpt, 1) != MPT_OK) {
2701 mpt_prt(mpt, "unable to initialize IOC\n");
2706 * Read IOC configuration information.
2708 * We need this to determine whether or not we have certain
2709 * settings for Integrated Mirroring (e.g.).
2711 mpt_read_config_info_ioc(mpt);
2717 mpt_enable_ioc(struct mpt_softc *mpt, int portenable)
2722 if (mpt_send_ioc_init(mpt, MPI_WHOINIT_HOST_DRIVER) != MPT_OK) {
2723 mpt_prt(mpt, "mpt_send_ioc_init failed\n");
2727 mpt_lprt(mpt, MPT_PRT_DEBUG, "mpt_send_ioc_init ok\n");
2729 if (mpt_wait_state(mpt, MPT_DB_STATE_RUNNING) != MPT_OK) {
2730 mpt_prt(mpt, "IOC failed to go to run state\n");
2733 mpt_lprt(mpt, MPT_PRT_DEBUG, "IOC now at RUNSTATE\n");
2736 * Give it reply buffers
2738 * Do *not* exceed global credits.
2740 for (val = 0, pptr = mpt->reply_phys;
2741 (pptr + MPT_REPLY_SIZE) < (mpt->reply_phys + PAGE_SIZE);
2742 pptr += MPT_REPLY_SIZE) {
2743 mpt_free_reply(mpt, pptr);
2744 if (++val == mpt->ioc_facts.GlobalCredits - 1)
2750 * Enable the port if asked. This is only done if we're resetting
2751 * the IOC after initial startup.
2755 * Enable asynchronous event reporting
2757 mpt_send_event_request(mpt, 1);
2759 if (mpt_send_port_enable(mpt, 0) != MPT_OK) {
2760 mpt_prt(mpt, "failed to enable port 0\n");
2768 * Endian Conversion Functions- only used on Big Endian machines
2770 #if _BYTE_ORDER == _BIG_ENDIAN
2772 mpt2host_sge_simple_union(SGE_SIMPLE_UNION *sge)
2775 MPT_2_HOST32(sge, FlagsLength);
2776 MPT_2_HOST32(sge, u.Address64.Low);
2777 MPT_2_HOST32(sge, u.Address64.High);
2781 mpt2host_iocfacts_reply(MSG_IOC_FACTS_REPLY *rp)
2784 MPT_2_HOST16(rp, MsgVersion);
2785 MPT_2_HOST16(rp, HeaderVersion);
2786 MPT_2_HOST32(rp, MsgContext);
2787 MPT_2_HOST16(rp, IOCExceptions);
2788 MPT_2_HOST16(rp, IOCStatus);
2789 MPT_2_HOST32(rp, IOCLogInfo);
2790 MPT_2_HOST16(rp, ReplyQueueDepth);
2791 MPT_2_HOST16(rp, RequestFrameSize);
2792 MPT_2_HOST16(rp, Reserved_0101_FWVersion);
2793 MPT_2_HOST16(rp, ProductID);
2794 MPT_2_HOST32(rp, CurrentHostMfaHighAddr);
2795 MPT_2_HOST16(rp, GlobalCredits);
2796 MPT_2_HOST32(rp, CurrentSenseBufferHighAddr);
2797 MPT_2_HOST16(rp, CurReplyFrameSize);
2798 MPT_2_HOST32(rp, FWImageSize);
2799 MPT_2_HOST32(rp, IOCCapabilities);
2800 MPT_2_HOST32(rp, FWVersion.Word);
2801 MPT_2_HOST16(rp, HighPriorityQueueDepth);
2802 MPT_2_HOST16(rp, Reserved2);
2803 mpt2host_sge_simple_union(&rp->HostPageBufferSGE);
2804 MPT_2_HOST32(rp, ReplyFifoHostSignalingAddr);
2808 mpt2host_portfacts_reply(MSG_PORT_FACTS_REPLY *pfp)
2811 MPT_2_HOST16(pfp, Reserved);
2812 MPT_2_HOST16(pfp, Reserved1);
2813 MPT_2_HOST32(pfp, MsgContext);
2814 MPT_2_HOST16(pfp, Reserved2);
2815 MPT_2_HOST16(pfp, IOCStatus);
2816 MPT_2_HOST32(pfp, IOCLogInfo);
2817 MPT_2_HOST16(pfp, MaxDevices);
2818 MPT_2_HOST16(pfp, PortSCSIID);
2819 MPT_2_HOST16(pfp, ProtocolFlags);
2820 MPT_2_HOST16(pfp, MaxPostedCmdBuffers);
2821 MPT_2_HOST16(pfp, MaxPersistentIDs);
2822 MPT_2_HOST16(pfp, MaxLanBuckets);
2823 MPT_2_HOST16(pfp, Reserved4);
2824 MPT_2_HOST32(pfp, Reserved5);
2828 mpt2host_config_page_ioc2(CONFIG_PAGE_IOC_2 *ioc2)
2832 MPT_2_HOST32(ioc2, CapabilitiesFlags);
2833 for (i = 0; i < MPI_IOC_PAGE_2_RAID_VOLUME_MAX; i++) {
2834 MPT_2_HOST16(ioc2, RaidVolume[i].Reserved3);
2839 mpt2host_config_page_ioc3(CONFIG_PAGE_IOC_3 *ioc3)
2842 MPT_2_HOST16(ioc3, Reserved2);
2846 mpt2host_config_page_scsi_port_0(CONFIG_PAGE_SCSI_PORT_0 *sp0)
2849 MPT_2_HOST32(sp0, Capabilities);
2850 MPT_2_HOST32(sp0, PhysicalInterface);
2854 mpt2host_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *sp1)
2857 MPT_2_HOST32(sp1, Configuration);
2858 MPT_2_HOST32(sp1, OnBusTimerValue);
2859 MPT_2_HOST16(sp1, IDConfig);
2863 host2mpt_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *sp1)
2866 HOST_2_MPT32(sp1, Configuration);
2867 HOST_2_MPT32(sp1, OnBusTimerValue);
2868 HOST_2_MPT16(sp1, IDConfig);
2872 mpt2host_config_page_scsi_port_2(CONFIG_PAGE_SCSI_PORT_2 *sp2)
2876 MPT_2_HOST32(sp2, PortFlags);
2877 MPT_2_HOST32(sp2, PortSettings);
2878 for (i = 0; i < sizeof(sp2->DeviceSettings) /
2879 sizeof(*sp2->DeviceSettings); i++) {
2880 MPT_2_HOST16(sp2, DeviceSettings[i].DeviceFlags);
2885 mpt2host_config_page_scsi_device_0(CONFIG_PAGE_SCSI_DEVICE_0 *sd0)
2888 MPT_2_HOST32(sd0, NegotiatedParameters);
2889 MPT_2_HOST32(sd0, Information);
2893 mpt2host_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *sd1)
2896 MPT_2_HOST32(sd1, RequestedParameters);
2897 MPT_2_HOST32(sd1, Reserved);
2898 MPT_2_HOST32(sd1, Configuration);
2902 host2mpt_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *sd1)
2905 HOST_2_MPT32(sd1, RequestedParameters);
2906 HOST_2_MPT32(sd1, Reserved);
2907 HOST_2_MPT32(sd1, Configuration);
2911 mpt2host_config_page_fc_port_0(CONFIG_PAGE_FC_PORT_0 *fp0)
2914 MPT_2_HOST32(fp0, Flags);
2915 MPT_2_HOST32(fp0, PortIdentifier);
2916 MPT_2_HOST32(fp0, WWNN.Low);
2917 MPT_2_HOST32(fp0, WWNN.High);
2918 MPT_2_HOST32(fp0, WWPN.Low);
2919 MPT_2_HOST32(fp0, WWPN.High);
2920 MPT_2_HOST32(fp0, SupportedServiceClass);
2921 MPT_2_HOST32(fp0, SupportedSpeeds);
2922 MPT_2_HOST32(fp0, CurrentSpeed);
2923 MPT_2_HOST32(fp0, MaxFrameSize);
2924 MPT_2_HOST32(fp0, FabricWWNN.Low);
2925 MPT_2_HOST32(fp0, FabricWWNN.High);
2926 MPT_2_HOST32(fp0, FabricWWPN.Low);
2927 MPT_2_HOST32(fp0, FabricWWPN.High);
2928 MPT_2_HOST32(fp0, DiscoveredPortsCount);
2929 MPT_2_HOST32(fp0, MaxInitiators);
2933 mpt2host_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *fp1)
2936 MPT_2_HOST32(fp1, Flags);
2937 MPT_2_HOST32(fp1, NoSEEPROMWWNN.Low);
2938 MPT_2_HOST32(fp1, NoSEEPROMWWNN.High);
2939 MPT_2_HOST32(fp1, NoSEEPROMWWPN.Low);
2940 MPT_2_HOST32(fp1, NoSEEPROMWWPN.High);
2944 host2mpt_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *fp1)
2947 HOST_2_MPT32(fp1, Flags);
2948 HOST_2_MPT32(fp1, NoSEEPROMWWNN.Low);
2949 HOST_2_MPT32(fp1, NoSEEPROMWWNN.High);
2950 HOST_2_MPT32(fp1, NoSEEPROMWWPN.Low);
2951 HOST_2_MPT32(fp1, NoSEEPROMWWPN.High);
2955 mpt2host_config_page_raid_vol_0(CONFIG_PAGE_RAID_VOL_0 *volp)
2959 MPT_2_HOST16(volp, VolumeStatus.Reserved);
2960 MPT_2_HOST16(volp, VolumeSettings.Settings);
2961 MPT_2_HOST32(volp, MaxLBA);
2962 MPT_2_HOST32(volp, MaxLBAHigh);
2963 MPT_2_HOST32(volp, StripeSize);
2964 MPT_2_HOST32(volp, Reserved2);
2965 MPT_2_HOST32(volp, Reserved3);
2966 for (i = 0; i < MPI_RAID_VOL_PAGE_0_PHYSDISK_MAX; i++) {
2967 MPT_2_HOST16(volp, PhysDisk[i].Reserved);
2972 mpt2host_config_page_raid_phys_disk_0(CONFIG_PAGE_RAID_PHYS_DISK_0 *rpd0)
2975 MPT_2_HOST32(rpd0, Reserved1);
2976 MPT_2_HOST16(rpd0, PhysDiskStatus.Reserved);
2977 MPT_2_HOST32(rpd0, MaxLBA);
2978 MPT_2_HOST16(rpd0, ErrorData.Reserved);
2979 MPT_2_HOST16(rpd0, ErrorData.ErrorCount);
2980 MPT_2_HOST16(rpd0, ErrorData.SmartCount);
2984 mpt2host_mpi_raid_vol_indicator(MPI_RAID_VOL_INDICATOR *vi)
2987 MPT_2_HOST16(vi, TotalBlocks.High);
2988 MPT_2_HOST16(vi, TotalBlocks.Low);
2989 MPT_2_HOST16(vi, BlocksRemaining.High);
2990 MPT_2_HOST16(vi, BlocksRemaining.Low);