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.
97 * $FreeBSD: src/sys/dev/mpt/mpt.c,v 1.49 2009/01/07 21:52:47 marius Exp $
100 #include <dev/disk/mpt/mpt.h>
101 #include <dev/disk/mpt/mpt_cam.h> /* XXX For static handler registration */
102 #include <dev/disk/mpt/mpt_raid.h> /* XXX For static handler registration */
104 #include <dev/disk/mpt/mpilib/mpi.h>
105 #include <dev/disk/mpt/mpilib/mpi_ioc.h>
106 #include <dev/disk/mpt/mpilib/mpi_fc.h>
107 #include <dev/disk/mpt/mpilib/mpi_targ.h>
109 #include <sys/sysctl.h>
111 #define MPT_MAX_TRYS 3
112 #define MPT_MAX_WAIT 300000
114 static int maxwait_ack = 0;
115 static int maxwait_int = 0;
116 static int maxwait_state = 0;
118 static TAILQ_HEAD(, mpt_softc) mpt_tailq = TAILQ_HEAD_INITIALIZER(mpt_tailq);
119 mpt_reply_handler_t *mpt_reply_handlers[MPT_NUM_REPLY_HANDLERS];
121 static mpt_reply_handler_t mpt_default_reply_handler;
122 static mpt_reply_handler_t mpt_config_reply_handler;
123 static mpt_reply_handler_t mpt_handshake_reply_handler;
124 static mpt_reply_handler_t mpt_event_reply_handler;
125 static void mpt_send_event_ack(struct mpt_softc *mpt, request_t *ack_req,
126 MSG_EVENT_NOTIFY_REPLY *msg, uint32_t context);
127 static int mpt_send_event_request(struct mpt_softc *mpt, int onoff);
128 static int mpt_soft_reset(struct mpt_softc *mpt);
129 static void mpt_hard_reset(struct mpt_softc *mpt);
130 static int mpt_configure_ioc(struct mpt_softc *mpt, int, int);
131 static int mpt_enable_ioc(struct mpt_softc *mpt, int);
133 /************************* Personality Module Support *************************/
135 * We include one extra entry that is guaranteed to be NULL
136 * to simplify our itterator.
138 static struct mpt_personality *mpt_personalities[MPT_MAX_PERSONALITIES + 1];
139 static __inline struct mpt_personality*
140 mpt_pers_find(struct mpt_softc *, u_int);
141 static __inline struct mpt_personality*
142 mpt_pers_find_reverse(struct mpt_softc *, u_int);
144 static __inline struct mpt_personality *
145 mpt_pers_find(struct mpt_softc *mpt, u_int start_at)
147 KASSERT(start_at <= MPT_MAX_PERSONALITIES,
148 ("mpt_pers_find: starting position out of range\n"));
150 while (start_at < MPT_MAX_PERSONALITIES
151 && (mpt->mpt_pers_mask & (0x1 << start_at)) == 0) {
154 return (mpt_personalities[start_at]);
158 * Used infrequently, so no need to optimize like a forward
159 * traversal where we use the MAX+1 is guaranteed to be NULL
162 static __inline struct mpt_personality *
163 mpt_pers_find_reverse(struct mpt_softc *mpt, u_int start_at)
165 while (start_at < MPT_MAX_PERSONALITIES
166 && (mpt->mpt_pers_mask & (0x1 << start_at)) == 0) {
169 if (start_at < MPT_MAX_PERSONALITIES)
170 return (mpt_personalities[start_at]);
174 #define MPT_PERS_FOREACH(mpt, pers) \
175 for (pers = mpt_pers_find(mpt, /*start_at*/0); \
177 pers = mpt_pers_find(mpt, /*start_at*/pers->id+1))
179 #define MPT_PERS_FOREACH_REVERSE(mpt, pers) \
180 for (pers = mpt_pers_find_reverse(mpt, MPT_MAX_PERSONALITIES-1);\
182 pers = mpt_pers_find_reverse(mpt, /*start_at*/pers->id-1))
184 static mpt_load_handler_t mpt_stdload;
185 static mpt_probe_handler_t mpt_stdprobe;
186 static mpt_attach_handler_t mpt_stdattach;
187 static mpt_enable_handler_t mpt_stdenable;
188 static mpt_ready_handler_t mpt_stdready;
189 static mpt_event_handler_t mpt_stdevent;
190 static mpt_reset_handler_t mpt_stdreset;
191 static mpt_shutdown_handler_t mpt_stdshutdown;
192 static mpt_detach_handler_t mpt_stddetach;
193 static mpt_unload_handler_t mpt_stdunload;
194 static struct mpt_personality mpt_default_personality =
197 .probe = mpt_stdprobe,
198 .attach = mpt_stdattach,
199 .enable = mpt_stdenable,
200 .ready = mpt_stdready,
201 .event = mpt_stdevent,
202 .reset = mpt_stdreset,
203 .shutdown = mpt_stdshutdown,
204 .detach = mpt_stddetach,
205 .unload = mpt_stdunload
208 static mpt_load_handler_t mpt_core_load;
209 static mpt_attach_handler_t mpt_core_attach;
210 static mpt_enable_handler_t mpt_core_enable;
211 static mpt_reset_handler_t mpt_core_ioc_reset;
212 static mpt_event_handler_t mpt_core_event;
213 static mpt_shutdown_handler_t mpt_core_shutdown;
214 static mpt_shutdown_handler_t mpt_core_detach;
215 static mpt_unload_handler_t mpt_core_unload;
216 static struct mpt_personality mpt_core_personality =
219 .load = mpt_core_load,
220 // .attach = mpt_core_attach,
221 // .enable = mpt_core_enable,
222 .event = mpt_core_event,
223 .reset = mpt_core_ioc_reset,
224 .shutdown = mpt_core_shutdown,
225 .detach = mpt_core_detach,
226 .unload = mpt_core_unload,
230 * Manual declaration so that DECLARE_MPT_PERSONALITY doesn't need
231 * ordering information. We want the core to always register FIRST.
232 * other modules are set to SI_ORDER_SECOND.
234 static moduledata_t mpt_core_mod = {
235 "mpt_core", mpt_modevent, &mpt_core_personality
237 DECLARE_MODULE(mpt_core, mpt_core_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
238 MODULE_VERSION(mpt_core, 1);
240 #define MPT_PERS_ATTACHED(pers, mpt) ((mpt)->mpt_pers_mask & (0x1 << pers->id))
243 mpt_modevent(module_t mod, int type, void *data)
245 struct mpt_personality *pers;
248 pers = (struct mpt_personality *)data;
254 mpt_load_handler_t **def_handler;
255 mpt_load_handler_t **pers_handler;
258 for (i = 0; i < MPT_MAX_PERSONALITIES; i++) {
259 if (mpt_personalities[i] == NULL)
262 if (i >= MPT_MAX_PERSONALITIES) {
267 mpt_personalities[i] = pers;
269 /* Install standard/noop handlers for any NULL entries. */
270 def_handler = MPT_PERS_FIRST_HANDLER(&mpt_default_personality);
271 pers_handler = MPT_PERS_FIRST_HANDLER(pers);
272 while (pers_handler <= MPT_PERS_LAST_HANDLER(pers)) {
273 if (*pers_handler == NULL)
274 *pers_handler = *def_handler;
279 error = (pers->load(pers));
281 mpt_personalities[i] = NULL;
286 #if __FreeBSD_version >= 500000
291 error = pers->unload(pers);
292 mpt_personalities[pers->id] = NULL;
302 mpt_stdload(struct mpt_personality *pers)
304 /* Load is always successfull. */
309 mpt_stdprobe(struct mpt_softc *mpt)
311 /* Probe is always successfull. */
316 mpt_stdattach(struct mpt_softc *mpt)
318 /* Attach is always successfull. */
323 mpt_stdenable(struct mpt_softc *mpt)
325 /* Enable is always successfull. */
330 mpt_stdready(struct mpt_softc *mpt)
336 mpt_stdevent(struct mpt_softc *mpt, request_t *req, MSG_EVENT_NOTIFY_REPLY *msg)
338 mpt_lprt(mpt, MPT_PRT_DEBUG, "mpt_stdevent: 0x%x\n",
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 (unsigned)msg->Event,
564 msg->AckRequired? "r" : "not r");
565 } else if (handled == 0) {
567 msg->AckRequired? MPT_PRT_WARN : MPT_PRT_INFO,
568 "Unhandled Event Notify Frame. Event %#x "
569 "(ACK %sequired).\n",
570 (unsigned)msg->Event,
571 msg->AckRequired? "r" : "not r");
574 if (msg->AckRequired) {
578 context = req->index | MPT_REPLY_HANDLER_EVENTS;
579 ack_req = mpt_get_request(mpt, FALSE);
580 if (ack_req == NULL) {
581 struct mpt_evtf_record *evtf;
583 evtf = (struct mpt_evtf_record *)reply_frame;
584 evtf->context = context;
585 LIST_INSERT_HEAD(&mpt->ack_frames, evtf, links);
589 mpt_send_event_ack(mpt, ack_req, msg, context);
591 * Don't check for CONTINUATION_REPLY here
597 case MPI_FUNCTION_PORT_ENABLE:
598 mpt_lprt(mpt, MPT_PRT_DEBUG , "enable port reply\n");
600 case MPI_FUNCTION_EVENT_ACK:
603 mpt_prt(mpt, "unknown event function: %x\n",
604 reply_frame->Function);
609 * I'm not sure that this continuation stuff works as it should.
611 * I've had FC async events occur that free the frame up because
612 * the continuation bit isn't set, and then additional async events
613 * then occur using the same context. As you might imagine, this
614 * leads to Very Bad Thing.
616 * Let's just be safe for now and not free them up until we figure
617 * out what's actually happening here.
620 if ((reply_frame->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY) == 0) {
621 TAILQ_REMOVE(&mpt->request_pending_list, req, links);
622 mpt_free_request(mpt, req);
623 mpt_prt(mpt, "event_reply %x for req %p:%u NOT a continuation",
624 reply_frame->Function, req, req->serno);
625 if (reply_frame->Function == MPI_FUNCTION_EVENT_NOTIFICATION) {
626 MSG_EVENT_NOTIFY_REPLY *msg =
627 (MSG_EVENT_NOTIFY_REPLY *)reply_frame;
628 mpt_prtc(mpt, " Event=0x%x AckReq=%d",
629 msg->Event, msg->AckRequired);
632 mpt_prt(mpt, "event_reply %x for %p:%u IS a continuation",
633 reply_frame->Function, req, req->serno);
634 if (reply_frame->Function == MPI_FUNCTION_EVENT_NOTIFICATION) {
635 MSG_EVENT_NOTIFY_REPLY *msg =
636 (MSG_EVENT_NOTIFY_REPLY *)reply_frame;
637 mpt_prtc(mpt, " Event=0x%x AckReq=%d",
638 msg->Event, msg->AckRequired);
647 * Process an asynchronous event from the IOC.
650 mpt_core_event(struct mpt_softc *mpt, request_t *req,
651 MSG_EVENT_NOTIFY_REPLY *msg)
653 mpt_lprt(mpt, MPT_PRT_DEBUG, "mpt_core_event: 0x%x\n",
654 (unsigned)(msg->Event & 0xFF));
655 switch(msg->Event & 0xFF) {
658 case MPI_EVENT_LOG_DATA:
662 /* Some error occured that LSI wants logged */
663 mpt_prt(mpt, "EvtLogData: IOCLogInfo: 0x%08x\n",
664 (unsigned)msg->IOCLogInfo);
665 mpt_prt(mpt, "\tEvtLogData: Event Data:");
666 for (i = 0; i < msg->EventDataLength; i++)
667 mpt_prtc(mpt, " %08x", (unsigned)msg->Data[i]);
671 case MPI_EVENT_EVENT_CHANGE:
673 * This is just an acknowledgement
674 * of our mpt_send_event_request.
677 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
687 mpt_send_event_ack(struct mpt_softc *mpt, request_t *ack_req,
688 MSG_EVENT_NOTIFY_REPLY *msg, uint32_t context)
692 ackp = (MSG_EVENT_ACK *)ack_req->req_vbuf;
693 memset(ackp, 0, sizeof (*ackp));
694 ackp->Function = MPI_FUNCTION_EVENT_ACK;
695 ackp->Event = htole32(msg->Event);
696 ackp->EventContext = htole32(msg->EventContext);
697 ackp->MsgContext = htole32(context);
698 mpt_check_doorbell(mpt);
699 mpt_send_cmd(mpt, ack_req);
702 /***************************** Interrupt Handling *****************************/
706 struct mpt_softc *mpt;
710 mpt = (struct mpt_softc *)arg;
711 mpt_lprt(mpt, MPT_PRT_DEBUG2, "enter mpt_intr\n");
712 MPT_LOCK_ASSERT(mpt);
714 while ((reply_desc = mpt_pop_reply_queue(mpt)) != MPT_REPLY_EMPTY) {
716 MSG_DEFAULT_REPLY *reply_frame;
717 uint32_t reply_baddr;
726 if ((reply_desc & MPI_ADDRESS_REPLY_A_BIT) != 0) {
729 * Insure that the reply frame is coherent.
731 reply_baddr = MPT_REPLY_BADDR(reply_desc);
732 offset = reply_baddr - (mpt->reply_phys & 0xFFFFFFFF);
733 bus_dmamap_sync_range(mpt->reply_dmat,
734 mpt->reply_dmap, offset, MPT_REPLY_SIZE,
735 BUS_DMASYNC_POSTREAD);
736 reply_frame = MPT_REPLY_OTOV(mpt, offset);
737 ctxt_idx = le32toh(reply_frame->MsgContext);
741 type = MPI_GET_CONTEXT_REPLY_TYPE(reply_desc);
742 ctxt_idx = reply_desc;
743 mpt_lprt(mpt, MPT_PRT_DEBUG1, "Context Reply: 0x%08x\n",
747 case MPI_CONTEXT_REPLY_TYPE_SCSI_INIT:
748 ctxt_idx &= MPI_CONTEXT_REPLY_CONTEXT_MASK;
750 case MPI_CONTEXT_REPLY_TYPE_SCSI_TARGET:
751 ctxt_idx = GET_IO_INDEX(reply_desc);
752 if (mpt->tgt_cmd_ptrs == NULL) {
754 "mpt_intr: no target cmd ptrs\n");
755 reply_desc = MPT_REPLY_EMPTY;
758 if (ctxt_idx >= mpt->tgt_cmds_allocated) {
760 "mpt_intr: bad tgt cmd ctxt %u\n",
762 reply_desc = MPT_REPLY_EMPTY;
766 req = mpt->tgt_cmd_ptrs[ctxt_idx];
768 mpt_prt(mpt, "no request backpointer "
769 "at index %u", ctxt_idx);
770 reply_desc = MPT_REPLY_EMPTY;
775 * Reformulate ctxt_idx to be just as if
776 * it were another type of context reply
777 * so the code below will find the request
778 * via indexing into the pool.
781 req->index | mpt->scsi_tgt_handler_id;
784 case MPI_CONTEXT_REPLY_TYPE_LAN:
785 mpt_prt(mpt, "LAN CONTEXT REPLY: 0x%08x\n",
787 reply_desc = MPT_REPLY_EMPTY;
790 mpt_prt(mpt, "Context Reply 0x%08x?\n", type);
791 reply_desc = MPT_REPLY_EMPTY;
794 if (reply_desc == MPT_REPLY_EMPTY) {
795 if (ntrips++ > 1000) {
802 cb_index = MPT_CONTEXT_TO_CBI(ctxt_idx);
803 req_index = MPT_CONTEXT_TO_REQI(ctxt_idx);
804 if (req_index < MPT_MAX_REQUESTS(mpt)) {
805 req = &mpt->request_pool[req_index];
807 mpt_prt(mpt, "WARN: mpt_intr index == %d (reply_desc =="
808 " 0x%x)\n", req_index, reply_desc);
811 free_rf = mpt_reply_handlers[cb_index](mpt, req,
812 reply_desc, reply_frame);
814 if (reply_frame != NULL && free_rf) {
815 mpt_free_reply(mpt, reply_baddr);
819 * If we got ourselves disabled, don't get stuck in a loop
822 mpt_disable_ints(mpt);
825 if (ntrips++ > 1000) {
829 mpt_lprt(mpt, MPT_PRT_DEBUG2, "exit mpt_intr\n");
832 /******************************* Error Recovery *******************************/
834 mpt_complete_request_chain(struct mpt_softc *mpt, struct req_queue *chain,
837 MSG_DEFAULT_REPLY ioc_status_frame;
840 memset(&ioc_status_frame, 0, sizeof(ioc_status_frame));
841 ioc_status_frame.MsgLength = roundup2(sizeof(ioc_status_frame), 4);
842 ioc_status_frame.IOCStatus = iocstatus;
843 while((req = TAILQ_FIRST(chain)) != NULL) {
844 MSG_REQUEST_HEADER *msg_hdr;
847 TAILQ_REMOVE(chain, req, links);
848 msg_hdr = (MSG_REQUEST_HEADER *)req->req_vbuf;
849 ioc_status_frame.Function = msg_hdr->Function;
850 ioc_status_frame.MsgContext = msg_hdr->MsgContext;
851 cb_index = MPT_CONTEXT_TO_CBI(le32toh(msg_hdr->MsgContext));
852 mpt_reply_handlers[cb_index](mpt, req, msg_hdr->MsgContext,
857 /********************************* Diagnostics ********************************/
859 * Perform a diagnostic dump of a reply frame.
862 mpt_dump_reply_frame(struct mpt_softc *mpt, MSG_DEFAULT_REPLY *reply_frame)
864 mpt_prt(mpt, "Address Reply:\n");
865 mpt_print_reply(reply_frame);
868 /******************************* Doorbell Access ******************************/
869 static __inline uint32_t mpt_rd_db(struct mpt_softc *mpt);
870 static __inline uint32_t mpt_rd_intr(struct mpt_softc *mpt);
872 static __inline uint32_t
873 mpt_rd_db(struct mpt_softc *mpt)
875 return mpt_read(mpt, MPT_OFFSET_DOORBELL);
878 static __inline uint32_t
879 mpt_rd_intr(struct mpt_softc *mpt)
881 return mpt_read(mpt, MPT_OFFSET_INTR_STATUS);
884 /* Busy wait for a door bell to be read by IOC */
886 mpt_wait_db_ack(struct mpt_softc *mpt)
889 for (i=0; i < MPT_MAX_WAIT; i++) {
890 if (!MPT_DB_IS_BUSY(mpt_rd_intr(mpt))) {
891 maxwait_ack = i > maxwait_ack ? i : maxwait_ack;
899 /* Busy wait for a door bell interrupt */
901 mpt_wait_db_int(struct mpt_softc *mpt)
904 for (i = 0; i < MPT_MAX_WAIT; i++) {
905 if (MPT_DB_INTR(mpt_rd_intr(mpt))) {
906 maxwait_int = i > maxwait_int ? i : maxwait_int;
914 /* Wait for IOC to transition to a give state */
916 mpt_check_doorbell(struct mpt_softc *mpt)
918 uint32_t db = mpt_rd_db(mpt);
919 if (MPT_STATE(db) != MPT_DB_STATE_RUNNING) {
920 mpt_prt(mpt, "Device not running\n");
925 /* Wait for IOC to transition to a give state */
927 mpt_wait_state(struct mpt_softc *mpt, enum DB_STATE_BITS state)
931 for (i = 0; i < MPT_MAX_WAIT; i++) {
932 uint32_t db = mpt_rd_db(mpt);
933 if (MPT_STATE(db) == state) {
934 maxwait_state = i > maxwait_state ? i : maxwait_state;
943 /************************* Intialization/Configuration ************************/
944 static int mpt_download_fw(struct mpt_softc *mpt);
946 /* Issue the reset COMMAND to the IOC */
948 mpt_soft_reset(struct mpt_softc *mpt)
950 mpt_lprt(mpt, MPT_PRT_DEBUG, "soft reset\n");
952 /* Have to use hard reset if we are not in Running state */
953 if (MPT_STATE(mpt_rd_db(mpt)) != MPT_DB_STATE_RUNNING) {
954 mpt_prt(mpt, "soft reset failed: device not running\n");
958 /* If door bell is in use we don't have a chance of getting
959 * a word in since the IOC probably crashed in message
960 * processing. So don't waste our time.
962 if (MPT_DB_IS_IN_USE(mpt_rd_db(mpt))) {
963 mpt_prt(mpt, "soft reset failed: doorbell wedged\n");
967 /* Send the reset request to the IOC */
968 mpt_write(mpt, MPT_OFFSET_DOORBELL,
969 MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET << MPI_DOORBELL_FUNCTION_SHIFT);
970 if (mpt_wait_db_ack(mpt) != MPT_OK) {
971 mpt_prt(mpt, "soft reset failed: ack timeout\n");
975 /* Wait for the IOC to reload and come out of reset state */
976 if (mpt_wait_state(mpt, MPT_DB_STATE_READY) != MPT_OK) {
977 mpt_prt(mpt, "soft reset failed: device did not restart\n");
985 mpt_enable_diag_mode(struct mpt_softc *mpt)
992 if ((mpt_read(mpt, MPT_OFFSET_DIAGNOSTIC) & MPI_DIAG_DRWE) != 0)
995 /* Enable diagnostic registers */
996 mpt_write(mpt, MPT_OFFSET_SEQUENCE, 0xFF);
997 mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_1ST_KEY_VALUE);
998 mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_2ND_KEY_VALUE);
999 mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_3RD_KEY_VALUE);
1000 mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_4TH_KEY_VALUE);
1001 mpt_write(mpt, MPT_OFFSET_SEQUENCE, MPI_WRSEQ_5TH_KEY_VALUE);
1011 mpt_disable_diag_mode(struct mpt_softc *mpt)
1013 mpt_write(mpt, MPT_OFFSET_SEQUENCE, 0xFFFFFFFF);
1016 /* This is a magic diagnostic reset that resets all the ARM
1017 * processors in the chip.
1020 mpt_hard_reset(struct mpt_softc *mpt)
1026 mpt_lprt(mpt, MPT_PRT_DEBUG, "hard reset\n");
1028 error = mpt_enable_diag_mode(mpt);
1030 mpt_prt(mpt, "WARNING - Could not enter diagnostic mode !\n");
1031 mpt_prt(mpt, "Trying to reset anyway.\n");
1034 diagreg = mpt_read(mpt, MPT_OFFSET_DIAGNOSTIC);
1037 * This appears to be a workaround required for some
1038 * firmware or hardware revs.
1040 mpt_write(mpt, MPT_OFFSET_DIAGNOSTIC, diagreg | MPI_DIAG_DISABLE_ARM);
1043 /* Diag. port is now active so we can now hit the reset bit */
1044 mpt_write(mpt, MPT_OFFSET_DIAGNOSTIC, diagreg | MPI_DIAG_RESET_ADAPTER);
1047 * Ensure that the reset has finished. We delay 1ms
1048 * prior to reading the register to make sure the chip
1049 * has sufficiently completed its reset to handle register
1055 diagreg = mpt_read(mpt, MPT_OFFSET_DIAGNOSTIC);
1056 } while (--wait && (diagreg & MPI_DIAG_RESET_ADAPTER) == 0);
1059 mpt_prt(mpt, "WARNING - Failed hard reset! "
1060 "Trying to initialize anyway.\n");
1064 * If we have firmware to download, it must be loaded before
1065 * the controller will become operational. Do so now.
1067 if (mpt->fw_image != NULL) {
1069 error = mpt_download_fw(mpt);
1072 mpt_prt(mpt, "WARNING - Firmware Download Failed!\n");
1073 mpt_prt(mpt, "Trying to initialize anyway.\n");
1078 * Reseting the controller should have disabled write
1079 * access to the diagnostic registers, but disable
1080 * manually to be sure.
1082 mpt_disable_diag_mode(mpt);
1086 mpt_core_ioc_reset(struct mpt_softc *mpt, int type)
1089 * Complete all pending requests with a status
1090 * appropriate for an IOC reset.
1092 mpt_complete_request_chain(mpt, &mpt->request_pending_list,
1093 MPI_IOCSTATUS_INVALID_STATE);
1098 * Reset the IOC when needed. Try software command first then if needed
1099 * poke at the magic diagnostic reset. Note that a hard reset resets
1100 * *both* IOCs on dual function chips (FC929 && LSI1030) as well as
1101 * fouls up the PCI configuration registers.
1104 mpt_reset(struct mpt_softc *mpt, int reinit)
1106 struct mpt_personality *pers;
1111 * Try a soft reset. If that fails, get out the big hammer.
1114 if ((ret = mpt_soft_reset(mpt)) != MPT_OK) {
1116 for (cnt = 0; cnt < 5; cnt++) {
1117 /* Failed; do a hard reset */
1118 mpt_hard_reset(mpt);
1121 * Wait for the IOC to reload
1122 * and come out of reset state
1124 ret = mpt_wait_state(mpt, MPT_DB_STATE_READY);
1125 if (ret == MPT_OK) {
1129 * Okay- try to check again...
1131 ret = mpt_wait_state(mpt, MPT_DB_STATE_READY);
1132 if (ret == MPT_OK) {
1135 mpt_prt(mpt, "mpt_reset: failed hard reset (%d:%d)\n",
1140 if (retry_cnt == 0) {
1142 * Invoke reset handlers. We bump the reset count so
1143 * that mpt_wait_req() understands that regardless of
1144 * the specified wait condition, it should stop its wait.
1147 MPT_PERS_FOREACH(mpt, pers)
1148 pers->reset(mpt, ret);
1152 ret = mpt_enable_ioc(mpt, 1);
1153 if (ret == MPT_OK) {
1154 mpt_enable_ints(mpt);
1157 if (ret != MPT_OK && retry_cnt++ < 2) {
1163 /* Return a command buffer to the free queue */
1165 mpt_free_request(struct mpt_softc *mpt, request_t *req)
1168 struct mpt_evtf_record *record;
1169 uint32_t reply_baddr;
1171 if (req == NULL || req != &mpt->request_pool[req->index]) {
1172 panic("mpt_free_request bad req ptr\n");
1175 if ((nxt = req->chain) != NULL) {
1177 mpt_free_request(mpt, nxt); /* NB: recursion */
1179 KASSERT(req->state != REQ_STATE_FREE, ("freeing free request"));
1180 KASSERT(!(req->state & REQ_STATE_LOCKED), ("freeing locked request"));
1181 MPT_LOCK_ASSERT(mpt);
1182 KASSERT(mpt_req_on_free_list(mpt, req) == 0,
1183 ("mpt_free_request: req %p:%u func %x already on freelist",
1184 req, req->serno, ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function));
1185 KASSERT(mpt_req_on_pending_list(mpt, req) == 0,
1186 ("mpt_free_request: req %p:%u func %x on pending list",
1187 req, req->serno, ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function));
1189 mpt_req_not_spcl(mpt, req, "mpt_free_request", __LINE__);
1193 if (LIST_EMPTY(&mpt->ack_frames)) {
1195 * Insert free ones at the tail
1198 req->state = REQ_STATE_FREE;
1200 memset(req->req_vbuf, 0xff, sizeof (MSG_REQUEST_HEADER));
1202 TAILQ_INSERT_TAIL(&mpt->request_free_list, req, links);
1203 if (mpt->getreqwaiter != 0) {
1204 mpt->getreqwaiter = 0;
1205 wakeup(&mpt->request_free_list);
1211 * Process an ack frame deferred due to resource shortage.
1213 record = LIST_FIRST(&mpt->ack_frames);
1214 LIST_REMOVE(record, links);
1215 req->state = REQ_STATE_ALLOCATED;
1216 mpt_assign_serno(mpt, req);
1217 mpt_send_event_ack(mpt, req, &record->reply, record->context);
1218 reply_baddr = (uint32_t)((uint8_t *)record - mpt->reply)
1219 + (mpt->reply_phys & 0xFFFFFFFF);
1220 mpt_free_reply(mpt, reply_baddr);
1223 /* Get a command buffer from the free queue */
1225 mpt_get_request(struct mpt_softc *mpt, int sleep_ok)
1230 MPT_LOCK_ASSERT(mpt);
1231 req = TAILQ_FIRST(&mpt->request_free_list);
1233 KASSERT(req == &mpt->request_pool[req->index],
1234 ("mpt_get_request: corrupted request free list\n"));
1235 KASSERT(req->state == REQ_STATE_FREE,
1236 ("req %p:%u not free on free list %x index %d function %x",
1237 req, req->serno, req->state, req->index,
1238 ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function));
1239 TAILQ_REMOVE(&mpt->request_free_list, req, links);
1240 req->state = REQ_STATE_ALLOCATED;
1242 mpt_assign_serno(mpt, req);
1243 mpt_callout_init(&req->callout);
1244 } else if (sleep_ok != 0) {
1245 mpt->getreqwaiter = 1;
1246 mpt_sleep(mpt, &mpt->request_free_list, PUSER, "mptgreq", 0);
1252 /* Pass the command to the IOC */
1254 mpt_send_cmd(struct mpt_softc *mpt, request_t *req)
1256 if (mpt->verbose > MPT_PRT_DEBUG2) {
1257 mpt_dump_request(mpt, req);
1259 bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap,
1260 BUS_DMASYNC_PREWRITE);
1261 req->state |= REQ_STATE_QUEUED;
1262 KASSERT(mpt_req_on_free_list(mpt, req) == 0,
1263 ("req %p:%u func %x on freelist list in mpt_send_cmd",
1264 req, req->serno, ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function));
1265 KASSERT(mpt_req_on_pending_list(mpt, req) == 0,
1266 ("req %p:%u func %x already on pending list in mpt_send_cmd",
1267 req, req->serno, ((MSG_REQUEST_HEADER *)req->req_vbuf)->Function));
1268 TAILQ_INSERT_HEAD(&mpt->request_pending_list, req, links);
1269 mpt_write(mpt, MPT_OFFSET_REQUEST_Q, (uint32_t) req->req_pbuf);
1273 * Wait for a request to complete.
1276 * mpt softc of controller executing request
1277 * req request to wait for
1278 * sleep_ok nonzero implies may sleep in this context
1279 * time_ms timeout in ms. 0 implies no timeout.
1282 * 0 Request completed
1283 * non-0 Timeout fired before request completion.
1286 mpt_wait_req(struct mpt_softc *mpt, request_t *req,
1287 mpt_req_state_t state, mpt_req_state_t mask,
1288 int sleep_ok, int time_ms)
1295 * timeout is in ms. 0 indicates infinite wait.
1296 * Convert to ticks or 500us units depending on
1299 if (sleep_ok != 0) {
1300 timeout = (time_ms * hz) / 1000;
1302 timeout = time_ms * 2;
1304 req->state |= REQ_STATE_NEED_WAKEUP;
1305 mask &= ~REQ_STATE_NEED_WAKEUP;
1306 saved_cnt = mpt->reset_cnt;
1307 while ((req->state & mask) != state && mpt->reset_cnt == saved_cnt) {
1308 if (sleep_ok != 0) {
1309 error = mpt_sleep(mpt, req, PUSER, "mptreq", timeout);
1310 if (error == EWOULDBLOCK) {
1315 if (time_ms != 0 && --timeout == 0) {
1322 req->state &= ~REQ_STATE_NEED_WAKEUP;
1323 if (mpt->reset_cnt != saved_cnt) {
1326 if (time_ms && timeout <= 0) {
1327 MSG_REQUEST_HEADER *msg_hdr = req->req_vbuf;
1328 req->state |= REQ_STATE_TIMEDOUT;
1329 mpt_prt(mpt, "mpt_wait_req(%x) timed out\n", msg_hdr->Function);
1336 * Send a command to the IOC via the handshake register.
1338 * Only done at initialization time and for certain unusual
1339 * commands such as device/bus reset as specified by LSI.
1342 mpt_send_handshake_cmd(struct mpt_softc *mpt, size_t len, void *cmd)
1345 uint32_t data, *data32;
1347 /* Check condition of the IOC */
1348 data = mpt_rd_db(mpt);
1349 if ((MPT_STATE(data) != MPT_DB_STATE_READY
1350 && MPT_STATE(data) != MPT_DB_STATE_RUNNING
1351 && MPT_STATE(data) != MPT_DB_STATE_FAULT)
1352 || MPT_DB_IS_IN_USE(data)) {
1353 mpt_prt(mpt, "handshake aborted - invalid doorbell state\n");
1358 /* We move things in 32 bit chunks */
1359 len = (len + 3) >> 2;
1362 /* Clear any left over pending doorbell interrupts */
1363 if (MPT_DB_INTR(mpt_rd_intr(mpt)))
1364 mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0);
1367 * Tell the handshake reg. we are going to send a command
1368 * and how long it is going to be.
1370 data = (MPI_FUNCTION_HANDSHAKE << MPI_DOORBELL_FUNCTION_SHIFT) |
1371 (len << MPI_DOORBELL_ADD_DWORDS_SHIFT);
1372 mpt_write(mpt, MPT_OFFSET_DOORBELL, data);
1374 /* Wait for the chip to notice */
1375 if (mpt_wait_db_int(mpt) != MPT_OK) {
1376 mpt_prt(mpt, "mpt_send_handshake_cmd: db ignored\n");
1380 /* Clear the interrupt */
1381 mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0);
1383 if (mpt_wait_db_ack(mpt) != MPT_OK) {
1384 mpt_prt(mpt, "mpt_send_handshake_cmd: db ack timed out\n");
1388 /* Send the command */
1389 for (i = 0; i < len; i++) {
1390 mpt_write(mpt, MPT_OFFSET_DOORBELL, htole32(*data32++));
1391 if (mpt_wait_db_ack(mpt) != MPT_OK) {
1393 "mpt_send_handshake_cmd: timeout @ index %d\n", i);
1400 /* Get the response from the handshake register */
1402 mpt_recv_handshake_reply(struct mpt_softc *mpt, size_t reply_len, void *reply)
1404 int left, reply_left;
1407 MSG_DEFAULT_REPLY *hdr;
1409 /* We move things out in 16 bit chunks */
1411 data16 = (u_int16_t *)reply;
1413 hdr = (MSG_DEFAULT_REPLY *)reply;
1415 /* Get first word */
1416 if (mpt_wait_db_int(mpt) != MPT_OK) {
1417 mpt_prt(mpt, "mpt_recv_handshake_cmd timeout1\n");
1420 data = mpt_read(mpt, MPT_OFFSET_DOORBELL);
1421 *data16++ = le16toh(data & MPT_DB_DATA_MASK);
1422 mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0);
1424 /* Get Second Word */
1425 if (mpt_wait_db_int(mpt) != MPT_OK) {
1426 mpt_prt(mpt, "mpt_recv_handshake_cmd timeout2\n");
1429 data = mpt_read(mpt, MPT_OFFSET_DOORBELL);
1430 *data16++ = le16toh(data & MPT_DB_DATA_MASK);
1431 mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0);
1434 * With the second word, we can now look at the length.
1435 * Warn about a reply that's too short (except for IOC FACTS REPLY)
1437 if ((reply_len >> 1) != hdr->MsgLength &&
1438 (hdr->Function != MPI_FUNCTION_IOC_FACTS)){
1439 #if __FreeBSD_version >= 500000
1440 mpt_prt(mpt, "reply length does not match message length: "
1441 "got %x; expected %zx for function %x\n",
1442 hdr->MsgLength << 2, reply_len << 1, hdr->Function);
1444 mpt_prt(mpt, "reply length does not match message length: "
1445 "got %x; expected %zx for function %x\n",
1446 hdr->MsgLength << 2, reply_len << 1, hdr->Function);
1450 /* Get rest of the reply; but don't overflow the provided buffer */
1451 left = (hdr->MsgLength << 1) - 2;
1452 reply_left = reply_len - 2;
1456 if (mpt_wait_db_int(mpt) != MPT_OK) {
1457 mpt_prt(mpt, "mpt_recv_handshake_cmd timeout3\n");
1460 data = mpt_read(mpt, MPT_OFFSET_DOORBELL);
1461 datum = le16toh(data & MPT_DB_DATA_MASK);
1463 if (reply_left-- > 0)
1466 mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0);
1469 /* One more wait & clear at the end */
1470 if (mpt_wait_db_int(mpt) != MPT_OK) {
1471 mpt_prt(mpt, "mpt_recv_handshake_cmd timeout4\n");
1474 mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0);
1476 if ((hdr->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
1477 if (mpt->verbose >= MPT_PRT_TRACE)
1478 mpt_print_reply(hdr);
1479 return (MPT_FAIL | hdr->IOCStatus);
1486 mpt_get_iocfacts(struct mpt_softc *mpt, MSG_IOC_FACTS_REPLY *freplp)
1488 MSG_IOC_FACTS f_req;
1491 memset(&f_req, 0, sizeof f_req);
1492 f_req.Function = MPI_FUNCTION_IOC_FACTS;
1493 f_req.MsgContext = htole32(MPT_REPLY_HANDLER_HANDSHAKE);
1494 error = mpt_send_handshake_cmd(mpt, sizeof f_req, &f_req);
1498 error = mpt_recv_handshake_reply(mpt, sizeof (*freplp), freplp);
1503 mpt_get_portfacts(struct mpt_softc *mpt, U8 port, MSG_PORT_FACTS_REPLY *freplp)
1505 MSG_PORT_FACTS f_req;
1508 memset(&f_req, 0, sizeof f_req);
1509 f_req.Function = MPI_FUNCTION_PORT_FACTS;
1510 f_req.PortNumber = port;
1511 f_req.MsgContext = htole32(MPT_REPLY_HANDLER_HANDSHAKE);
1512 error = mpt_send_handshake_cmd(mpt, sizeof f_req, &f_req);
1516 error = mpt_recv_handshake_reply(mpt, sizeof (*freplp), freplp);
1521 * Send the initialization request. This is where we specify how many
1522 * SCSI busses and how many devices per bus we wish to emulate.
1523 * This is also the command that specifies the max size of the reply
1524 * frames from the IOC that we will be allocating.
1527 mpt_send_ioc_init(struct mpt_softc *mpt, uint32_t who)
1531 MSG_IOC_INIT_REPLY reply;
1533 memset(&init, 0, sizeof init);
1535 init.Function = MPI_FUNCTION_IOC_INIT;
1536 init.MaxDevices = 0; /* at least 256 devices per bus */
1537 init.MaxBuses = 16; /* at least 16 busses */
1539 init.MsgVersion = htole16(MPI_VERSION);
1540 init.HeaderVersion = htole16(MPI_HEADER_VERSION);
1541 init.ReplyFrameSize = htole16(MPT_REPLY_SIZE);
1542 init.MsgContext = htole32(MPT_REPLY_HANDLER_HANDSHAKE);
1544 if ((error = mpt_send_handshake_cmd(mpt, sizeof init, &init)) != 0) {
1548 error = mpt_recv_handshake_reply(mpt, sizeof reply, &reply);
1554 * Utiltity routine to read configuration headers and pages
1557 mpt_issue_cfg_req(struct mpt_softc *mpt, request_t *req, cfgparms_t *params,
1558 bus_addr_t addr, bus_size_t len, int sleep_ok, int timeout_ms)
1563 cfgp = req->req_vbuf;
1564 memset(cfgp, 0, sizeof *cfgp);
1565 cfgp->Action = params->Action;
1566 cfgp->Function = MPI_FUNCTION_CONFIG;
1567 cfgp->Header.PageVersion = params->PageVersion;
1568 cfgp->Header.PageNumber = params->PageNumber;
1569 cfgp->PageAddress = htole32(params->PageAddress);
1570 if ((params->PageType & MPI_CONFIG_PAGETYPE_MASK) ==
1571 MPI_CONFIG_PAGETYPE_EXTENDED) {
1572 cfgp->Header.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1573 cfgp->Header.PageLength = 0;
1574 cfgp->ExtPageLength = htole16(params->ExtPageLength);
1575 cfgp->ExtPageType = params->ExtPageType;
1577 cfgp->Header.PageType = params->PageType;
1578 cfgp->Header.PageLength = params->PageLength;
1580 se = (SGE_SIMPLE32 *)&cfgp->PageBufferSGE;
1581 se->Address = htole32(addr);
1582 MPI_pSGE_SET_LENGTH(se, len);
1583 MPI_pSGE_SET_FLAGS(se, (MPI_SGE_FLAGS_SIMPLE_ELEMENT |
1584 MPI_SGE_FLAGS_LAST_ELEMENT | MPI_SGE_FLAGS_END_OF_BUFFER |
1585 MPI_SGE_FLAGS_END_OF_LIST |
1586 ((params->Action == MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT
1587 || params->Action == MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM)
1588 ? MPI_SGE_FLAGS_HOST_TO_IOC : MPI_SGE_FLAGS_IOC_TO_HOST)));
1589 se->FlagsLength = htole32(se->FlagsLength);
1590 cfgp->MsgContext = htole32(req->index | MPT_REPLY_HANDLER_CONFIG);
1592 mpt_check_doorbell(mpt);
1593 mpt_send_cmd(mpt, req);
1594 return (mpt_wait_req(mpt, req, REQ_STATE_DONE, REQ_STATE_DONE,
1595 sleep_ok, timeout_ms));
1599 mpt_read_extcfg_header(struct mpt_softc *mpt, int PageVersion, int PageNumber,
1600 uint32_t PageAddress, int ExtPageType,
1601 CONFIG_EXTENDED_PAGE_HEADER *rslt,
1602 int sleep_ok, int timeout_ms)
1606 MSG_CONFIG_REPLY *cfgp;
1609 req = mpt_get_request(mpt, sleep_ok);
1611 mpt_prt(mpt, "mpt_extread_cfg_header: Get request failed!\n");
1615 params.Action = MPI_CONFIG_ACTION_PAGE_HEADER;
1616 params.PageVersion = PageVersion;
1617 params.PageLength = 0;
1618 params.PageNumber = PageNumber;
1619 params.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1620 params.PageAddress = PageAddress;
1621 params.ExtPageType = ExtPageType;
1622 params.ExtPageLength = 0;
1623 error = mpt_issue_cfg_req(mpt, req, ¶ms, /*addr*/0, /*len*/0,
1624 sleep_ok, timeout_ms);
1627 * Leave the request. Without resetting the chip, it's
1628 * still owned by it and we'll just get into trouble
1629 * freeing it now. Mark it as abandoned so that if it
1630 * shows up later it can be freed.
1632 mpt_prt(mpt, "read_extcfg_header timed out\n");
1636 switch (req->IOCStatus & MPI_IOCSTATUS_MASK) {
1637 case MPI_IOCSTATUS_SUCCESS:
1638 cfgp = req->req_vbuf;
1639 rslt->PageVersion = cfgp->Header.PageVersion;
1640 rslt->PageNumber = cfgp->Header.PageNumber;
1641 rslt->PageType = cfgp->Header.PageType;
1642 rslt->ExtPageLength = le16toh(cfgp->ExtPageLength);
1643 rslt->ExtPageType = cfgp->ExtPageType;
1646 case MPI_IOCSTATUS_CONFIG_INVALID_PAGE:
1647 mpt_lprt(mpt, MPT_PRT_DEBUG,
1648 "Invalid Page Type %d Number %d Addr 0x%0x\n",
1649 MPI_CONFIG_PAGETYPE_EXTENDED, PageNumber, PageAddress);
1653 mpt_prt(mpt, "mpt_read_extcfg_header: Config Info Status %x\n",
1658 mpt_free_request(mpt, req);
1663 mpt_read_extcfg_page(struct mpt_softc *mpt, int Action, uint32_t PageAddress,
1664 CONFIG_EXTENDED_PAGE_HEADER *hdr, void *buf, size_t len,
1665 int sleep_ok, int timeout_ms)
1671 req = mpt_get_request(mpt, sleep_ok);
1673 mpt_prt(mpt, "mpt_read_extcfg_page: Get request failed!\n");
1677 params.Action = Action;
1678 params.PageVersion = hdr->PageVersion;
1679 params.PageLength = 0;
1680 params.PageNumber = hdr->PageNumber;
1681 params.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
1682 params.PageAddress = PageAddress;
1683 params.ExtPageType = hdr->ExtPageType;
1684 params.ExtPageLength = hdr->ExtPageLength;
1685 error = mpt_issue_cfg_req(mpt, req, ¶ms,
1686 req->req_pbuf + MPT_RQSL(mpt),
1687 len, sleep_ok, timeout_ms);
1689 mpt_prt(mpt, "read_extcfg_page(%d) timed out\n", Action);
1693 if ((req->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
1694 mpt_prt(mpt, "mpt_read_extcfg_page: Config Info Status %x\n",
1696 mpt_free_request(mpt, req);
1699 bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap,
1700 BUS_DMASYNC_POSTREAD);
1701 memcpy(buf, ((uint8_t *)req->req_vbuf)+MPT_RQSL(mpt), len);
1702 mpt_free_request(mpt, req);
1707 mpt_read_cfg_header(struct mpt_softc *mpt, int PageType, int PageNumber,
1708 uint32_t PageAddress, CONFIG_PAGE_HEADER *rslt,
1709 int sleep_ok, int timeout_ms)
1716 req = mpt_get_request(mpt, sleep_ok);
1718 mpt_prt(mpt, "mpt_read_cfg_header: Get request failed!\n");
1722 params.Action = MPI_CONFIG_ACTION_PAGE_HEADER;
1723 params.PageVersion = 0;
1724 params.PageLength = 0;
1725 params.PageNumber = PageNumber;
1726 params.PageType = PageType;
1727 params.PageAddress = PageAddress;
1728 error = mpt_issue_cfg_req(mpt, req, ¶ms, /*addr*/0, /*len*/0,
1729 sleep_ok, timeout_ms);
1732 * Leave the request. Without resetting the chip, it's
1733 * still owned by it and we'll just get into trouble
1734 * freeing it now. Mark it as abandoned so that if it
1735 * shows up later it can be freed.
1737 mpt_prt(mpt, "read_cfg_header timed out\n");
1741 switch (req->IOCStatus & MPI_IOCSTATUS_MASK) {
1742 case MPI_IOCSTATUS_SUCCESS:
1743 cfgp = req->req_vbuf;
1744 bcopy(&cfgp->Header, rslt, sizeof(*rslt));
1747 case MPI_IOCSTATUS_CONFIG_INVALID_PAGE:
1748 mpt_lprt(mpt, MPT_PRT_DEBUG,
1749 "Invalid Page Type %d Number %d Addr 0x%0x\n",
1750 PageType, PageNumber, PageAddress);
1754 mpt_prt(mpt, "mpt_read_cfg_header: Config Info Status %x\n",
1759 mpt_free_request(mpt, req);
1764 mpt_read_cfg_page(struct mpt_softc *mpt, int Action, uint32_t PageAddress,
1765 CONFIG_PAGE_HEADER *hdr, size_t len, int sleep_ok,
1772 req = mpt_get_request(mpt, sleep_ok);
1774 mpt_prt(mpt, "mpt_read_cfg_page: Get request failed!\n");
1778 params.Action = Action;
1779 params.PageVersion = hdr->PageVersion;
1780 params.PageLength = hdr->PageLength;
1781 params.PageNumber = hdr->PageNumber;
1782 params.PageType = hdr->PageType & MPI_CONFIG_PAGETYPE_MASK;
1783 params.PageAddress = PageAddress;
1784 error = mpt_issue_cfg_req(mpt, req, ¶ms,
1785 req->req_pbuf + MPT_RQSL(mpt),
1786 len, sleep_ok, timeout_ms);
1788 mpt_prt(mpt, "read_cfg_page(%d) timed out\n", Action);
1792 if ((req->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
1793 mpt_prt(mpt, "mpt_read_cfg_page: Config Info Status %x\n",
1795 mpt_free_request(mpt, req);
1798 bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap,
1799 BUS_DMASYNC_POSTREAD);
1800 memcpy(hdr, ((uint8_t *)req->req_vbuf)+MPT_RQSL(mpt), len);
1801 mpt_free_request(mpt, req);
1806 mpt_write_cfg_page(struct mpt_softc *mpt, int Action, uint32_t PageAddress,
1807 CONFIG_PAGE_HEADER *hdr, size_t len, int sleep_ok,
1815 hdr_attr = hdr->PageType & MPI_CONFIG_PAGEATTR_MASK;
1816 if (hdr_attr != MPI_CONFIG_PAGEATTR_CHANGEABLE &&
1817 hdr_attr != MPI_CONFIG_PAGEATTR_PERSISTENT) {
1818 mpt_prt(mpt, "page type 0x%x not changeable\n",
1819 hdr->PageType & MPI_CONFIG_PAGETYPE_MASK);
1825 * We shouldn't mask off other bits here.
1827 hdr->PageType &= MPI_CONFIG_PAGETYPE_MASK;
1830 req = mpt_get_request(mpt, sleep_ok);
1834 memcpy(((caddr_t)req->req_vbuf) + MPT_RQSL(mpt), hdr, len);
1837 * There isn't any point in restoring stripped out attributes
1838 * if you then mask them going down to issue the request.
1841 params.Action = Action;
1842 params.PageVersion = hdr->PageVersion;
1843 params.PageLength = hdr->PageLength;
1844 params.PageNumber = hdr->PageNumber;
1845 params.PageAddress = PageAddress;
1847 /* Restore stripped out attributes */
1848 hdr->PageType |= hdr_attr;
1849 params.PageType = hdr->PageType & MPI_CONFIG_PAGETYPE_MASK;
1851 params.PageType = hdr->PageType;
1853 error = mpt_issue_cfg_req(mpt, req, ¶ms,
1854 req->req_pbuf + MPT_RQSL(mpt),
1855 len, sleep_ok, timeout_ms);
1857 mpt_prt(mpt, "mpt_write_cfg_page timed out\n");
1861 if ((req->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
1862 mpt_prt(mpt, "mpt_write_cfg_page: Config Info Status %x\n",
1864 mpt_free_request(mpt, req);
1867 mpt_free_request(mpt, req);
1872 * Read IOC configuration information
1875 mpt_read_config_info_ioc(struct mpt_softc *mpt)
1877 CONFIG_PAGE_HEADER hdr;
1878 struct mpt_raid_volume *mpt_raid;
1883 rv = mpt_read_cfg_header(mpt, MPI_CONFIG_PAGETYPE_IOC,
1884 2, 0, &hdr, FALSE, 5000);
1886 * If it's an invalid page, so what? Not a supported function....
1895 mpt_lprt(mpt, MPT_PRT_DEBUG,
1896 "IOC Page 2 Header: Version %x len %x PageNumber %x PageType %x\n",
1897 hdr.PageVersion, hdr.PageLength << 2,
1898 hdr.PageNumber, hdr.PageType);
1900 len = hdr.PageLength * sizeof(uint32_t);
1901 mpt->ioc_page2 = kmalloc(len, M_DEVBUF, M_NOWAIT | M_ZERO);
1902 if (mpt->ioc_page2 == NULL) {
1903 mpt_prt(mpt, "unable to allocate memory for IOC page 2\n");
1904 mpt_raid_free_mem(mpt);
1907 memcpy(&mpt->ioc_page2->Header, &hdr, sizeof(hdr));
1908 rv = mpt_read_cur_cfg_page(mpt, 0,
1909 &mpt->ioc_page2->Header, len, FALSE, 5000);
1911 mpt_prt(mpt, "failed to read IOC Page 2\n");
1912 mpt_raid_free_mem(mpt);
1915 mpt2host_config_page_ioc2(mpt->ioc_page2);
1917 if (mpt->ioc_page2->CapabilitiesFlags != 0) {
1920 mpt_prt(mpt, "Capabilities: (");
1921 for (mask = 1; mask != 0; mask <<= 1) {
1922 if ((mpt->ioc_page2->CapabilitiesFlags & mask) == 0) {
1926 case MPI_IOCPAGE2_CAP_FLAGS_IS_SUPPORT:
1927 mpt_prtc(mpt, " RAID-0");
1929 case MPI_IOCPAGE2_CAP_FLAGS_IME_SUPPORT:
1930 mpt_prtc(mpt, " RAID-1E");
1932 case MPI_IOCPAGE2_CAP_FLAGS_IM_SUPPORT:
1933 mpt_prtc(mpt, " RAID-1");
1935 case MPI_IOCPAGE2_CAP_FLAGS_SES_SUPPORT:
1936 mpt_prtc(mpt, " SES");
1938 case MPI_IOCPAGE2_CAP_FLAGS_SAFTE_SUPPORT:
1939 mpt_prtc(mpt, " SAFTE");
1941 case MPI_IOCPAGE2_CAP_FLAGS_CROSS_CHANNEL_SUPPORT:
1942 mpt_prtc(mpt, " Multi-Channel-Arrays");
1947 mpt_prtc(mpt, " )\n");
1948 if ((mpt->ioc_page2->CapabilitiesFlags
1949 & (MPI_IOCPAGE2_CAP_FLAGS_IS_SUPPORT
1950 | MPI_IOCPAGE2_CAP_FLAGS_IME_SUPPORT
1951 | MPI_IOCPAGE2_CAP_FLAGS_IM_SUPPORT)) != 0) {
1952 mpt_prt(mpt, "%d Active Volume%s(%d Max)\n",
1953 mpt->ioc_page2->NumActiveVolumes,
1954 mpt->ioc_page2->NumActiveVolumes != 1
1956 mpt->ioc_page2->MaxVolumes);
1957 mpt_prt(mpt, "%d Hidden Drive Member%s(%d Max)\n",
1958 mpt->ioc_page2->NumActivePhysDisks,
1959 mpt->ioc_page2->NumActivePhysDisks != 1
1961 mpt->ioc_page2->MaxPhysDisks);
1965 len = mpt->ioc_page2->MaxVolumes * sizeof(struct mpt_raid_volume);
1966 mpt->raid_volumes = kmalloc(len, M_DEVBUF, M_NOWAIT | M_ZERO);
1967 if (mpt->raid_volumes == NULL) {
1968 mpt_prt(mpt, "Could not allocate RAID volume data\n");
1969 mpt_raid_free_mem(mpt);
1974 * Copy critical data out of ioc_page2 so that we can
1975 * safely refresh the page without windows of unreliable
1978 mpt->raid_max_volumes = mpt->ioc_page2->MaxVolumes;
1980 len = sizeof(*mpt->raid_volumes->config_page) +
1981 (sizeof (RAID_VOL0_PHYS_DISK) * (mpt->ioc_page2->MaxPhysDisks - 1));
1982 for (i = 0; i < mpt->ioc_page2->MaxVolumes; i++) {
1983 mpt_raid = &mpt->raid_volumes[i];
1984 mpt_raid->config_page =
1985 kmalloc(len, M_DEVBUF, M_NOWAIT | M_ZERO);
1986 if (mpt_raid->config_page == NULL) {
1987 mpt_prt(mpt, "Could not allocate RAID page data\n");
1988 mpt_raid_free_mem(mpt);
1992 mpt->raid_page0_len = len;
1994 len = mpt->ioc_page2->MaxPhysDisks * sizeof(struct mpt_raid_disk);
1995 mpt->raid_disks = kmalloc(len, M_DEVBUF, M_NOWAIT | M_ZERO);
1996 if (mpt->raid_disks == NULL) {
1997 mpt_prt(mpt, "Could not allocate RAID disk data\n");
1998 mpt_raid_free_mem(mpt);
2001 mpt->raid_max_disks = mpt->ioc_page2->MaxPhysDisks;
2006 rv = mpt_read_cfg_header(mpt, MPI_CONFIG_PAGETYPE_IOC,
2007 3, 0, &hdr, FALSE, 5000);
2009 mpt_raid_free_mem(mpt);
2013 mpt_lprt(mpt, MPT_PRT_DEBUG, "IOC Page 3 Header: %x %x %x %x\n",
2014 hdr.PageVersion, hdr.PageLength, hdr.PageNumber, hdr.PageType);
2016 len = hdr.PageLength * sizeof(uint32_t);
2017 mpt->ioc_page3 = kmalloc(len, M_DEVBUF, M_NOWAIT | M_ZERO);
2018 if (mpt->ioc_page3 == NULL) {
2019 mpt_prt(mpt, "unable to allocate memory for IOC page 3\n");
2020 mpt_raid_free_mem(mpt);
2023 memcpy(&mpt->ioc_page3->Header, &hdr, sizeof(hdr));
2024 rv = mpt_read_cur_cfg_page(mpt, 0,
2025 &mpt->ioc_page3->Header, len, FALSE, 5000);
2027 mpt_raid_free_mem(mpt);
2030 mpt2host_config_page_ioc3(mpt->ioc_page3);
2031 mpt_raid_wakeup(mpt);
2039 mpt_send_port_enable(struct mpt_softc *mpt, int port)
2042 MSG_PORT_ENABLE *enable_req;
2045 req = mpt_get_request(mpt, /*sleep_ok*/FALSE);
2049 enable_req = req->req_vbuf;
2050 memset(enable_req, 0, MPT_RQSL(mpt));
2052 enable_req->Function = MPI_FUNCTION_PORT_ENABLE;
2053 enable_req->MsgContext = htole32(req->index | MPT_REPLY_HANDLER_CONFIG);
2054 enable_req->PortNumber = port;
2056 mpt_check_doorbell(mpt);
2057 mpt_lprt(mpt, MPT_PRT_DEBUG, "enabling port %d\n", port);
2059 mpt_send_cmd(mpt, req);
2060 error = mpt_wait_req(mpt, req, REQ_STATE_DONE, REQ_STATE_DONE,
2061 FALSE, (mpt->is_sas || mpt->is_fc)? 30000 : 3000);
2063 mpt_prt(mpt, "port %d enable timed out\n", port);
2066 mpt_free_request(mpt, req);
2067 mpt_lprt(mpt, MPT_PRT_DEBUG, "enabled port %d\n", port);
2072 * Enable/Disable asynchronous event reporting.
2075 mpt_send_event_request(struct mpt_softc *mpt, int onoff)
2078 MSG_EVENT_NOTIFY *enable_req;
2080 req = mpt_get_request(mpt, FALSE);
2084 enable_req = req->req_vbuf;
2085 memset(enable_req, 0, sizeof *enable_req);
2087 enable_req->Function = MPI_FUNCTION_EVENT_NOTIFICATION;
2088 enable_req->MsgContext = htole32(req->index | MPT_REPLY_HANDLER_EVENTS);
2089 enable_req->Switch = onoff;
2091 mpt_check_doorbell(mpt);
2092 mpt_lprt(mpt, MPT_PRT_DEBUG, "%sabling async events\n",
2093 onoff ? "en" : "dis");
2095 * Send the command off, but don't wait for it.
2097 mpt_send_cmd(mpt, req);
2102 * Un-mask the interrupts on the chip.
2105 mpt_enable_ints(struct mpt_softc *mpt)
2107 /* Unmask every thing except door bell int */
2108 mpt_write(mpt, MPT_OFFSET_INTR_MASK, MPT_INTR_DB_MASK);
2112 * Mask the interrupts on the chip.
2115 mpt_disable_ints(struct mpt_softc *mpt)
2117 /* Mask all interrupts */
2118 mpt_write(mpt, MPT_OFFSET_INTR_MASK,
2119 MPT_INTR_REPLY_MASK | MPT_INTR_DB_MASK);
2123 mpt_sysctl_attach(struct mpt_softc *mpt)
2125 #if __FreeBSD_version >= 500000
2126 struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(mpt->dev);
2127 struct sysctl_oid *tree = device_get_sysctl_tree(mpt->dev);
2129 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
2130 "debug", CTLFLAG_RW, &mpt->verbose, 0,
2131 "Debugging/Verbose level");
2132 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
2133 "role", CTLFLAG_RD, &mpt->role, 0,
2135 #ifdef MPT_TEST_MULTIPATH
2136 SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
2137 "failure_id", CTLFLAG_RW, &mpt->failure_id, -1,
2138 "Next Target to Fail");
2144 mpt_attach(struct mpt_softc *mpt)
2146 struct mpt_personality *pers;
2150 mpt_core_attach(mpt);
2151 mpt_core_enable(mpt);
2153 TAILQ_INSERT_TAIL(&mpt_tailq, mpt, links);
2154 for (i = 0; i < MPT_MAX_PERSONALITIES; i++) {
2155 pers = mpt_personalities[i];
2159 if (pers->probe(mpt) == 0) {
2160 error = pers->attach(mpt);
2165 mpt->mpt_pers_mask |= (0x1 << pers->id);
2171 * Now that we've attached everything, do the enable function
2172 * for all of the personalities. This allows the personalities
2173 * to do setups that are appropriate for them prior to enabling
2176 for (i = 0; i < MPT_MAX_PERSONALITIES; i++) {
2177 pers = mpt_personalities[i];
2178 if (pers != NULL && MPT_PERS_ATTACHED(pers, mpt) != 0) {
2179 error = pers->enable(mpt);
2181 mpt_prt(mpt, "personality %s attached but would"
2182 " not enable (%d)\n", pers->name, error);
2192 mpt_shutdown(struct mpt_softc *mpt)
2194 struct mpt_personality *pers;
2196 MPT_PERS_FOREACH_REVERSE(mpt, pers) {
2197 pers->shutdown(mpt);
2203 mpt_detach(struct mpt_softc *mpt)
2205 struct mpt_personality *pers;
2207 MPT_PERS_FOREACH_REVERSE(mpt, pers) {
2209 mpt->mpt_pers_mask &= ~(0x1 << pers->id);
2212 TAILQ_REMOVE(&mpt_tailq, mpt, links);
2217 mpt_core_load(struct mpt_personality *pers)
2222 * Setup core handlers and insert the default handler
2223 * into all "empty slots".
2225 for (i = 0; i < MPT_NUM_REPLY_HANDLERS; i++) {
2226 mpt_reply_handlers[i] = mpt_default_reply_handler;
2229 mpt_reply_handlers[MPT_CBI(MPT_REPLY_HANDLER_EVENTS)] =
2230 mpt_event_reply_handler;
2231 mpt_reply_handlers[MPT_CBI(MPT_REPLY_HANDLER_CONFIG)] =
2232 mpt_config_reply_handler;
2233 mpt_reply_handlers[MPT_CBI(MPT_REPLY_HANDLER_HANDSHAKE)] =
2234 mpt_handshake_reply_handler;
2239 * Initialize per-instance driver data and perform
2240 * initial controller configuration.
2243 mpt_core_attach(struct mpt_softc *mpt)
2247 LIST_INIT(&mpt->ack_frames);
2248 /* Put all request buffers on the free list */
2249 TAILQ_INIT(&mpt->request_pending_list);
2250 TAILQ_INIT(&mpt->request_free_list);
2251 TAILQ_INIT(&mpt->request_timeout_list);
2253 for (val = 0; val < MPT_MAX_REQUESTS(mpt); val++) {
2254 request_t *req = &mpt->request_pool[val];
2255 req->state = REQ_STATE_ALLOCATED;
2256 mpt_free_request(mpt, req);
2259 for (val = 0; val < MPT_MAX_LUNS; val++) {
2260 STAILQ_INIT(&mpt->trt[val].atios);
2261 STAILQ_INIT(&mpt->trt[val].inots);
2263 STAILQ_INIT(&mpt->trt_wildcard.atios);
2264 STAILQ_INIT(&mpt->trt_wildcard.inots);
2265 #ifdef MPT_TEST_MULTIPATH
2266 mpt->failure_id = -1;
2268 mpt->scsi_tgt_handler_id = MPT_HANDLER_ID_NONE;
2269 mpt_sysctl_attach(mpt);
2270 mpt_lprt(mpt, MPT_PRT_DEBUG, "doorbell req = %s\n",
2271 mpt_ioc_diag(mpt_read(mpt, MPT_OFFSET_DOORBELL)));
2274 error = mpt_configure_ioc(mpt, 0, 0);
2281 mpt_core_enable(struct mpt_softc *mpt)
2284 * We enter with the IOC enabled, but async events
2285 * not enabled, ports not enabled and interrupts
2291 * Enable asynchronous event reporting- all personalities
2292 * have attached so that they should be able to now field
2295 mpt_send_event_request(mpt, 1);
2298 * Catch any pending interrupts
2300 * This seems to be crucial- otherwise
2301 * the portenable below times out.
2308 mpt_enable_ints(mpt);
2311 * Catch any pending interrupts
2313 * This seems to be crucial- otherwise
2314 * the portenable below times out.
2321 if (mpt_send_port_enable(mpt, 0) != MPT_OK) {
2322 mpt_prt(mpt, "failed to enable port 0\n");
2331 mpt_core_shutdown(struct mpt_softc *mpt)
2333 mpt_disable_ints(mpt);
2337 mpt_core_detach(struct mpt_softc *mpt)
2342 mpt_disable_ints(mpt);
2346 mpt_core_unload(struct mpt_personality *pers)
2348 /* Unload is always successfull. */
2352 #define FW_UPLOAD_REQ_SIZE \
2353 (sizeof(MSG_FW_UPLOAD) - sizeof(SGE_MPI_UNION) \
2354 + sizeof(FW_UPLOAD_TCSGE) + sizeof(SGE_SIMPLE32))
2357 mpt_upload_fw(struct mpt_softc *mpt)
2359 uint8_t fw_req_buf[FW_UPLOAD_REQ_SIZE];
2360 MSG_FW_UPLOAD_REPLY fw_reply;
2361 MSG_FW_UPLOAD *fw_req;
2362 FW_UPLOAD_TCSGE *tsge;
2367 memset(&fw_req_buf, 0, sizeof(fw_req_buf));
2368 fw_req = (MSG_FW_UPLOAD *)fw_req_buf;
2369 fw_req->ImageType = MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM;
2370 fw_req->Function = MPI_FUNCTION_FW_UPLOAD;
2371 fw_req->MsgContext = htole32(MPT_REPLY_HANDLER_HANDSHAKE);
2372 tsge = (FW_UPLOAD_TCSGE *)&fw_req->SGL;
2373 tsge->DetailsLength = 12;
2374 tsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
2375 tsge->ImageSize = htole32(mpt->fw_image_size);
2376 sge = (SGE_SIMPLE32 *)(tsge + 1);
2377 flags = (MPI_SGE_FLAGS_LAST_ELEMENT | MPI_SGE_FLAGS_END_OF_BUFFER
2378 | MPI_SGE_FLAGS_END_OF_LIST | MPI_SGE_FLAGS_SIMPLE_ELEMENT
2379 | MPI_SGE_FLAGS_32_BIT_ADDRESSING | MPI_SGE_FLAGS_IOC_TO_HOST);
2380 flags <<= MPI_SGE_FLAGS_SHIFT;
2381 sge->FlagsLength = htole32(flags | mpt->fw_image_size);
2382 sge->Address = htole32(mpt->fw_phys);
2383 error = mpt_send_handshake_cmd(mpt, sizeof(fw_req_buf), &fw_req_buf);
2386 error = mpt_recv_handshake_reply(mpt, sizeof(fw_reply), &fw_reply);
2391 mpt_diag_outsl(struct mpt_softc *mpt, uint32_t addr,
2392 uint32_t *data, bus_size_t len)
2396 data_end = data + (roundup2(len, sizeof(uint32_t)) / 4);
2398 pci_enable_io(mpt->dev, SYS_RES_IOPORT);
2400 mpt_pio_write(mpt, MPT_OFFSET_DIAG_ADDR, addr);
2401 while (data != data_end) {
2402 mpt_pio_write(mpt, MPT_OFFSET_DIAG_DATA, *data);
2406 pci_disable_io(mpt->dev, SYS_RES_IOPORT);
2411 mpt_download_fw(struct mpt_softc *mpt)
2413 MpiFwHeader_t *fw_hdr;
2415 uint32_t ext_offset;
2418 mpt_prt(mpt, "Downloading Firmware - Image Size %d\n",
2419 mpt->fw_image_size);
2421 error = mpt_enable_diag_mode(mpt);
2423 mpt_prt(mpt, "Could not enter diagnostic mode!\n");
2427 mpt_write(mpt, MPT_OFFSET_DIAGNOSTIC,
2428 MPI_DIAG_RW_ENABLE|MPI_DIAG_DISABLE_ARM);
2430 fw_hdr = (MpiFwHeader_t *)mpt->fw_image;
2431 mpt_diag_outsl(mpt, fw_hdr->LoadStartAddress, (uint32_t*)fw_hdr,
2434 ext_offset = fw_hdr->NextImageHeaderOffset;
2435 while (ext_offset != 0) {
2436 MpiExtImageHeader_t *ext;
2438 ext = (MpiExtImageHeader_t *)((uintptr_t)fw_hdr + ext_offset);
2439 ext_offset = ext->NextImageHeaderOffset;
2441 mpt_diag_outsl(mpt, ext->LoadStartAddress, (uint32_t*)ext,
2446 pci_enable_io(mpt->dev, SYS_RES_IOPORT);
2448 /* Setup the address to jump to on reset. */
2449 mpt_pio_write(mpt, MPT_OFFSET_DIAG_ADDR, fw_hdr->IopResetRegAddr);
2450 mpt_pio_write(mpt, MPT_OFFSET_DIAG_DATA, fw_hdr->IopResetVectorValue);
2453 * The controller sets the "flash bad" status after attempting
2454 * to auto-boot from flash. Clear the status so that the controller
2455 * will continue the boot process with our newly installed firmware.
2457 mpt_pio_write(mpt, MPT_OFFSET_DIAG_ADDR, MPT_DIAG_MEM_CFG_BASE);
2458 data = mpt_pio_read(mpt, MPT_OFFSET_DIAG_DATA) | MPT_DIAG_MEM_CFG_BADFL;
2459 mpt_pio_write(mpt, MPT_OFFSET_DIAG_ADDR, MPT_DIAG_MEM_CFG_BASE);
2460 mpt_pio_write(mpt, MPT_OFFSET_DIAG_DATA, data);
2463 pci_disable_io(mpt->dev, SYS_RES_IOPORT);
2467 * Re-enable the processor and clear the boot halt flag.
2469 data = mpt_read(mpt, MPT_OFFSET_DIAGNOSTIC);
2470 data &= ~(MPI_DIAG_PREVENT_IOC_BOOT|MPI_DIAG_DISABLE_ARM);
2471 mpt_write(mpt, MPT_OFFSET_DIAGNOSTIC, data);
2473 mpt_disable_diag_mode(mpt);
2478 * Allocate/Initialize data structures for the controller. Called
2479 * once at instance startup.
2482 mpt_configure_ioc(struct mpt_softc *mpt, int tn, int needreset)
2484 PTR_MSG_PORT_FACTS_REPLY pfp;
2488 if (tn == MPT_MAX_TRYS) {
2493 * No need to reset if the IOC is already in the READY state.
2495 * Force reset if initialization failed previously.
2496 * Note that a hard_reset of the second channel of a '929
2497 * will stop operation of the first channel. Hopefully, if the
2498 * first channel is ok, the second will not require a hard
2501 if (needreset || MPT_STATE(mpt_rd_db(mpt)) != MPT_DB_STATE_READY) {
2502 if (mpt_reset(mpt, FALSE) != MPT_OK) {
2503 return (mpt_configure_ioc(mpt, tn++, 1));
2508 if (mpt_get_iocfacts(mpt, &mpt->ioc_facts) != MPT_OK) {
2509 mpt_prt(mpt, "mpt_get_iocfacts failed\n");
2510 return (mpt_configure_ioc(mpt, tn++, 1));
2512 mpt2host_iocfacts_reply(&mpt->ioc_facts);
2514 mpt_prt(mpt, "MPI Version=%d.%d.%d.%d\n",
2515 mpt->ioc_facts.MsgVersion >> 8,
2516 mpt->ioc_facts.MsgVersion & 0xFF,
2517 mpt->ioc_facts.HeaderVersion >> 8,
2518 mpt->ioc_facts.HeaderVersion & 0xFF);
2521 * Now that we know request frame size, we can calculate
2522 * the actual (reasonable) segment limit for read/write I/O.
2524 * This limit is constrained by:
2526 * + The size of each area we allocate per command (and how
2527 * many chain segments we can fit into it).
2528 * + The total number of areas we've set up.
2529 * + The actual chain depth the card will allow.
2531 * The first area's segment count is limited by the I/O request
2532 * at the head of it. We cannot allocate realistically more
2533 * than MPT_MAX_REQUESTS areas. Therefore, to account for both
2534 * conditions, we'll just start out with MPT_MAX_REQUESTS-2.
2537 /* total number of request areas we (can) allocate */
2538 mpt->max_seg_cnt = MPT_MAX_REQUESTS(mpt) - 2;
2540 /* converted to the number of chain areas possible */
2541 mpt->max_seg_cnt *= MPT_NRFM(mpt);
2543 /* limited by the number of chain areas the card will support */
2544 if (mpt->max_seg_cnt > mpt->ioc_facts.MaxChainDepth) {
2545 mpt_lprt(mpt, MPT_PRT_DEBUG,
2546 "chain depth limited to %u (from %u)\n",
2547 mpt->ioc_facts.MaxChainDepth, mpt->max_seg_cnt);
2548 mpt->max_seg_cnt = mpt->ioc_facts.MaxChainDepth;
2551 /* converted to the number of simple sges in chain segments. */
2552 mpt->max_seg_cnt *= (MPT_NSGL(mpt) - 1);
2554 mpt_lprt(mpt, MPT_PRT_DEBUG, "Maximum Segment Count: %u\n",
2556 mpt_lprt(mpt, MPT_PRT_DEBUG, "MsgLength=%u IOCNumber = %d\n",
2557 mpt->ioc_facts.MsgLength, mpt->ioc_facts.IOCNumber);
2558 mpt_lprt(mpt, MPT_PRT_DEBUG,
2559 "IOCFACTS: GlobalCredits=%d BlockSize=%u bytes "
2560 "Request Frame Size %u bytes Max Chain Depth %u\n",
2561 mpt->ioc_facts.GlobalCredits, mpt->ioc_facts.BlockSize,
2562 mpt->ioc_facts.RequestFrameSize << 2,
2563 mpt->ioc_facts.MaxChainDepth);
2564 mpt_lprt(mpt, MPT_PRT_DEBUG, "IOCFACTS: Num Ports %d, FWImageSize %d, "
2565 "Flags=%#x\n", mpt->ioc_facts.NumberOfPorts,
2566 (int)mpt->ioc_facts.FWImageSize, mpt->ioc_facts.Flags);
2568 len = mpt->ioc_facts.NumberOfPorts * sizeof (MSG_PORT_FACTS_REPLY);
2569 mpt->port_facts = kmalloc(len, M_DEVBUF, M_NOWAIT | M_ZERO);
2570 if (mpt->port_facts == NULL) {
2571 mpt_prt(mpt, "unable to allocate memory for port facts\n");
2576 if ((mpt->ioc_facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT) &&
2577 (mpt->fw_uploaded == 0)) {
2578 struct mpt_map_info mi;
2581 * In some configurations, the IOC's firmware is
2582 * stored in a shared piece of system NVRAM that
2583 * is only accessable via the BIOS. In this
2584 * case, the firmware keeps a copy of firmware in
2585 * RAM until the OS driver retrieves it. Once
2586 * retrieved, we are responsible for re-downloading
2587 * the firmware after any hard-reset.
2589 mpt->fw_image_size = mpt->ioc_facts.FWImageSize;
2590 error = mpt_dma_tag_create(mpt, mpt->parent_dmat, 1, 0,
2591 BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, NULL, NULL,
2592 mpt->fw_image_size, 1, mpt->fw_image_size, 0,
2595 mpt_prt(mpt, "cannot create firmwarew dma tag\n");
2598 error = bus_dmamem_alloc(mpt->fw_dmat,
2599 (void **)&mpt->fw_image, BUS_DMA_NOWAIT, &mpt->fw_dmap);
2601 mpt_prt(mpt, "cannot allocate firmware memory\n");
2602 bus_dma_tag_destroy(mpt->fw_dmat);
2607 bus_dmamap_load(mpt->fw_dmat, mpt->fw_dmap,
2608 mpt->fw_image, mpt->fw_image_size, mpt_map_rquest, &mi, 0);
2609 mpt->fw_phys = mi.phys;
2611 error = mpt_upload_fw(mpt);
2613 mpt_prt(mpt, "firmware upload failed.\n");
2614 bus_dmamap_unload(mpt->fw_dmat, mpt->fw_dmap);
2615 bus_dmamem_free(mpt->fw_dmat, mpt->fw_image,
2617 bus_dma_tag_destroy(mpt->fw_dmat);
2618 mpt->fw_image = NULL;
2621 mpt->fw_uploaded = 1;
2624 for (port = 0; port < mpt->ioc_facts.NumberOfPorts; port++) {
2625 pfp = &mpt->port_facts[port];
2626 error = mpt_get_portfacts(mpt, 0, pfp);
2627 if (error != MPT_OK) {
2629 "mpt_get_portfacts on port %d failed\n", port);
2630 kfree(mpt->port_facts, M_DEVBUF);
2631 mpt->port_facts = NULL;
2632 return (mpt_configure_ioc(mpt, tn++, 1));
2634 mpt2host_portfacts_reply(pfp);
2637 error = MPT_PRT_INFO;
2639 error = MPT_PRT_DEBUG;
2641 mpt_lprt(mpt, error,
2642 "PORTFACTS[%d]: Type %x PFlags %x IID %d MaxDev %d\n",
2643 port, pfp->PortType, pfp->ProtocolFlags, pfp->PortSCSIID,
2649 * XXX: Not yet supporting more than port 0
2651 pfp = &mpt->port_facts[0];
2652 if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_FC) {
2656 } else if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_SAS) {
2660 } else if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_SCSI) {
2664 } else if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_ISCSI) {
2665 mpt_prt(mpt, "iSCSI not supported yet\n");
2667 } else if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_INACTIVE) {
2668 mpt_prt(mpt, "Inactive Port\n");
2671 mpt_prt(mpt, "unknown Port Type %#x\n", pfp->PortType);
2676 * Set our role with what this port supports.
2678 * Note this might be changed later in different modules
2679 * if this is different from what is wanted.
2681 mpt->role = MPT_ROLE_NONE;
2682 if (pfp->ProtocolFlags & MPI_PORTFACTS_PROTOCOL_INITIATOR) {
2683 mpt->role |= MPT_ROLE_INITIATOR;
2685 if (pfp->ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
2686 mpt->role |= MPT_ROLE_TARGET;
2692 if (mpt_enable_ioc(mpt, 1) != MPT_OK) {
2693 mpt_prt(mpt, "unable to initialize IOC\n");
2698 * Read IOC configuration information.
2700 * We need this to determine whether or not we have certain
2701 * settings for Integrated Mirroring (e.g.).
2703 mpt_read_config_info_ioc(mpt);
2709 mpt_enable_ioc(struct mpt_softc *mpt, int portenable)
2714 if (mpt_send_ioc_init(mpt, MPI_WHOINIT_HOST_DRIVER) != MPT_OK) {
2715 mpt_prt(mpt, "mpt_send_ioc_init failed\n");
2719 mpt_lprt(mpt, MPT_PRT_DEBUG, "mpt_send_ioc_init ok\n");
2721 if (mpt_wait_state(mpt, MPT_DB_STATE_RUNNING) != MPT_OK) {
2722 mpt_prt(mpt, "IOC failed to go to run state\n");
2725 mpt_lprt(mpt, MPT_PRT_DEBUG, "IOC now at RUNSTATE\n");
2728 * Give it reply buffers
2730 * Do *not* exceed global credits.
2732 for (val = 0, pptr = mpt->reply_phys;
2733 (pptr + MPT_REPLY_SIZE) < (mpt->reply_phys + PAGE_SIZE);
2734 pptr += MPT_REPLY_SIZE) {
2735 mpt_free_reply(mpt, pptr);
2736 if (++val == mpt->ioc_facts.GlobalCredits - 1)
2742 * Enable the port if asked. This is only done if we're resetting
2743 * the IOC after initial startup.
2747 * Enable asynchronous event reporting
2749 mpt_send_event_request(mpt, 1);
2751 if (mpt_send_port_enable(mpt, 0) != MPT_OK) {
2752 mpt_prt(mpt, "failed to enable port 0\n");
2760 * Endian Conversion Functions- only used on Big Endian machines
2762 #if _BYTE_ORDER == _BIG_ENDIAN
2764 mpt2host_sge_simple_union(SGE_SIMPLE_UNION *sge)
2767 MPT_2_HOST32(sge, FlagsLength);
2768 MPT_2_HOST32(sge, u.Address64.Low);
2769 MPT_2_HOST32(sge, u.Address64.High);
2773 mpt2host_iocfacts_reply(MSG_IOC_FACTS_REPLY *rp)
2776 MPT_2_HOST16(rp, MsgVersion);
2777 MPT_2_HOST16(rp, HeaderVersion);
2778 MPT_2_HOST32(rp, MsgContext);
2779 MPT_2_HOST16(rp, IOCExceptions);
2780 MPT_2_HOST16(rp, IOCStatus);
2781 MPT_2_HOST32(rp, IOCLogInfo);
2782 MPT_2_HOST16(rp, ReplyQueueDepth);
2783 MPT_2_HOST16(rp, RequestFrameSize);
2784 MPT_2_HOST16(rp, Reserved_0101_FWVersion);
2785 MPT_2_HOST16(rp, ProductID);
2786 MPT_2_HOST32(rp, CurrentHostMfaHighAddr);
2787 MPT_2_HOST16(rp, GlobalCredits);
2788 MPT_2_HOST32(rp, CurrentSenseBufferHighAddr);
2789 MPT_2_HOST16(rp, CurReplyFrameSize);
2790 MPT_2_HOST32(rp, FWImageSize);
2791 MPT_2_HOST32(rp, IOCCapabilities);
2792 MPT_2_HOST32(rp, FWVersion.Word);
2793 MPT_2_HOST16(rp, HighPriorityQueueDepth);
2794 MPT_2_HOST16(rp, Reserved2);
2795 mpt2host_sge_simple_union(&rp->HostPageBufferSGE);
2796 MPT_2_HOST32(rp, ReplyFifoHostSignalingAddr);
2800 mpt2host_portfacts_reply(MSG_PORT_FACTS_REPLY *pfp)
2803 MPT_2_HOST16(pfp, Reserved);
2804 MPT_2_HOST16(pfp, Reserved1);
2805 MPT_2_HOST32(pfp, MsgContext);
2806 MPT_2_HOST16(pfp, Reserved2);
2807 MPT_2_HOST16(pfp, IOCStatus);
2808 MPT_2_HOST32(pfp, IOCLogInfo);
2809 MPT_2_HOST16(pfp, MaxDevices);
2810 MPT_2_HOST16(pfp, PortSCSIID);
2811 MPT_2_HOST16(pfp, ProtocolFlags);
2812 MPT_2_HOST16(pfp, MaxPostedCmdBuffers);
2813 MPT_2_HOST16(pfp, MaxPersistentIDs);
2814 MPT_2_HOST16(pfp, MaxLanBuckets);
2815 MPT_2_HOST16(pfp, Reserved4);
2816 MPT_2_HOST32(pfp, Reserved5);
2820 mpt2host_config_page_ioc2(CONFIG_PAGE_IOC_2 *ioc2)
2824 MPT_2_HOST32(ioc2, CapabilitiesFlags);
2825 for (i = 0; i < MPI_IOC_PAGE_2_RAID_VOLUME_MAX; i++) {
2826 MPT_2_HOST16(ioc2, RaidVolume[i].Reserved3);
2831 mpt2host_config_page_ioc3(CONFIG_PAGE_IOC_3 *ioc3)
2834 MPT_2_HOST16(ioc3, Reserved2);
2838 mpt2host_config_page_scsi_port_0(CONFIG_PAGE_SCSI_PORT_0 *sp0)
2841 MPT_2_HOST32(sp0, Capabilities);
2842 MPT_2_HOST32(sp0, PhysicalInterface);
2846 mpt2host_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *sp1)
2849 MPT_2_HOST32(sp1, Configuration);
2850 MPT_2_HOST32(sp1, OnBusTimerValue);
2851 MPT_2_HOST16(sp1, IDConfig);
2855 host2mpt_config_page_scsi_port_1(CONFIG_PAGE_SCSI_PORT_1 *sp1)
2858 HOST_2_MPT32(sp1, Configuration);
2859 HOST_2_MPT32(sp1, OnBusTimerValue);
2860 HOST_2_MPT16(sp1, IDConfig);
2864 mpt2host_config_page_scsi_port_2(CONFIG_PAGE_SCSI_PORT_2 *sp2)
2868 MPT_2_HOST32(sp2, PortFlags);
2869 MPT_2_HOST32(sp2, PortSettings);
2870 for (i = 0; i < sizeof(sp2->DeviceSettings) /
2871 sizeof(*sp2->DeviceSettings); i++) {
2872 MPT_2_HOST16(sp2, DeviceSettings[i].DeviceFlags);
2877 mpt2host_config_page_scsi_device_0(CONFIG_PAGE_SCSI_DEVICE_0 *sd0)
2880 MPT_2_HOST32(sd0, NegotiatedParameters);
2881 MPT_2_HOST32(sd0, Information);
2885 mpt2host_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *sd1)
2888 MPT_2_HOST32(sd1, RequestedParameters);
2889 MPT_2_HOST32(sd1, Reserved);
2890 MPT_2_HOST32(sd1, Configuration);
2894 host2mpt_config_page_scsi_device_1(CONFIG_PAGE_SCSI_DEVICE_1 *sd1)
2897 HOST_2_MPT32(sd1, RequestedParameters);
2898 HOST_2_MPT32(sd1, Reserved);
2899 HOST_2_MPT32(sd1, Configuration);
2903 mpt2host_config_page_fc_port_0(CONFIG_PAGE_FC_PORT_0 *fp0)
2906 MPT_2_HOST32(fp0, Flags);
2907 MPT_2_HOST32(fp0, PortIdentifier);
2908 MPT_2_HOST32(fp0, WWNN.Low);
2909 MPT_2_HOST32(fp0, WWNN.High);
2910 MPT_2_HOST32(fp0, WWPN.Low);
2911 MPT_2_HOST32(fp0, WWPN.High);
2912 MPT_2_HOST32(fp0, SupportedServiceClass);
2913 MPT_2_HOST32(fp0, SupportedSpeeds);
2914 MPT_2_HOST32(fp0, CurrentSpeed);
2915 MPT_2_HOST32(fp0, MaxFrameSize);
2916 MPT_2_HOST32(fp0, FabricWWNN.Low);
2917 MPT_2_HOST32(fp0, FabricWWNN.High);
2918 MPT_2_HOST32(fp0, FabricWWPN.Low);
2919 MPT_2_HOST32(fp0, FabricWWPN.High);
2920 MPT_2_HOST32(fp0, DiscoveredPortsCount);
2921 MPT_2_HOST32(fp0, MaxInitiators);
2925 mpt2host_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *fp1)
2928 MPT_2_HOST32(fp1, Flags);
2929 MPT_2_HOST32(fp1, NoSEEPROMWWNN.Low);
2930 MPT_2_HOST32(fp1, NoSEEPROMWWNN.High);
2931 MPT_2_HOST32(fp1, NoSEEPROMWWPN.Low);
2932 MPT_2_HOST32(fp1, NoSEEPROMWWPN.High);
2936 host2mpt_config_page_fc_port_1(CONFIG_PAGE_FC_PORT_1 *fp1)
2939 HOST_2_MPT32(fp1, Flags);
2940 HOST_2_MPT32(fp1, NoSEEPROMWWNN.Low);
2941 HOST_2_MPT32(fp1, NoSEEPROMWWNN.High);
2942 HOST_2_MPT32(fp1, NoSEEPROMWWPN.Low);
2943 HOST_2_MPT32(fp1, NoSEEPROMWWPN.High);
2947 mpt2host_config_page_raid_vol_0(CONFIG_PAGE_RAID_VOL_0 *volp)
2951 MPT_2_HOST16(volp, VolumeStatus.Reserved);
2952 MPT_2_HOST16(volp, VolumeSettings.Settings);
2953 MPT_2_HOST32(volp, MaxLBA);
2954 MPT_2_HOST32(volp, MaxLBAHigh);
2955 MPT_2_HOST32(volp, StripeSize);
2956 MPT_2_HOST32(volp, Reserved2);
2957 MPT_2_HOST32(volp, Reserved3);
2958 for (i = 0; i < MPI_RAID_VOL_PAGE_0_PHYSDISK_MAX; i++) {
2959 MPT_2_HOST16(volp, PhysDisk[i].Reserved);
2964 mpt2host_config_page_raid_phys_disk_0(CONFIG_PAGE_RAID_PHYS_DISK_0 *rpd0)
2967 MPT_2_HOST32(rpd0, Reserved1);
2968 MPT_2_HOST16(rpd0, PhysDiskStatus.Reserved);
2969 MPT_2_HOST32(rpd0, MaxLBA);
2970 MPT_2_HOST16(rpd0, ErrorData.Reserved);
2971 MPT_2_HOST16(rpd0, ErrorData.ErrorCount);
2972 MPT_2_HOST16(rpd0, ErrorData.SmartCount);
2976 mpt2host_mpi_raid_vol_indicator(MPI_RAID_VOL_INDICATOR *vi)
2979 MPT_2_HOST16(vi, TotalBlocks.High);
2980 MPT_2_HOST16(vi, TotalBlocks.Low);
2981 MPT_2_HOST16(vi, BlocksRemaining.High);
2982 MPT_2_HOST16(vi, BlocksRemaining.Low);