From 6d259fc1b7faf91ed8b9e3165b52a8d35311895d Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Fri, 29 Apr 2011 01:54:29 +0200 Subject: [PATCH] mpt(4): Sync with FreeBSD. This fixes issues which were observed with the LSI SAS 3081E-R card. Reported-and-tested-by: --- share/man/man4/mpt.4 | 10 +- sys/dev/disk/mpt/mpilib/fc_log.h | 111 ------------ sys/dev/disk/mpt/mpilib/mpi_type.h | 2 +- sys/dev/disk/mpt/mpt.c | 276 ++++++++++++++++++++++------- sys/dev/disk/mpt/mpt.h | 257 ++++----------------------- sys/dev/disk/mpt/mpt_cam.c | 158 ++++++++--------- sys/dev/disk/mpt/mpt_cam.h | 13 +- sys/dev/disk/mpt/mpt_debug.c | 115 ++++-------- sys/dev/disk/mpt/mpt_pci.c | 189 ++++---------------- sys/dev/disk/mpt/mpt_raid.c | 82 ++++----- sys/dev/disk/mpt/mpt_raid.h | 8 +- sys/dev/disk/mpt/mpt_user.c | 44 +++-- usr.sbin/mptutil/mpt_cam.c | 20 ++- usr.sbin/mptutil/mpt_cmd.c | 52 +++--- usr.sbin/mptutil/mpt_config.c | 221 +++++++++++++---------- usr.sbin/mptutil/mpt_drive.c | 40 +++-- usr.sbin/mptutil/mpt_evt.c | 12 +- usr.sbin/mptutil/mpt_show.c | 42 +++-- usr.sbin/mptutil/mpt_volume.c | 68 ++++--- usr.sbin/mptutil/mptutil.8 | 23 ++- usr.sbin/mptutil/mptutil.c | 10 +- usr.sbin/mptutil/mptutil.h | 1 - 22 files changed, 740 insertions(+), 1014 deletions(-) delete mode 100644 sys/dev/disk/mpt/mpilib/fc_log.h diff --git a/share/man/man4/mpt.4 b/share/man/man4/mpt.4 index 1d3b44c2ce..fd2672d0e7 100644 --- a/share/man/man4/mpt.4 +++ b/share/man/man4/mpt.4 @@ -1,5 +1,4 @@ .\" $NetBSD: mpt.4,v 1.1 2003/04/16 22:32:15 thorpej Exp $ -.\" $FreeBSD: src/share/man/man4/mpt.4,v 1.16.2.1 2009/08/03 08:13:06 kensmith Exp $ .\" .\" Copyright (c) 2003 Wasabi Systems, Inc. .\" All rights reserved. @@ -34,7 +33,9 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd August 16, 2009 +.\" $FreeBSD: src/share/man/man4/mpt.4,v 1.21 2010/09/14 21:40:29 ken Exp $ +.\" +.Dd April 28, 2011 .Dt MPT 4 .Os .Sh NAME @@ -104,6 +105,7 @@ LSI Logic FC949X (Dual 4Gb/s .Tn Fibre Channel ) .It +LSI Logic FC949E, LSI Logic FC949ES (Dual 4Gb/s .Tn Fibre Channel PCI-Express) @@ -151,9 +153,11 @@ can take on - no separate compilation is required. .Xr cd 4 , .Xr ch 4 , .Xr da 4 , +.\".Xr mps 4 , .Xr pci 4 , .Xr sa 4 , -.Xr scsi 4 +.Xr scsi 4 , +.Xr mptutil 8 .Rs .%T "LSI Logic Website" .%O http://www.lsilogic.com/ diff --git a/sys/dev/disk/mpt/mpilib/fc_log.h b/sys/dev/disk/mpt/mpilib/fc_log.h deleted file mode 100644 index d09f846799..0000000000 --- a/sys/dev/disk/mpt/mpilib/fc_log.h +++ /dev/null @@ -1,111 +0,0 @@ -/* $FreeBSD: src/sys/dev/mpt/mpilib/fc_log.h,v 1.1.2.2 2002/09/01 23:08:06 mjacob Exp $ */ -/* $DragonFly: src/sys/dev/disk/mpt/mpilib/fc_log.h,v 1.2 2003/06/17 04:28:28 dillon Exp $ */ -/* - * Copyright (c) 2000, 2001 by LSI Logic Corporation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice immediately at the beginning of the file, without modification, - * this list of conditions, and the following disclaimer. - * 2. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * NAME: fc_log.h - * SUMMARY: MPI IocLogInfo definitions for the SYMFC9xx chips - * DESCRIPTION: Contains the enumerated list of values that may be returned - * in the IOCLogInfo field of a MPI Default Reply Message. - * - * CREATION DATE: 6/02/2000 - * ID: $Id: fc_log.h,v 4.6 2001/07/26 14:41:33 sschremm Exp $ - */ - -/* - * MpiIocLogInfo_t enum - * - * These 32 bit values are used in the IOCLogInfo field of the MPI reply - * messages. - * The value is 0xabcccccc where - * a = The type of log info as per the MPI spec. Since these codes are - * all for Fibre Channel this value will always be 2. - * b = Specifies a subclass of the firmware where - * 0 = FCP Initiator - * 1 = FCP Target - * 2 = LAN - * 3 = MPI Message Layer - * 4 = FC Link - * 5 = Context Manager - * 6 = Invalid Field Offset - * 7 = State Change Info - * all others are reserved for future use - * c = A specific value within the subclass. - * - * NOTE: Any new values should be added to the end of each subclass so that the - * codes remain consistent across firmware releases. - */ -typedef enum _MpiIocLogInfoFc -{ - MPI_IOCLOGINFO_FC_INIT_BASE = 0x20000000, - MPI_IOCLOGINFO_FC_INIT_ERROR_OUT_OF_ORDER_FRAME = 0x20000001, /* received an out of order frame - unsupported */ - MPI_IOCLOGINFO_FC_INIT_ERROR_BAD_START_OF_FRAME = 0x20000002, /* Bad Rx Frame, bad start of frame primative */ - MPI_IOCLOGINFO_FC_INIT_ERROR_BAD_END_OF_FRAME = 0x20000003, /* Bad Rx Frame, bad end of frame primative */ - MPI_IOCLOGINFO_FC_INIT_ERROR_OVER_RUN = 0x20000004, /* Bad Rx Frame, overrun */ - MPI_IOCLOGINFO_FC_INIT_ERROR_RX_OTHER = 0x20000005, /* Other errors caught by IOC which require retries */ - MPI_IOCLOGINFO_FC_INIT_ERROR_SUBPROC_DEAD = 0x20000006, /* Main processor could not initialize sub-processor */ - MPI_IOCLOGINFO_FC_INIT_ERROR_RX_OVERRUN = 0x20000007, /* Scatter Gather overrun */ - MPI_IOCLOGINFO_FC_INIT_ERROR_RX_BAD_STATUS = 0x20000008, /* Receiver detected context mismatch via invalid header */ - MPI_IOCLOGINFO_FC_INIT_ERROR_RX_UNEXPECTED_FRAME= 0x20000009, /* CtxMgr detected unsupported frame type */ - MPI_IOCLOGINFO_FC_INIT_ERROR_LINK_FAILURE = 0x2000000A, /* Link failure occurred */ - MPI_IOCLOGINFO_FC_INIT_ERROR_TX_TIMEOUT = 0x2000000B, /* Transmitter timeout error */ - - MPI_IOCLOGINFO_FC_TARGET_BASE = 0x21000000, - MPI_IOCLOGINFO_FC_TARGET_NO_PDISC = 0x21000001, /* not sent because we are waiting for a PDISC from the initiator */ - MPI_IOCLOGINFO_FC_TARGET_NO_LOGIN = 0x21000002, /* not sent because we are not logged in to the remote node */ - MPI_IOCLOGINFO_FC_TARGET_DOAR_KILLED_BY_LIP = 0x21000003, /* Data Out, Auto Response, not sent due to a LIP */ - MPI_IOCLOGINFO_FC_TARGET_DIAR_KILLED_BY_LIP = 0x21000004, /* Data In, Auto Response, not sent due to a LIP */ - MPI_IOCLOGINFO_FC_TARGET_DIAR_MISSING_DATA = 0x21000005, /* Data In, Auto Response, missing data frames */ - MPI_IOCLOGINFO_FC_TARGET_DONR_KILLED_BY_LIP = 0x21000006, /* Data Out, No Response, not sent due to a LIP */ - MPI_IOCLOGINFO_FC_TARGET_WRSP_KILLED_BY_LIP = 0x21000007, /* Auto-response after a write not sent due to a LIP */ - MPI_IOCLOGINFO_FC_TARGET_DINR_KILLED_BY_LIP = 0x21000008, /* Data In, No Response, not completed due to a LIP */ - MPI_IOCLOGINFO_FC_TARGET_DINR_MISSING_DATA = 0x21000009, /* Data In, No Response, missing data frames */ - MPI_IOCLOGINFO_FC_TARGET_MRSP_KILLED_BY_LIP = 0x2100000a, /* Manual Response not sent due to a LIP */ - MPI_IOCLOGINFO_FC_TARGET_NO_CLASS_3 = 0x2100000b, /* not sent because remote node does not support Class 3 */ - MPI_IOCLOGINFO_FC_TARGET_LOGIN_NOT_VALID = 0x2100000c, /* not sent because login to remote node not validated */ - MPI_IOCLOGINFO_FC_TARGET_FROM_OUTBOUND = 0x2100000e, /* cleared from the outbound queue after a logout */ - MPI_IOCLOGINFO_FC_TARGET_WAITING_FOR_DATA_IN = 0x2100000f, /* cleared waiting for data after a logout */ - - MPI_IOCLOGINFO_FC_LAN_BASE = 0x22000000, - MPI_IOCLOGINFO_FC_LAN_TRANS_SGL_MISSING = 0x22000001, /* Transaction Context Sgl Missing */ - MPI_IOCLOGINFO_FC_LAN_TRANS_WRONG_PLACE = 0x22000002, /* Transaction Context found before an EOB */ - MPI_IOCLOGINFO_FC_LAN_TRANS_RES_BITS_SET = 0x22000003, /* Transaction Context value has reserved bits set */ - MPI_IOCLOGINFO_FC_LAN_WRONG_SGL_FLAG = 0x22000004, /* Invalid SGL Flags */ - - MPI_IOCLOGINFO_FC_MSG_BASE = 0x23000000, - - MPI_IOCLOGINFO_FC_LINK_BASE = 0x24000000, - MPI_IOCLOGINFO_FC_LINK_LOOP_INIT_TIMEOUT = 0x24000001, /* Loop initialization timed out */ - MPI_IOCLOGINFO_FC_LINK_ALREADY_INITIALIZED = 0x24000002, /* Another system controller already initialized the loop */ - MPI_IOCLOGINFO_FC_LINK_LINK_NOT_ESTABLISHED = 0x24000003, /* Not synchronized to signal or still negotiating (possible cable problem) */ - MPI_IOCLOGINFO_FC_LINK_CRC_ERROR = 0x24000004, /* CRC check detected error on received frame */ - - MPI_IOCLOGINFO_FC_CTX_BASE = 0x25000000, - - MPI_IOCLOGINFO_FC_INVALID_FIELD_BYTE_OFFSET = 0x26000000, /* The lower 24 bits give the byte offset of the field in the request message that is invalid */ - MPI_IOCLOGINFO_FC_INVALID_FIELD_MAX_OFFSET = 0x26ffffff, - - MPI_IOCLOGINFO_FC_STATE_CHANGE = 0x27000000 /* The lower 24 bits give additional information concerning state change */ - -} MpiIocLogInfoFc_t; diff --git a/sys/dev/disk/mpt/mpilib/mpi_type.h b/sys/dev/disk/mpt/mpilib/mpi_type.h index 69271d6427..f4bcbc0a8f 100644 --- a/sys/dev/disk/mpt/mpilib/mpi_type.h +++ b/sys/dev/disk/mpt/mpilib/mpi_type.h @@ -77,7 +77,7 @@ typedef unsigned char U8; typedef signed short S16; typedef unsigned short U16; -#if defined(__FreeBSD__) || defined(__DragonFly__) +#ifdef __DragonFly__ typedef int32_t S32; typedef uint32_t U32; diff --git a/sys/dev/disk/mpt/mpt.c b/sys/dev/disk/mpt/mpt.c index 5279b154aa..e7ac172824 100644 --- a/sys/dev/disk/mpt/mpt.c +++ b/sys/dev/disk/mpt/mpt.c @@ -94,7 +94,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/sys/dev/mpt/mpt.c,v 1.49 2009/01/07 21:52:47 marius Exp $ + * $FreeBSD: src/sys/dev/mpt/mpt.c,v 1.57 2011/04/22 09:59:16 marius Exp $ */ #include @@ -127,6 +127,8 @@ static void mpt_send_event_ack(struct mpt_softc *mpt, request_t *ack_req, static int mpt_send_event_request(struct mpt_softc *mpt, int onoff); static int mpt_soft_reset(struct mpt_softc *mpt); static void mpt_hard_reset(struct mpt_softc *mpt); +static int mpt_dma_buf_alloc(struct mpt_softc *mpt); +static void mpt_dma_buf_free(struct mpt_softc *mpt); static int mpt_configure_ioc(struct mpt_softc *mpt, int, int); static int mpt_enable_ioc(struct mpt_softc *mpt, int); @@ -301,28 +303,28 @@ mpt_modevent(module_t mod, int type, void *data) int mpt_stdload(struct mpt_personality *pers) { - /* Load is always successfull. */ + /* Load is always successful. */ return (0); } int mpt_stdprobe(struct mpt_softc *mpt) { - /* Probe is always successfull. */ + /* Probe is always successful. */ return (0); } int mpt_stdattach(struct mpt_softc *mpt) { - /* Attach is always successfull. */ + /* Attach is always successful. */ return (0); } int mpt_stdenable(struct mpt_softc *mpt) { - /* Enable is always successfull. */ + /* Enable is always successful. */ return (0); } @@ -335,8 +337,7 @@ mpt_stdready(struct mpt_softc *mpt) int mpt_stdevent(struct mpt_softc *mpt, request_t *req, MSG_EVENT_NOTIFY_REPLY *msg) { - mpt_lprt(mpt, MPT_PRT_DEBUG, "mpt_stdevent: 0x%x\n", - msg->Event & 0xFF); + mpt_lprt(mpt, MPT_PRT_DEBUG, "mpt_stdevent: 0x%x\n", msg->Event & 0xFF); /* Event was not for us. */ return (0); } @@ -359,7 +360,7 @@ mpt_stddetach(struct mpt_softc *mpt) int mpt_stdunload(struct mpt_personality *pers) { - /* Unload is always successfull. */ + /* Unload is always successful. */ return (0); } @@ -560,15 +561,13 @@ mpt_event_reply_handler(struct mpt_softc *mpt, request_t *req, mpt_lprt(mpt, MPT_PRT_INFO, "No Handlers For Any Event Notify Frames. " "Event %#x (ACK %sequired).\n", - (unsigned)msg->Event, - msg->AckRequired? "r" : "not r"); + msg->Event, msg->AckRequired? "r" : "not r"); } else if (handled == 0) { mpt_lprt(mpt, msg->AckRequired? MPT_PRT_WARN : MPT_PRT_INFO, "Unhandled Event Notify Frame. Event %#x " "(ACK %sequired).\n", - (unsigned)msg->Event, - msg->AckRequired? "r" : "not r"); + msg->Event, msg->AckRequired? "r" : "not r"); } if (msg->AckRequired) { @@ -651,7 +650,7 @@ mpt_core_event(struct mpt_softc *mpt, request_t *req, MSG_EVENT_NOTIFY_REPLY *msg) { mpt_lprt(mpt, MPT_PRT_DEBUG, "mpt_core_event: 0x%x\n", - (unsigned)(msg->Event & 0xFF)); + msg->Event & 0xFF); switch(msg->Event & 0xFF) { case MPI_EVENT_NONE: break; @@ -659,12 +658,12 @@ mpt_core_event(struct mpt_softc *mpt, request_t *req, { int i; - /* Some error occured that LSI wants logged */ + /* Some error occurred that LSI wants logged */ mpt_prt(mpt, "EvtLogData: IOCLogInfo: 0x%08x\n", - (unsigned)msg->IOCLogInfo); + msg->IOCLogInfo); mpt_prt(mpt, "\tEvtLogData: Event Data:"); for (i = 0; i < msg->EventDataLength; i++) - mpt_prtc(mpt, " %08x", (unsigned)msg->Data[i]); + mpt_prtc(mpt, " %08x", msg->Data[i]); mpt_prtc(mpt, "\n"); break; } @@ -718,15 +717,16 @@ mpt_intr(void *arg) uint32_t ctxt_idx; u_int cb_index; u_int req_index; + u_int offset; int free_rf; req = NULL; reply_frame = NULL; reply_baddr = 0; + offset = 0; if ((reply_desc & MPI_ADDRESS_REPLY_A_BIT) != 0) { - u_int offset; /* - * Insure that the reply frame is coherent. + * Ensure that the reply frame is coherent. */ reply_baddr = MPT_REPLY_BADDR(reply_desc); offset = reply_baddr - (mpt->reply_phys & 0xFFFFFFFF); @@ -808,10 +808,15 @@ mpt_intr(void *arg) " 0x%x)\n", req_index, reply_desc); } + bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap, + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); free_rf = mpt_reply_handlers[cb_index](mpt, req, reply_desc, reply_frame); if (reply_frame != NULL && free_rf) { + bus_dmamap_sync_range(mpt->reply_dmat, + mpt->reply_dmap, offset, MPT_REPLY_SIZE, + BUS_DMASYNC_PREREAD); mpt_free_reply(mpt, reply_baddr); } @@ -844,13 +849,16 @@ mpt_complete_request_chain(struct mpt_softc *mpt, struct req_queue *chain, MSG_REQUEST_HEADER *msg_hdr; u_int cb_index; - TAILQ_REMOVE(chain, req, links); + bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap, + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); msg_hdr = (MSG_REQUEST_HEADER *)req->req_vbuf; ioc_status_frame.Function = msg_hdr->Function; ioc_status_frame.MsgContext = msg_hdr->MsgContext; cb_index = MPT_CONTEXT_TO_CBI(le32toh(msg_hdr->MsgContext)); mpt_reply_handlers[cb_index](mpt, req, msg_hdr->MsgContext, &ioc_status_frame); + if (mpt_req_on_pending_list(mpt, req) != 0) + TAILQ_REMOVE(chain, req, links); } } @@ -1166,7 +1174,7 @@ mpt_free_request(struct mpt_softc *mpt, request_t *req) { request_t *nxt; struct mpt_evtf_record *record; - uint32_t reply_baddr; + uint32_t offset, reply_baddr; if (req == NULL || req != &mpt->request_pool[req->index]) { panic("mpt_free_request bad req ptr\n"); @@ -1215,8 +1223,10 @@ mpt_free_request(struct mpt_softc *mpt, request_t *req) req->state = REQ_STATE_ALLOCATED; mpt_assign_serno(mpt, req); mpt_send_event_ack(mpt, req, &record->reply, record->context); - reply_baddr = (uint32_t)((uint8_t *)record - mpt->reply) - + (mpt->reply_phys & 0xFFFFFFFF); + offset = (uint32_t)((uint8_t *)record - mpt->reply); + reply_baddr = offset + (mpt->reply_phys & 0xFFFFFFFF); + bus_dmamap_sync_range(mpt->reply_dmat, mpt->reply_dmap, offset, + MPT_REPLY_SIZE, BUS_DMASYNC_PREREAD); mpt_free_reply(mpt, reply_baddr); } @@ -1240,10 +1250,9 @@ retry: req->state = REQ_STATE_ALLOCATED; req->chain = NULL; mpt_assign_serno(mpt, req); - mpt_callout_init(&req->callout); } else if (sleep_ok != 0) { mpt->getreqwaiter = 1; - mpt_sleep(mpt, &mpt->request_free_list, PUSER, "mptgreq", 0); + mpt_sleep(mpt, &mpt->request_free_list, 0, "mptgreq", 0); goto retry; } return (req); @@ -1257,7 +1266,7 @@ mpt_send_cmd(struct mpt_softc *mpt, request_t *req) mpt_dump_request(mpt, req); } bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap, - BUS_DMASYNC_PREWRITE); + BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); req->state |= REQ_STATE_QUEUED; KASSERT(mpt_req_on_free_list(mpt, req) == 0, ("req %p:%u func %x on freelist list in mpt_send_cmd", @@ -1306,7 +1315,7 @@ mpt_wait_req(struct mpt_softc *mpt, request_t *req, saved_cnt = mpt->reset_cnt; while ((req->state & mask) != state && mpt->reset_cnt == saved_cnt) { if (sleep_ok != 0) { - error = mpt_sleep(mpt, req, PUSER, "mptreq", timeout); + error = mpt_sleep(mpt, req, 0, "mptreq", timeout); if (error == EWOULDBLOCK) { timeout = 0; break; @@ -1436,15 +1445,9 @@ mpt_recv_handshake_reply(struct mpt_softc *mpt, size_t reply_len, void *reply) */ if ((reply_len >> 1) != hdr->MsgLength && (hdr->Function != MPI_FUNCTION_IOC_FACTS)){ -#if __FreeBSD_version >= 500000 mpt_prt(mpt, "reply length does not match message length: " "got %x; expected %zx for function %x\n", hdr->MsgLength << 2, reply_len << 1, hdr->Function); -#else - mpt_prt(mpt, "reply length does not match message length: " - "got %x; expected %zx for function %x\n", - hdr->MsgLength << 2, reply_len << 1, hdr->Function); -#endif } /* Get rest of the reply; but don't overflow the provided buffer */ @@ -1487,7 +1490,7 @@ mpt_get_iocfacts(struct mpt_softc *mpt, MSG_IOC_FACTS_REPLY *freplp) { MSG_IOC_FACTS f_req; int error; - + memset(&f_req, 0, sizeof f_req); f_req.Function = MPI_FUNCTION_IOC_FACTS; f_req.MsgContext = htole32(MPT_REPLY_HANDLER_HANDSHAKE); @@ -1504,7 +1507,7 @@ mpt_get_portfacts(struct mpt_softc *mpt, U8 port, MSG_PORT_FACTS_REPLY *freplp) { MSG_PORT_FACTS f_req; int error; - + memset(&f_req, 0, sizeof f_req); f_req.Function = MPI_FUNCTION_PORT_FACTS; f_req.PortNumber = port; @@ -1696,8 +1699,6 @@ mpt_read_extcfg_page(struct mpt_softc *mpt, int Action, uint32_t PageAddress, mpt_free_request(mpt, req); return (-1); } - bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap, - BUS_DMASYNC_POSTREAD); memcpy(buf, ((uint8_t *)req->req_vbuf)+MPT_RQSL(mpt), len); mpt_free_request(mpt, req); return (0); @@ -1795,8 +1796,6 @@ mpt_read_cfg_page(struct mpt_softc *mpt, int Action, uint32_t PageAddress, mpt_free_request(mpt, req); return (-1); } - bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap, - BUS_DMASYNC_POSTREAD); memcpy(hdr, ((uint8_t *)req->req_vbuf)+MPT_RQSL(mpt), len); mpt_free_request(mpt, req); return (0); @@ -2122,22 +2121,20 @@ mpt_disable_ints(struct mpt_softc *mpt) static void mpt_sysctl_attach(struct mpt_softc *mpt) { -#if __FreeBSD_version >= 500000 - struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(mpt->dev); - struct sysctl_oid *tree = device_get_sysctl_tree(mpt->dev); - - SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + SYSCTL_ADD_UINT(&mpt->mpt_sysctl_ctx, + SYSCTL_CHILDREN(mpt->mpt_sysctl_tree), OID_AUTO, "debug", CTLFLAG_RW, &mpt->verbose, 0, "Debugging/Verbose level"); - SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + SYSCTL_ADD_UINT(&mpt->mpt_sysctl_ctx, + SYSCTL_CHILDREN(mpt->mpt_sysctl_tree), OID_AUTO, "role", CTLFLAG_RD, &mpt->role, 0, "HBA role"); #ifdef MPT_TEST_MULTIPATH - SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + SYSCTL_ADD_INT(&mpt->mpt_sysctl_ctx, + SYSCTL_CHILDREN(mpt->mpt_sysctl_tree), OID_AUTO, "failure_id", CTLFLAG_RW, &mpt->failure_id, -1, "Next Target to Fail"); #endif -#endif } int @@ -2249,13 +2246,6 @@ mpt_core_attach(struct mpt_softc *mpt) TAILQ_INIT(&mpt->request_pending_list); TAILQ_INIT(&mpt->request_free_list); TAILQ_INIT(&mpt->request_timeout_list); - MPT_LOCK(mpt); - for (val = 0; val < MPT_MAX_REQUESTS(mpt); val++) { - request_t *req = &mpt->request_pool[val]; - req->state = REQ_STATE_ALLOCATED; - mpt_free_request(mpt, req); - } - MPT_UNLOCK(mpt); for (val = 0; val < MPT_MAX_LUNS; val++) { STAILQ_INIT(&mpt->trt[val].atios); STAILQ_INIT(&mpt->trt[val].inots); @@ -2266,6 +2256,14 @@ mpt_core_attach(struct mpt_softc *mpt) mpt->failure_id = -1; #endif mpt->scsi_tgt_handler_id = MPT_HANDLER_ID_NONE; + sysctl_ctx_init(&mpt->mpt_sysctl_ctx); + mpt->mpt_sysctl_tree = SYSCTL_ADD_NODE(&mpt->mpt_sysctl_ctx, + SYSCTL_STATIC_CHILDREN(_hw), OID_AUTO, + device_get_nameunit(mpt->dev), CTLFLAG_RD, 0, ""); + if (mpt->mpt_sysctl_tree == NULL) { + device_printf(mpt->dev, "can't add sysctl node\n"); + return (EINVAL); + } mpt_sysctl_attach(mpt); mpt_lprt(mpt, MPT_PRT_DEBUG, "doorbell req = %s\n", mpt_ioc_diag(mpt_read(mpt, MPT_OFFSET_DOORBELL))); @@ -2336,16 +2334,29 @@ mpt_core_shutdown(struct mpt_softc *mpt) void mpt_core_detach(struct mpt_softc *mpt) { + int val; + /* * XXX: FREE MEMORY */ mpt_disable_ints(mpt); + + /* Make sure no request has pending timeouts. */ + for (val = 0; val < MPT_MAX_REQUESTS(mpt); val++) { + request_t *req = &mpt->request_pool[val]; + callout_stop(&req->callout); + } + + mpt_dma_buf_free(mpt); + + if (mpt->mpt_sysctl_tree != NULL) + sysctl_ctx_free(&mpt->mpt_sysctl_ctx); } int mpt_core_unload(struct mpt_personality *pers) { - /* Unload is always successfull. */ + /* Unload is always successful. */ return (0); } @@ -2363,7 +2374,7 @@ mpt_upload_fw(struct mpt_softc *mpt) SGE_SIMPLE32 *sge; uint32_t flags; int error; - + memset(&fw_req_buf, 0, sizeof(fw_req_buf)); fw_req = (MSG_FW_UPLOAD *)fw_req_buf; fw_req->ImageType = MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM; @@ -2380,10 +2391,12 @@ mpt_upload_fw(struct mpt_softc *mpt) flags <<= MPI_SGE_FLAGS_SHIFT; sge->FlagsLength = htole32(flags | mpt->fw_image_size); sge->Address = htole32(mpt->fw_phys); + bus_dmamap_sync(mpt->fw_dmat, mpt->fw_dmap, BUS_DMASYNC_PREREAD); error = mpt_send_handshake_cmd(mpt, sizeof(fw_req_buf), &fw_req_buf); if (error) return(error); error = mpt_recv_handshake_reply(mpt, sizeof(fw_reply), &fw_reply); + bus_dmamap_sync(mpt->fw_dmat, mpt->fw_dmap, BUS_DMASYNC_POSTREAD); return (error); } @@ -2428,8 +2441,10 @@ mpt_download_fw(struct mpt_softc *mpt) MPI_DIAG_RW_ENABLE|MPI_DIAG_DISABLE_ARM); fw_hdr = (MpiFwHeader_t *)mpt->fw_image; + bus_dmamap_sync(mpt->fw_dmat, mpt->fw_dmap, BUS_DMASYNC_PREWRITE); mpt_diag_outsl(mpt, fw_hdr->LoadStartAddress, (uint32_t*)fw_hdr, fw_hdr->ImageSize); + bus_dmamap_sync(mpt->fw_dmat, mpt->fw_dmap, BUS_DMASYNC_POSTWRITE); ext_offset = fw_hdr->NextImageHeaderOffset; while (ext_offset != 0) { @@ -2437,9 +2452,12 @@ mpt_download_fw(struct mpt_softc *mpt) ext = (MpiExtImageHeader_t *)((uintptr_t)fw_hdr + ext_offset); ext_offset = ext->NextImageHeaderOffset; - + bus_dmamap_sync(mpt->fw_dmat, mpt->fw_dmap, + BUS_DMASYNC_PREWRITE); mpt_diag_outsl(mpt, ext->LoadStartAddress, (uint32_t*)ext, ext->ImageSize); + bus_dmamap_sync(mpt->fw_dmat, mpt->fw_dmap, + BUS_DMASYNC_POSTWRITE); } if (mpt->is_sas) { @@ -2474,6 +2492,105 @@ mpt_download_fw(struct mpt_softc *mpt) return (0); } +static int +mpt_dma_buf_alloc(struct mpt_softc *mpt) +{ + struct mpt_map_info mi; + uint8_t *vptr; + uint32_t pptr, end; + int i, error; + + /* Create a child tag for data buffers */ + if (mpt_dma_tag_create(mpt, mpt->parent_dmat, 1, + 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, + NULL, NULL, (mpt->max_cam_seg_cnt - 1) * PAGE_SIZE, + mpt->max_cam_seg_cnt, BUS_SPACE_MAXSIZE_32BIT, 0, + &mpt->buffer_dmat) != 0) { + mpt_prt(mpt, "cannot create a dma tag for data buffers\n"); + return (1); + } + + /* Create a child tag for request buffers */ + if (mpt_dma_tag_create(mpt, mpt->parent_dmat, PAGE_SIZE, 0, + BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, + NULL, NULL, MPT_REQ_MEM_SIZE(mpt), 1, BUS_SPACE_MAXSIZE_32BIT, 0, + &mpt->request_dmat) != 0) { + mpt_prt(mpt, "cannot create a dma tag for requests\n"); + return (1); + } + + /* Allocate some DMA accessible memory for requests */ + if (bus_dmamem_alloc(mpt->request_dmat, (void **)&mpt->request, + BUS_DMA_NOWAIT | BUS_DMA_COHERENT, &mpt->request_dmap) != 0) { + mpt_prt(mpt, "cannot allocate %d bytes of request memory\n", + MPT_REQ_MEM_SIZE(mpt)); + return (1); + } + + mi.mpt = mpt; + mi.error = 0; + + /* Load and lock it into "bus space" */ + bus_dmamap_load(mpt->request_dmat, mpt->request_dmap, mpt->request, + MPT_REQ_MEM_SIZE(mpt), mpt_map_rquest, &mi, 0); + + if (mi.error) { + mpt_prt(mpt, "error %d loading dma map for DMA request queue\n", + mi.error); + return (1); + } + mpt->request_phys = mi.phys; + + /* + * Now create per-request dma maps + */ + i = 0; + pptr = mpt->request_phys; + vptr = mpt->request; + end = pptr + MPT_REQ_MEM_SIZE(mpt); + while(pptr < end) { + request_t *req = &mpt->request_pool[i]; + req->index = i++; + + /* Store location of Request Data */ + req->req_pbuf = pptr; + req->req_vbuf = vptr; + + pptr += MPT_REQUEST_AREA; + vptr += MPT_REQUEST_AREA; + + req->sense_pbuf = (pptr - MPT_SENSE_SIZE); + req->sense_vbuf = (vptr - MPT_SENSE_SIZE); + + error = bus_dmamap_create(mpt->buffer_dmat, 0, &req->dmap); + if (error) { + mpt_prt(mpt, "error %d creating per-cmd DMA maps\n", + error); + return (1); + } + } + + return (0); +} + +static void +mpt_dma_buf_free(struct mpt_softc *mpt) +{ + int i; + if (mpt->request_dmat == 0) { + mpt_lprt(mpt, MPT_PRT_DEBUG, "already released dma memory\n"); + return; + } + for (i = 0; i < MPT_MAX_REQUESTS(mpt); i++) { + bus_dmamap_destroy(mpt->buffer_dmat, mpt->request_pool[i].dmap); + } + bus_dmamap_unload(mpt->request_dmat, mpt->request_dmap); + bus_dmamem_free(mpt->request_dmat, mpt->request, mpt->request_dmap); + bus_dma_tag_destroy(mpt->request_dmat); + mpt->request_dmat = 0; + bus_dma_tag_destroy(mpt->buffer_dmat); +} + /* * Allocate/Initialize data structures for the controller. Called * once at instance startup. @@ -2482,7 +2599,7 @@ static int mpt_configure_ioc(struct mpt_softc *mpt, int tn, int needreset) { PTR_MSG_PORT_FACTS_REPLY pfp; - int error, port; + int error, port, val; size_t len; if (tn == MPT_MAX_TRYS) { @@ -2542,7 +2659,7 @@ mpt_configure_ioc(struct mpt_softc *mpt, int tn, int needreset) /* limited by the number of chain areas the card will support */ if (mpt->max_seg_cnt > mpt->ioc_facts.MaxChainDepth) { - mpt_lprt(mpt, MPT_PRT_DEBUG, + mpt_lprt(mpt, MPT_PRT_INFO, "chain depth limited to %u (from %u)\n", mpt->ioc_facts.MaxChainDepth, mpt->max_seg_cnt); mpt->max_seg_cnt = mpt->ioc_facts.MaxChainDepth; @@ -2551,19 +2668,39 @@ mpt_configure_ioc(struct mpt_softc *mpt, int tn, int needreset) /* converted to the number of simple sges in chain segments. */ mpt->max_seg_cnt *= (MPT_NSGL(mpt) - 1); - mpt_lprt(mpt, MPT_PRT_DEBUG, "Maximum Segment Count: %u\n", - mpt->max_seg_cnt); - mpt_lprt(mpt, MPT_PRT_DEBUG, "MsgLength=%u IOCNumber = %d\n", + /* + * Use this as the basis for reporting the maximum I/O size to CAM. + */ + mpt->max_cam_seg_cnt = min(mpt->max_seg_cnt, (MAXPHYS / PAGE_SIZE) + 1); + + error = mpt_dma_buf_alloc(mpt); + if (error != 0) { + mpt_prt(mpt, "mpt_dma_buf_alloc() failed!\n"); + return (EIO); + } + + for (val = 0; val < MPT_MAX_REQUESTS(mpt); val++) { + request_t *req = &mpt->request_pool[val]; + req->state = REQ_STATE_ALLOCATED; + mpt_callout_init(mpt, &req->callout); + mpt_free_request(mpt, req); + } + + mpt_lprt(mpt, MPT_PRT_INFO, "Maximum Segment Count: %u, Maximum " + "CAM Segment Count: %u\n", mpt->max_seg_cnt, + mpt->max_cam_seg_cnt); + + mpt_lprt(mpt, MPT_PRT_INFO, "MsgLength=%u IOCNumber = %d\n", mpt->ioc_facts.MsgLength, mpt->ioc_facts.IOCNumber); - mpt_lprt(mpt, MPT_PRT_DEBUG, + mpt_lprt(mpt, MPT_PRT_INFO, "IOCFACTS: GlobalCredits=%d BlockSize=%u bytes " "Request Frame Size %u bytes Max Chain Depth %u\n", mpt->ioc_facts.GlobalCredits, mpt->ioc_facts.BlockSize, mpt->ioc_facts.RequestFrameSize << 2, mpt->ioc_facts.MaxChainDepth); - mpt_lprt(mpt, MPT_PRT_DEBUG, "IOCFACTS: Num Ports %d, FWImageSize %d, " + mpt_lprt(mpt, MPT_PRT_INFO, "IOCFACTS: Num Ports %d, FWImageSize %d, " "Flags=%#x\n", mpt->ioc_facts.NumberOfPorts, - (int)mpt->ioc_facts.FWImageSize, mpt->ioc_facts.Flags); + mpt->ioc_facts.FWImageSize, mpt->ioc_facts.Flags); len = mpt->ioc_facts.NumberOfPorts * sizeof (MSG_PORT_FACTS_REPLY); mpt->port_facts = kmalloc(len, M_DEVBUF, M_NOWAIT | M_ZERO); @@ -2580,7 +2717,7 @@ mpt_configure_ioc(struct mpt_softc *mpt, int tn, int needreset) /* * In some configurations, the IOC's firmware is * stored in a shared piece of system NVRAM that - * is only accessable via the BIOS. In this + * is only accessible via the BIOS. In this * case, the firmware keeps a copy of firmware in * RAM until the OS driver retrieves it. Once * retrieved, we are responsible for re-downloading @@ -2592,11 +2729,12 @@ mpt_configure_ioc(struct mpt_softc *mpt, int tn, int needreset) mpt->fw_image_size, 1, mpt->fw_image_size, 0, &mpt->fw_dmat); if (error != 0) { - mpt_prt(mpt, "cannot create firmwarew dma tag\n"); + mpt_prt(mpt, "cannot create firmware dma tag\n"); return (ENOMEM); } error = bus_dmamem_alloc(mpt->fw_dmat, - (void **)&mpt->fw_image, BUS_DMA_NOWAIT, &mpt->fw_dmap); + (void **)&mpt->fw_image, BUS_DMA_NOWAIT | + BUS_DMA_COHERENT, &mpt->fw_dmap); if (error != 0) { mpt_prt(mpt, "cannot allocate firmware memory\n"); bus_dma_tag_destroy(mpt->fw_dmat); @@ -2661,6 +2799,8 @@ mpt_configure_ioc(struct mpt_softc *mpt, int tn, int needreset) mpt->is_fc = 0; mpt->is_sas = 0; mpt->is_spi = 1; + if (mpt->mpt_ini_id == MPT_INI_ID_NONE) + mpt->mpt_ini_id = pfp->PortSCSIID; } else if (pfp->PortType == MPI_PORTFACTS_PORTTYPE_ISCSI) { mpt_prt(mpt, "iSCSI not supported yet\n"); return (ENXIO); @@ -2749,7 +2889,7 @@ mpt_enable_ioc(struct mpt_softc *mpt, int portenable) mpt_send_event_request(mpt, 1); if (mpt_send_port_enable(mpt, 0) != MPT_OK) { - mpt_prt(mpt, "failed to enable port 0\n"); + mpt_prt(mpt, "%s: failed to enable port 0\n", __func__); return (ENXIO); } } diff --git a/sys/dev/disk/mpt/mpt.h b/sys/dev/disk/mpt/mpt.h index 1df6a7170e..67dbc17570 100644 --- a/sys/dev/disk/mpt/mpt.h +++ b/sys/dev/disk/mpt/mpt.h @@ -1,4 +1,4 @@ -/* $FreeBSD: src/sys/dev/mpt/mpt.h,v 1.48 2009/07/10 08:18:08 scottl Exp $ */ +/* $FreeBSD: src/sys/dev/mpt/mpt.h,v 1.55 2011/04/22 09:59:16 marius Exp $ */ /*- * Generic defines for LSI '909 FC adapters. * FreeBSD Version. @@ -105,28 +105,21 @@ #include #include #include - #include #include #include #include - #include #include #include - #include #include #include +#include -#if __FreeBSD_version < 500000 #include #include -#else -#include -#include -#endif #include "opt_ddb.h" @@ -159,6 +152,8 @@ #define MPT_ROLE_BOTH 3 #define MPT_ROLE_DEFAULT MPT_ROLE_INITIATOR +#define MPT_INI_ID_NONE -1 + /**************************** Forward Declarations ****************************/ struct mpt_softc; struct mpt_personality; @@ -218,20 +213,6 @@ int mpt_modevent(module_t, int, void *); #define bus_dmamap_sync_range(dma_tag, dmamap, offset, len, op) \ bus_dmamap_sync(dma_tag, dmamap, op) -#if __FreeBSD_version < 600000 -#define bus_get_dma_tag(x) NULL -#endif -#if __FreeBSD_version >= 501102 -#define mpt_dma_tag_create(mpt, parent_tag, alignment, boundary, \ - lowaddr, highaddr, filter, filterarg, \ - maxsize, nsegments, maxsegsz, flags, \ - dma_tagp) \ - bus_dma_tag_create(parent_tag, alignment, boundary, \ - lowaddr, highaddr, filter, filterarg, \ - maxsize, nsegments, maxsegsz, flags, \ - busdma_lock_mutex, &(mpt)->mpt_lock, \ - dma_tagp) -#else #define mpt_dma_tag_create(mpt, parent_tag, alignment, boundary, \ lowaddr, highaddr, filter, filterarg, \ maxsize, nsegments, maxsegsz, flags, \ @@ -240,7 +221,6 @@ int mpt_modevent(module_t, int, void *); lowaddr, highaddr, filter, filterarg, \ maxsize, nsegments, maxsegsz, flags, \ dma_tagp) -#endif struct mpt_map_info { struct mpt_softc *mpt; @@ -250,50 +230,18 @@ struct mpt_map_info { void mpt_map_rquest(void *, bus_dma_segment_t *, int, int); /* **************************** NewBUS interrupt Crock ************************/ -#ifdef __DragonFly__ -#define mpt_setup_intr(d, i, f, U, if, ifa, hp) \ - bus_setup_intr(d, i, f, if, ifa, hp, NULL) -#else -#if __FreeBSD_version < 700031 #define mpt_setup_intr(d, i, f, U, if, ifa, hp) \ - bus_setup_intr(d, i, f, if, ifa, hp) -#else -#define mpt_setup_intr bus_setup_intr -#endif -#endif + bus_setup_intr(d, i, f, if, ifa, hp, NULL) /* **************************** NewBUS CAM Support ****************************/ -#if __FreeBSD_version < 700049 #define mpt_xpt_bus_register(sim, parent, bus) \ xpt_bus_register(sim, bus) -#else -#define mpt_xpt_bus_register xpt_bus_register -#endif /**************************** Kernel Thread Support ***************************/ -#if __FreeBSD_version > 800001 -#define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ - kproc_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) -#define mpt_kthread_exit(status) \ - kproc_exit(status) -#elif __FreeBSD_version > 500005 -#define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ - kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) -#define mpt_kthread_exit(status) \ - kthread_exit(status) -#else #define mpt_kthread_create(func, farg, proc_ptr, flags, stackpgs, fmtstr, arg) \ kthread_create(func, farg, proc_ptr, fmtstr, arg) #define mpt_kthread_exit(status) \ kthread_exit() -#endif - -/****************************** Timer Facilities ******************************/ -#if __FreeBSD_version > 500000 -#define mpt_callout_init(c) callout_init(c, /*mpsafe*/1); -#else -#define mpt_callout_init(c) callout_init(c); -#endif /********************************** Endianess *********************************/ #define MPT_2_HOST64(ptr, tag) ptr->tag = le64toh(ptr->tag) @@ -363,7 +311,7 @@ struct req_entry { mpt_req_state_t state; /* Request State Information */ uint16_t index; /* Index of this entry */ uint16_t IOCStatus; /* Completion status */ - uint16_t ResponseCode; /* TMF Reponse Code */ + uint16_t ResponseCode; /* TMF Response Code */ uint16_t serno; /* serial number */ union ccb *ccb; /* CAM request */ void *req_vbuf; /* Virtual Address of Entry */ @@ -591,13 +539,8 @@ struct mptsas_portinfo { struct mpt_softc { device_t dev; -#if __FreeBSD_version < 500000 - uint32_t mpt_islocked; - int mpt_splsaved; -#else - struct mtx mpt_lock; + struct lock mpt_lock; int mpt_locksetup; -#endif uint32_t mpt_pers_mask; uint32_t : 8, @@ -636,7 +579,6 @@ struct mpt_softc { * Port Facts */ MSG_PORT_FACTS_REPLY * port_facts; -#define mpt_ini_id port_facts[0].PortSCSIID #define mpt_max_tgtcmds port_facts[0].MaxPostedCmdBuffers /* @@ -649,6 +591,7 @@ struct mpt_softc { CONFIG_PAGE_SCSI_PORT_2 _port_page2; CONFIG_PAGE_SCSI_DEVICE_0 _dev_page0[16]; CONFIG_PAGE_SCSI_DEVICE_1 _dev_page1[16]; + int _ini_id; uint16_t _tag_enable; uint16_t _disc_enable; } spi; @@ -657,6 +600,7 @@ struct mpt_softc { #define mpt_port_page2 cfg.spi._port_page2 #define mpt_dev_page0 cfg.spi._dev_page0 #define mpt_dev_page1 cfg.spi._dev_page1 +#define mpt_ini_id cfg.spi._ini_id #define mpt_tag_enable cfg.spi._tag_enable #define mpt_disc_enable cfg.spi._disc_enable struct mpi_fc_cfg { @@ -666,7 +610,6 @@ struct mpt_softc { #define mpt_fcport_speed cfg.fc._port_speed } fc; } cfg; -#if __FreeBSD_version >= 500000 /* * Device config information stored up for sysctl to access */ @@ -679,7 +622,6 @@ struct mpt_softc { char wwpn[19]; } fc; } scinfo; -#endif /* Controller Info for RAID information */ CONFIG_PAGE_IOC_2 * ioc_page2; @@ -705,7 +647,7 @@ struct mpt_softc { */ int pci_msi_count; struct resource * pci_irq; /* Interrupt map for chip */ - void * ih; /* Interupt handle */ + void * ih; /* Interrupt handle */ struct mpt_pci_cfg pci_cfg; /* saved PCI conf registers */ /* @@ -734,6 +676,7 @@ struct mpt_softc { bus_addr_t request_phys; /* BusAddr of request memory */ uint32_t max_seg_cnt; /* calculated after IOC facts */ + uint32_t max_cam_seg_cnt;/* calculated from MAXPHYS*/ /* * Hardware management @@ -805,6 +748,9 @@ struct mpt_softc { /* Userland management interface. */ struct cdev *cdev; + struct sysctl_ctx_list mpt_sysctl_ctx; + struct sysctl_oid *mpt_sysctl_tree; + TAILQ_ENTRY(mpt_softc) links; }; @@ -819,150 +765,29 @@ mpt_assign_serno(struct mpt_softc *mpt, request_t *req) } /***************************** Locking Primitives *****************************/ -#ifdef __DragonFly__ -#define PUSER 0 -#define MPT_IFLAGS 0 -#define MPT_LOCK(mpt) crit_enter() -#define MPT_UNLOCK(mpt) crit_exit() -#define MPT_LOCK_SETUP(mpt) do { } while(0) -#define MPT_LOCK_DESTROY(mpt) do { } while(0) -#define MPT_LOCK_ASSERT(mpt) do { } while(0) -#define MPTLOCK_2_CAMLOCK MPT_UNLOCK -#define CAMLOCK_2_MPTLOCK MPT_LOCK -#define splx(s) -#define splsoftvm() 0 -static __inline int -mpt_sleep(struct mpt_softc *mpt, void *ident, int priority, - const char *wmesg, int timo) { - int error; - error = tsleep(ident, 0, wmesg, timo); - return(error); -} -#endif -#define mpt_req_timeout(req, ticks, func, arg) \ - callout_reset(&(req)->callout, (ticks), (func), (arg)); -#define mpt_req_untimeout(req, func, arg) \ - callout_stop(&(req)->callout) -#if 0 -#if __FreeBSD_version < 500000 -#define MPT_IFLAGS INTR_TYPE_CAM -#define MPT_LOCK(mpt) mpt_lockspl(mpt) -#define MPT_UNLOCK(mpt) mpt_unlockspl(mpt) -#define MPT_OWNED(mpt) mpt->mpt_islocked -#define MPT_LOCK_ASSERT(mpt) -#define MPTLOCK_2_CAMLOCK MPT_UNLOCK -#define CAMLOCK_2_MPTLOCK MPT_LOCK -#define MPT_LOCK_SETUP(mpt) -#define MPT_LOCK_DESTROY(mpt) - -static __inline void mpt_lockspl(struct mpt_softc *mpt); -static __inline void mpt_unlockspl(struct mpt_softc *mpt); - -static __inline void -mpt_lockspl(struct mpt_softc *mpt) -{ - int s; - - s = splcam(); - if (mpt->mpt_islocked++ == 0) { - mpt->mpt_splsaved = s; - } else { - splx(s); - panic("Recursed lock with mask: 0x%x\n", s); - } -} - -static __inline void -mpt_unlockspl(struct mpt_softc *mpt) -{ - if (mpt->mpt_islocked) { - if (--mpt->mpt_islocked == 0) { - splx(mpt->mpt_splsaved); - } - } else - panic("Negative lock count\n"); -} - -static __inline int -mpt_sleep(struct mpt_softc *mpt, void *ident, int priority, - const char *wmesg, int timo) -{ - int saved_cnt; - int saved_spl; - int error; - - KASSERT(mpt->mpt_islocked <= 1, ("Invalid lock count on tsleep")); - saved_cnt = mpt->mpt_islocked; - saved_spl = mpt->mpt_splsaved; - mpt->mpt_islocked = 0; - error = tsleep(ident, priority, wmesg, timo); - KASSERT(mpt->mpt_islocked == 0, ("Invalid lock count on wakeup")); - mpt->mpt_islocked = saved_cnt; - mpt->mpt_splsaved = saved_spl; - return (error); -} - -#define mpt_req_timeout(req, ticks, func, arg) \ - callout_reset(&(req)->callout, (ticks), (func), (arg)); -#define mpt_req_untimeout(req, func, arg) \ - callout_stop(&(req)->callout) -#else -#if 1 -#define MPT_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY | INTR_MPSAFE #define MPT_LOCK_SETUP(mpt) \ - mtx_init(&mpt->mpt_lock, "mpt", NULL, MTX_DEF); \ + lockinit(&mpt->mpt_lock, "mpt", 0, LK_CANRECURSE); \ mpt->mpt_locksetup = 1 #define MPT_LOCK_DESTROY(mpt) \ if (mpt->mpt_locksetup) { \ - mtx_destroy(&mpt->mpt_lock); \ + lockuninit(&mpt->mpt_lock); \ mpt->mpt_locksetup = 0; \ } -#define MPT_LOCK(mpt) mtx_lock(&(mpt)->mpt_lock) -#define MPT_UNLOCK(mpt) mtx_unlock(&(mpt)->mpt_lock) -#define MPT_OWNED(mpt) mtx_owned(&(mpt)->mpt_lock) -#define MPT_LOCK_ASSERT(mpt) mtx_assert(&(mpt)->mpt_lock, MA_OWNED) +#define MPT_LOCK(mpt) lockmgr(&(mpt)->mpt_lock, LK_EXCLUSIVE) +#define MPT_UNLOCK(mpt) lockmgr(&(mpt)->mpt_lock, LK_RELEASE) +#define MPT_OWNED(mpt) lockstatus(&(mpt)->mpt_lock, curthread) +#define MPT_LOCK_ASSERT(mpt) KKASSERT(lockstatus(&(mpt)->mpt_lock, curthread) != 0) #define MPTLOCK_2_CAMLOCK(mpt) #define CAMLOCK_2_MPTLOCK(mpt) #define mpt_sleep(mpt, ident, priority, wmesg, timo) \ - msleep(ident, &(mpt)->mpt_lock, priority, wmesg, timo) + lksleep(ident, &(mpt)->mpt_lock, priority, wmesg, timo) #define mpt_req_timeout(req, ticks, func, arg) \ - callout_reset(&(req)->callout, (ticks), (func), (arg)); + callout_reset(&(req)->callout, (ticks), (func), (arg)) #define mpt_req_untimeout(req, func, arg) \ callout_stop(&(req)->callout) -#else - -#define MPT_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY -#define MPT_LOCK_SETUP(mpt) do { } while (0) -#define MPT_LOCK_DESTROY(mpt) do { } while (0) -#define MPT_LOCK_ASSERT(mpt) mtx_assert(&Giant, MA_OWNED) -#define MPT_LOCK(mpt) mtx_lock(&Giant) -#define MPT_UNLOCK(mpt) mtx_unlock(&Giant) -#define MPTLOCK_2_CAMLOCK(mpt) -#define CAMLOCK_2_MPTLOCK(mpt) - -static __inline int -mpt_sleep(struct mpt_softc *, void *, int, const char *, int); - -#define mpt_ccb_timeout(ccb, ticks, func, arg) \ - do { \ - (ccb)->ccb_h.timeout_ch = timeout((func), (arg), (ticks)); \ - } while (0) -#define mpt_ccb_untimeout(ccb, func, arg) \ - untimeout((func), (arg), (ccb)->ccb_h.timeout_ch) -#define mpt_ccb_timeout_init(ccb) \ - callout_handle_init(&(ccb)->ccb_h.timeout_ch) - -static __inline int -mpt_sleep(struct mpt_softc *mpt, void *i, int p, const char *w, int t) -{ - int r; - r = tsleep(i, p, w, t); - return (r); -} -#endif -#endif -#endif +#define mpt_callout_init(mpt, c) \ + callout_init(c) /******************************* Register Access ******************************/ static __inline void mpt_write(struct mpt_softc *, size_t, uint32_t); @@ -1002,9 +827,6 @@ mpt_pio_read(struct mpt_softc *mpt, int offset) /* Max MPT Reply we are willing to accept (must be power of 2) */ #define MPT_REPLY_SIZE 256 -/* Max i/o size, based on legacy MAXPHYS. Can be increased. */ -#define MPT_MAXPHYS (128 * 1024) - /* * Must be less than 16384 in order for target mode to work */ @@ -1061,7 +883,7 @@ mpt_pop_reply_queue(struct mpt_softc *mpt) void mpt_complete_request_chain(struct mpt_softc *, struct req_queue *, u_int); -/************************** Scatter Gather Managment **************************/ +/************************** Scatter Gather Management **************************/ /* MPT_RQSL- size of request frame, in bytes */ #define MPT_RQSL(mpt) (mpt->ioc_facts.RequestFrameSize << 2) @@ -1114,24 +936,17 @@ enum { MPT_PRT_NONE=100 }; -#if __FreeBSD_version > 500000 #define mpt_lprt(mpt, level, ...) \ do { \ if (level <= (mpt)->verbose) \ mpt_prt(mpt, __VA_ARGS__); \ } while (0) -#define mpt_lprtc(mpt, level, ...) \ -do { \ - if (level <= (mpt)->debug_level) \ - mpt_prtc(mpt, __VA_ARGS__); \ +#define mpt_lprtc(mpt, level, ...) \ +do { \ + if (level <= (mpt)->verbose) \ + mpt_prtc(mpt, __VA_ARGS__); \ } while (0) -#else -void mpt_lprt(struct mpt_softc *, int, const char *, ...) - __printflike(3, 4); -void mpt_lprtc(struct mpt_softc *, int, const char *, ...) - __printflike(3, 4); -#endif void mpt_prt(struct mpt_softc *, const char *, ...) __printflike(2, 3); void mpt_prtc(struct mpt_softc *, const char *, ...) @@ -1166,19 +981,13 @@ mpt_tag_2_req(struct mpt_softc *mpt, uint32_t tag) KASSERT(mpt->tgt_cmd_ptrs[rtg], ("no cmd backpointer")); return (mpt->tgt_cmd_ptrs[rtg]); } - +#endif static __inline int mpt_req_on_free_list(struct mpt_softc *, request_t *); static __inline int mpt_req_on_pending_list(struct mpt_softc *, request_t *); -static __inline void -mpt_req_spcl(struct mpt_softc *, request_t *, const char *, int); -static __inline void -mpt_req_not_spcl(struct mpt_softc *, request_t *, const char *, int); - - /* * Is request on freelist? */ @@ -1211,6 +1020,12 @@ mpt_req_on_pending_list(struct mpt_softc *mpt, request_t *req) return (0); } +#ifdef INVARIANTS +static __inline void +mpt_req_spcl(struct mpt_softc *, request_t *, const char *, int); +static __inline void +mpt_req_not_spcl(struct mpt_softc *, request_t *, const char *, int); + /* * Make sure that req *is* part of one of the special lists */ diff --git a/sys/dev/disk/mpt/mpt_cam.c b/sys/dev/disk/mpt/mpt_cam.c index 92f78bb22d..2b8a37be91 100644 --- a/sys/dev/disk/mpt/mpt_cam.c +++ b/sys/dev/disk/mpt/mpt_cam.c @@ -93,7 +93,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/sys/dev/mpt/mpt_cam.c,v 1.68 2009/07/02 00:43:10 delphij Exp $ + * $FreeBSD: src/sys/dev/mpt/mpt_cam.c,v 1.77 2011/04/22 09:59:16 marius Exp $ */ #include @@ -105,17 +105,13 @@ #include "dev/disk/mpt/mpilib/mpi_targ.h" #include "dev/disk/mpt/mpilib/mpi_fc.h" #include "dev/disk/mpt/mpilib/mpi_sas.h" -#if __FreeBSD_version >= 500000 #include -#endif #include #include -#if __FreeBSD_version >= 700025 || defined(__DragonFly__) #ifndef CAM_NEW_TRAN_CODE #define CAM_NEW_TRAN_CODE 1 #endif -#endif static void mpt_poll(struct cam_sim *); static timeout_t mpt_timeout; @@ -468,38 +464,35 @@ mpt_read_config_info_fc(struct mpt_softc *mpt) mpt_lprt(mpt, MPT_PRT_INFO, "FC Port Page 0: Topology <%s> WWNN 0x%08x%08x WWPN 0x%08x%08x " "Speed %u-Gbit\n", topology, - (unsigned)mpt->mpt_fcport_page0.WWNN.High, - (unsigned)mpt->mpt_fcport_page0.WWNN.Low, - (unsigned)mpt->mpt_fcport_page0.WWPN.High, - (unsigned)mpt->mpt_fcport_page0.WWPN.Low, - (unsigned)mpt->mpt_fcport_speed); -#if __FreeBSD_version >= 500000 + mpt->mpt_fcport_page0.WWNN.High, + mpt->mpt_fcport_page0.WWNN.Low, + mpt->mpt_fcport_page0.WWPN.High, + mpt->mpt_fcport_page0.WWPN.Low, + mpt->mpt_fcport_speed); MPT_UNLOCK(mpt); { - struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(mpt->dev); - struct sysctl_oid *tree = device_get_sysctl_tree(mpt->dev); - - snprintf(mpt->scinfo.fc.wwnn, + ksnprintf(mpt->scinfo.fc.wwnn, sizeof (mpt->scinfo.fc.wwnn), "0x%08x%08x", mpt->mpt_fcport_page0.WWNN.High, mpt->mpt_fcport_page0.WWNN.Low); - snprintf(mpt->scinfo.fc.wwpn, + ksnprintf(mpt->scinfo.fc.wwpn, sizeof (mpt->scinfo.fc.wwpn), "0x%08x%08x", mpt->mpt_fcport_page0.WWPN.High, mpt->mpt_fcport_page0.WWPN.Low); - SYSCTL_ADD_STRING(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + SYSCTL_ADD_STRING(&mpt->mpt_sysctl_ctx, + SYSCTL_CHILDREN(mpt->mpt_sysctl_tree), OID_AUTO, "wwnn", CTLFLAG_RD, mpt->scinfo.fc.wwnn, 0, "World Wide Node Name"); - SYSCTL_ADD_STRING(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + SYSCTL_ADD_STRING(&mpt->mpt_sysctl_ctx, + SYSCTL_CHILDREN(mpt->mpt_sysctl_tree), OID_AUTO, "wwpn", CTLFLAG_RD, mpt->scinfo.fc.wwpn, 0, "World Wide Port Name"); } MPT_LOCK(mpt); -#endif return (0); } @@ -983,8 +976,8 @@ mpt_read_config_info_spi(struct mpt_softc *mpt) mpt2host_config_page_scsi_port_0(&mpt->mpt_port_page0); mpt_lprt(mpt, MPT_PRT_NEGOTIATION, "SPI Port Page 0: Capabilities %x PhysicalInterface %x\n", - (unsigned)mpt->mpt_port_page0.Capabilities, - (unsigned)mpt->mpt_port_page0.PhysicalInterface); + mpt->mpt_port_page0.Capabilities, + mpt->mpt_port_page0.PhysicalInterface); } rv = mpt_read_cur_cfg_page(mpt, 0, &mpt->mpt_port_page1.Header, @@ -995,8 +988,8 @@ mpt_read_config_info_spi(struct mpt_softc *mpt) mpt2host_config_page_scsi_port_1(&mpt->mpt_port_page1); mpt_lprt(mpt, MPT_PRT_DEBUG, "SPI Port Page 1: Configuration %x OnBusTimerValue %x\n", - (unsigned)mpt->mpt_port_page1.Configuration, - (unsigned)mpt->mpt_port_page1.OnBusTimerValue); + mpt->mpt_port_page1.Configuration, + mpt->mpt_port_page1.OnBusTimerValue); } rv = mpt_read_cur_cfg_page(mpt, 0, &mpt->mpt_port_page2.Header, @@ -1006,8 +999,8 @@ mpt_read_config_info_spi(struct mpt_softc *mpt) } else { mpt_lprt(mpt, MPT_PRT_NEGOTIATION, "Port Page 2: Flags %x Settings %x\n", - (unsigned)mpt->mpt_port_page2.PortFlags, - (unsigned)mpt->mpt_port_page2.PortSettings); + mpt->mpt_port_page2.PortFlags, + mpt->mpt_port_page2.PortSettings); mpt2host_config_page_scsi_port_2(&mpt->mpt_port_page2); for (i = 0; i < 16; i++) { mpt_lprt(mpt, MPT_PRT_NEGOTIATION, @@ -1030,9 +1023,8 @@ mpt_read_config_info_spi(struct mpt_softc *mpt) mpt2host_config_page_scsi_device_0(&mpt->mpt_dev_page0[i]); mpt_lprt(mpt, MPT_PRT_NEGOTIATION, "target %d page 0: Negotiated Params %x Information %x\n", - i, - (unsigned)mpt->mpt_dev_page0[i].NegotiatedParameters, - (unsigned)mpt->mpt_dev_page0[i].Information); + i, mpt->mpt_dev_page0[i].NegotiatedParameters, + mpt->mpt_dev_page0[i].Information); rv = mpt_read_cur_cfg_page(mpt, i, &mpt->mpt_dev_page1[i].Header, sizeof(*mpt->mpt_dev_page1), @@ -1045,9 +1037,8 @@ mpt_read_config_info_spi(struct mpt_softc *mpt) mpt2host_config_page_scsi_device_1(&mpt->mpt_dev_page1[i]); mpt_lprt(mpt, MPT_PRT_NEGOTIATION, "target %d page 1: Requested Params %x Configuration %x\n", - i, - (unsigned)mpt->mpt_dev_page1[i].RequestedParameters, - (unsigned)mpt->mpt_dev_page1[i].Configuration); + i, mpt->mpt_dev_page1[i].RequestedParameters, + mpt->mpt_dev_page1[i].Configuration); } return (0); } @@ -1060,19 +1051,18 @@ mpt_read_config_info_spi(struct mpt_softc *mpt) static int mpt_set_initial_config_spi(struct mpt_softc *mpt) { - int i, pp1val = ((1 << mpt->mpt_ini_id) << 16) | mpt->mpt_ini_id; - int error; + int error, i, pp1val; mpt->mpt_disc_enable = 0xff; mpt->mpt_tag_enable = 0; + pp1val = ((1 << mpt->mpt_ini_id) << + MPI_SCSIPORTPAGE1_CFG_SHIFT_PORT_RESPONSE_ID) | mpt->mpt_ini_id; if (mpt->mpt_port_page1.Configuration != pp1val) { CONFIG_PAGE_SCSI_PORT_1 tmp; mpt_prt(mpt, "SPI Port Page 1 Config value bad (%x)- should " - "be %x\n", - (unsigned)mpt->mpt_port_page1.Configuration, - (unsigned)pp1val); + "be %x\n", mpt->mpt_port_page1.Configuration, pp1val); tmp = mpt->mpt_port_page1; tmp.Configuration = pp1val; host2mpt_config_page_scsi_port_1(&tmp); @@ -1208,7 +1198,6 @@ mpt_cam_detach(struct mpt_softc *mpt) kfree(mpt->sas_portinfo, M_DEVBUF); mpt->sas_portinfo = NULL; } - MPT_UNLOCK(mpt); if (mpt->sim != NULL) { xpt_free_path(mpt->path); @@ -1223,6 +1212,7 @@ mpt_cam_detach(struct mpt_softc *mpt) cam_sim_free(mpt->phydisk_sim); mpt->phydisk_sim = NULL; } + MPT_UNLOCK(mpt); } /* This routine is used after a system crash to dump core onto the swap device. @@ -1249,7 +1239,7 @@ mpt_timeout(void *arg) ccb = (union ccb *)arg; mpt = ccb->ccb_h.ccb_mpt_ptr; - MPT_LOCK(mpt); + MPT_LOCK_ASSERT(mpt); req = ccb->ccb_h.ccb_req_ptr; mpt_prt(mpt, "request %p:%u timed out for ccb %p (req->ccb %p)\n", req, req->serno, ccb, req->ccb); @@ -1260,7 +1250,6 @@ mpt_timeout(void *arg) req->state |= REQ_STATE_TIMEDOUT; mpt_wakeup_recovery_thread(mpt); } - MPT_UNLOCK(mpt); } /* @@ -2248,9 +2237,11 @@ mpt_start(struct cam_sim *sim, union ccb *ccb) * one or more physical address ranges. */ int error; + crit_enter(); error = bus_dmamap_load(mpt->buffer_dmat, req->dmap, csio->data_ptr, csio->dxfer_len, cb, req, 0); + crit_exit(); if (error == EINPROGRESS) { /* * So as to maintain ordering, @@ -2380,6 +2371,13 @@ mpt_fc_reset_link(struct mpt_softc *mpt, int dowait) return (r); } +static void +mpt_cam_rescan_callback(struct cam_periph *periph, union ccb *ccb) +{ + xpt_free_path(ccb->ccb_h.path); + kfree(ccb, M_TEMP); +} + static int mpt_cam_event(struct mpt_softc *mpt, request_t *req, MSG_EVENT_NOTIFY_REPLY *msg) @@ -2412,7 +2410,6 @@ mpt_cam_event(struct mpt_softc *mpt, request_t *req, break; case MPI_EVENT_RESCAN: -#if __FreeBSD_version >= 600000 { union ccb *ccb; uint32_t pathid; @@ -2433,28 +2430,27 @@ mpt_cam_event(struct mpt_softc *mpt, request_t *req, * Allocate a CCB, create a wildcard path for this bus, * and schedule a rescan. */ - ccb = xpt_alloc_ccb_nowait(); - if (ccb == NULL) { - mpt_prt(mpt, "unable to alloc CCB for rescan\n"); - CAMLOCK_2_MPTLOCK(mpt); - break; - } + ccb = kmalloc(sizeof(union ccb), M_TEMP, M_WAITOK | M_ZERO); if (xpt_create_path(&ccb->ccb_h.path, xpt_periph, pathid, CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { CAMLOCK_2_MPTLOCK(mpt); mpt_prt(mpt, "unable to create path for rescan\n"); - xpt_free_ccb(ccb); + kfree(ccb, M_TEMP); break; } - xpt_rescan(ccb); + + xpt_setup_ccb(&ccb->ccb_h, ccb->ccb_h.path, 5/*priority (low)*/); + ccb->ccb_h.func_code = XPT_SCAN_BUS; + ccb->ccb_h.cbfcnp = mpt_cam_rescan_callback; + ccb->crcn.flags = CAM_FLAG_NONE; + xpt_action(ccb); + + /* scan is now in progress */ + CAMLOCK_2_MPTLOCK(mpt); break; } -#else - mpt_prt(mpt, "Rescan Port: %d\n", (data0 >> 8) & 0xff); - break; -#endif case MPI_EVENT_LINK_STATUS_CHANGE: mpt_prt(mpt, "Port %d: LinkState: %s\n", (data1 >> 8) & 0xff, @@ -2555,6 +2551,7 @@ mpt_cam_event(struct mpt_softc *mpt, request_t *req, } xpt_setup_ccb(&crs.ccb_h, tmppath, 5); crs.ccb_h.func_code = XPT_REL_SIMQ; + crs.ccb_h.flags = CAM_DEV_QFREEZE; crs.release_flags = RELSIM_ADJUST_OPENINGS; crs.openings = pqf->CurrentDepth - 1; xpt_action((union ccb *)&crs); @@ -2566,6 +2563,10 @@ mpt_cam_event(struct mpt_softc *mpt, request_t *req, CAMLOCK_2_MPTLOCK(mpt); break; } + case MPI_EVENT_IR_RESYNC_UPDATE: + mpt_prt(mpt, "IR resync update %d completed\n", + (data0 >> 16) & 0xff); + break; case MPI_EVENT_EVENT_CHANGE: case MPI_EVENT_INTEGRATED_RAID: case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE: @@ -2573,7 +2574,7 @@ mpt_cam_event(struct mpt_softc *mpt, request_t *req, break; default: mpt_lprt(mpt, MPT_PRT_WARN, "mpt_cam_event: 0x%x\n", - (unsigned)msg->Event & 0xFF); + msg->Event & 0xFF); return (0); } return (1); @@ -2962,7 +2963,7 @@ mpt_fc_els_reply_handler(struct mpt_softc *mpt, request_t *req, } if (tgt_req) { mpt_tgt_state_t *tgt = MPT_TGT_STATE(mpt, tgt_req); - union ccb *ccb = tgt->ccb; + union ccb *ccb; uint32_t ct_id; /* @@ -3006,7 +3007,7 @@ mpt_fc_els_reply_handler(struct mpt_softc *mpt, request_t *req, elsbuf[1] = htobe32((ox_id << 16) | rx_id); elsbuf[2] = htobe32(0x000ffff); /* - * Dork with the reply frame so that the reponse to it + * Dork with the reply frame so that the response to it * will be correct. */ rp->Rctl_Did += ((BA_ACC - ABTS) << MPI_FC_RCTL_SHIFT); @@ -3133,7 +3134,7 @@ XXXX mpt_set_ccb_status(ccb, CAM_AUTOSENSE_FAIL); } else if ((sstate & MPI_SCSI_STATE_RESPONSE_INFO_VALID) != 0) { - /* XXX Handle SPI-Packet and FCP-2 reponse info. */ + /* XXX Handle SPI-Packet and FCP-2 response info. */ mpt_set_ccb_status(ccb, CAM_REQ_CMP_ERR); } else mpt_set_ccb_status(ccb, CAM_REQ_CMP); @@ -3573,6 +3574,9 @@ mpt_action(struct cam_sim *sim, union ccb *ccb) cpi->target_sprt = 0; cpi->hba_eng_cnt = 0; cpi->max_target = mpt->port_facts[0].MaxDevices - 1; +#if 0 /* XXX swildner */ + cpi->maxio = (mpt->max_cam_seg_cnt - 1) * PAGE_SIZE; +#endif /* * FC cards report MAX_DEVICES of 512, but * the MSG_SCSI_IO_REQUEST target id field @@ -3785,10 +3789,8 @@ mpt_get_spi_settings(struct mpt_softc *mpt, struct ccb_trans_settings *cts) MPTLOCK_2_CAMLOCK(mpt); mpt_lprt(mpt, MPT_PRT_DEBUG, - "mpt_get_spi_settings[%d]: current NP %x Info %x\n", - tgt, - (unsigned)tmp.NegotiatedParameters, - (unsigned)tmp.Information); + "mpt_get_spi_settings[%d]: current NP %x Info %x\n", tgt, + tmp.NegotiatedParameters, tmp.Information); dval |= (tmp.NegotiatedParameters & MPI_SCSIDEVPAGE0_NP_WIDE) ? DP_WIDE : DP_NARROW; dval |= (mpt->mpt_disc_enable & (1 << tgt)) ? @@ -3912,8 +3914,7 @@ mpt_update_spi_config(struct mpt_softc *mpt, int tgt) mpt_lprt(mpt, MPT_PRT_NEGOTIATION, "mpt_update_spi_config[%d].page1: Requested Params 0x%08x\n", - tgt, - (unsigned)mpt->mpt_dev_page1[tgt].RequestedParameters); + tgt, mpt->mpt_dev_page1[tgt].RequestedParameters); tmp = mpt->mpt_dev_page1[tgt]; host2mpt_config_page_scsi_device_1(&tmp); rv = mpt_write_cur_cfg_page(mpt, tgt, @@ -3928,9 +3929,7 @@ mpt_update_spi_config(struct mpt_softc *mpt, int tgt) static void mpt_calc_geometry(struct ccb_calc_geometry *ccg, int extended) { -#if __FreeBSD_version >= 500000 cam_calc_geometry(ccg, extended); -#else uint32_t size_mb; uint32_t secs_per_cylinder; @@ -3949,7 +3948,6 @@ mpt_calc_geometry(struct ccb_calc_geometry *ccg, int extended) secs_per_cylinder = ccg->heads * ccg->secs_per_track; ccg->cylinders = ccg->volume_size / secs_per_cylinder; ccg->ccb_h.status = CAM_REQ_CMP; -#endif } /****************************** Timeout Recovery ******************************/ @@ -3976,7 +3974,7 @@ mpt_terminate_recovery_thread(struct mpt_softc *mpt) * Sleep on a slightly different location * for this interlock just for added safety. */ - mpt_sleep(mpt, &mpt->recovery_thread, PUSER, "thtrm", 0); + mpt_sleep(mpt, &mpt->recovery_thread, 0, "thtrm", 0); } static void @@ -3985,14 +3983,11 @@ mpt_recovery_thread(void *arg) struct mpt_softc *mpt; mpt = (struct mpt_softc *)arg; - - get_mplock(); MPT_LOCK(mpt); - for (;;) { if (TAILQ_EMPTY(&mpt->request_timeout_list) != 0) { if (mpt->shutdwn_recovery == 0) { - mpt_sleep(mpt, mpt, PUSER, "idle", 0); + mpt_sleep(mpt, mpt, 0, "idle", 0); } } if (mpt->shutdwn_recovery != 0) { @@ -4003,7 +3998,7 @@ mpt_recovery_thread(void *arg) mpt->recovery_thread = NULL; wakeup(&mpt->recovery_thread); MPT_UNLOCK(mpt); - rel_mplock(); + mpt_kthread_exit(0); } static int @@ -4045,10 +4040,8 @@ mpt_scsi_send_tmf(struct mpt_softc *mpt, u_int type, u_int flags, tmf_req->TaskMsgContext = abort_ctx; mpt_lprt(mpt, MPT_PRT_DEBUG, - "Issuing TMF %p:%u with MsgContext of 0x%x\n", - mpt->tmf_req, - (unsigned)mpt->tmf_req->serno, - (unsigned)tmf_req->MsgContext); + "Issuing TMF %p:%u with MsgContext of 0x%x\n", mpt->tmf_req, + mpt->tmf_req->serno, tmf_req->MsgContext); if (mpt->verbose > MPT_PRT_DEBUG) { mpt_print_request(tmf_req); } @@ -4221,7 +4214,7 @@ mpt_fc_post_els(struct mpt_softc *mpt, request_t *req, int ioindex) /* * Okay, set up ELS buffer pointers. ELS buffer pointers * consist of a TE SGL element (with details length of zero) - * followe by a SIMPLE SGL element which holds the address + * followed by a SIMPLE SGL element which holds the address * of the buffer. */ @@ -4555,9 +4548,11 @@ mpt_target_start_io(struct mpt_softc *mpt, union ccb *ccb) if ((ccb->ccb_h.flags & CAM_SCATTER_VALID) == 0) { if ((ccb->ccb_h.flags & CAM_DATA_PHYS) == 0) { int error; + crit_enter(); error = bus_dmamap_load(mpt->buffer_dmat, req->dmap, csio->data_ptr, csio->dxfer_len, cb, req, 0); + crit_exit(); if (error == EINPROGRESS) { xpt_freeze_simq(mpt->sim, 1); ccb->ccb_h.status |= CAM_RELEASE_SIMQ; @@ -5018,15 +5013,6 @@ mpt_scsi_tgt_atio(struct mpt_softc *mpt, request_t *req, uint32_t reply_desc) mpt_task_mgmt_t fct = MPT_NIL_TMT_VALUE; uint8_t *cdbp; - /* - * First, DMA sync the received command- - * which is in the *request* * phys area. - * - * XXX: We could optimize this for a range - */ - bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap, - BUS_DMASYNC_POSTREAD); - /* * Stash info for the current command where we can get at it later. */ @@ -5269,7 +5255,7 @@ mpt_scsi_tgt_atio(struct mpt_softc *mpt, request_t *req, uint32_t reply_desc) (i == (atiop->cdb_len - 1))? '>' : ' '); } mpt_prtc(mpt, " itag %x tag %x rdesc %x dl=%u\n", - itag, atiop->tag_id, tgt->reply_desc, tgt->resid); + itag, atiop->tag_id, tgt->reply_desc, tgt->resid); } MPTLOCK_2_CAMLOCK(mpt); diff --git a/sys/dev/disk/mpt/mpt_cam.h b/sys/dev/disk/mpt/mpt_cam.h index d8c7a4b0c9..2b5e246825 100644 --- a/sys/dev/disk/mpt/mpt_cam.h +++ b/sys/dev/disk/mpt/mpt_cam.h @@ -1,4 +1,4 @@ -/* $FreeBSD: src/sys/dev/mpt/mpt_cam.h,v 1.6 2007/05/05 20:18:24 mjacob Exp $ */ +/* $FreeBSD: src/sys/dev/mpt/mpt_cam.h,v 1.7 2010/01/28 08:41:30 mav Exp $ */ /*- * LSI MPT Host Adapter FreeBSD Wrapper Definitions (CAM version) * @@ -102,7 +102,6 @@ #include #include #include -#include #include #include #include @@ -144,16 +143,6 @@ mpt_wakeup_recovery_thread(struct mpt_softc *mpt) } /************************** Version Compatibility *************************/ -#ifdef __DragonFly__ -#define mpt_sim_alloc(a, b, c, mpt, e, f, g) \ - cam_sim_alloc(a, b, c, mpt, (mpt)->unit, &sim_mplock, e, f, g) -#else -#if __FreeBSD_version < 700031 -#define mpt_sim_alloc(a, b, c, mpt, e, f, g) \ - cam_sim_alloc(a, b, c, mpt, (mpt)->unit, e, f, g) -#else #define mpt_sim_alloc(a, b, c, mpt, e, f, g) \ cam_sim_alloc(a, b, c, mpt, (mpt)->unit, &(mpt)->mpt_lock, e, f, g) -#endif #endif /*_MPT_CAM_H_ */ -#endif diff --git a/sys/dev/disk/mpt/mpt_debug.c b/sys/dev/disk/mpt/mpt_debug.c index 8daa3eff55..2e712d486d 100644 --- a/sys/dev/disk/mpt/mpt_debug.c +++ b/sys/dev/disk/mpt/mpt_debug.c @@ -62,7 +62,7 @@ * Support from LSI-Logic has also gone a great deal toward making this a * workable subsystem and is gratefully acknowledged. * - * $FreeBSD: src/sys/dev/mpt/mpt_debug.c,v 1.18 2006/12/07 22:02:28 mjacob Exp $ + * $FreeBSD: src/sys/dev/mpt/mpt_debug.c,v 1.19 2011/04/22 09:59:16 marius Exp $ */ #include @@ -358,10 +358,10 @@ mpt_print_reply_hdr(MSG_DEFAULT_REPLY *msg) { kprintf("%s Reply @ %p\n", mpt_ioc_function(msg->Function), msg); kprintf("\tIOC Status %s\n", mpt_ioc_status(msg->IOCStatus)); - kprintf("\tIOCLogInfo 0x%08x\n", (unsigned)msg->IOCLogInfo); + kprintf("\tIOCLogInfo 0x%08x\n", msg->IOCLogInfo); kprintf("\tMsgLength 0x%02x\n", msg->MsgLength); kprintf("\tMsgFlags 0x%02x\n", msg->MsgFlags); - kprintf("\tMsgContext 0x%08x\n", (unsigned)msg->MsgContext); + kprintf("\tMsgContext 0x%08x\n", msg->MsgContext); } static void @@ -384,19 +384,18 @@ mpt_print_ioc_facts(MSG_IOC_FACTS_REPLY *msg) kprintf("\tFlags %d\n", msg->Flags); kprintf("\tReplyQueueDepth %d\n", msg->ReplyQueueDepth); kprintf("\tReqFrameSize 0x%04x\n", msg->RequestFrameSize); - kprintf("\tFW Version 0x%08x\n", (unsigned)msg->FWVersion.Word); + kprintf("\tFW Version 0x%08x\n", msg->FWVersion.Word); kprintf("\tProduct ID 0x%04x\n", msg->ProductID); kprintf("\tCredits 0x%04x\n", msg->GlobalCredits); kprintf("\tPorts %d\n", msg->NumberOfPorts); kprintf("\tEventState 0x%02x\n", msg->EventState); - kprintf("\tHostMFA_HA 0x%08x\n", - (unsigned)msg->CurrentHostMfaHighAddr); + kprintf("\tHostMFA_HA 0x%08x\n", msg->CurrentHostMfaHighAddr); kprintf("\tSenseBuf_HA 0x%08x\n", - (unsigned)msg->CurrentSenseBufferHighAddr); + msg->CurrentSenseBufferHighAddr); kprintf("\tRepFrameSize 0x%04x\n", msg->CurReplyFrameSize); kprintf("\tMaxDevices 0x%02x\n", msg->MaxDevices); kprintf("\tMaxBuses 0x%02x\n", msg->MaxBuses); - kprintf("\tFWImageSize 0x%04x\n", (unsigned)msg->FWImageSize); + kprintf("\tFWImageSize 0x%04x\n", msg->FWImageSize); } static void @@ -415,9 +414,9 @@ mpt_print_scsi_io_reply(MSG_SCSI_IO_REPLY *msg) kprintf("\tCDBLength %d\n", msg->CDBLength); kprintf("\tSCSI Status: %s\n", mpt_scsi_status(msg->SCSIStatus)); kprintf("\tSCSI State: %s\n", mpt_scsi_state(msg->SCSIState)); - kprintf("\tTransferCnt 0x%04x\n", (unsigned)msg->TransferCount); - kprintf("\tSenseCnt 0x%04x\n", (unsigned)msg->SenseCount); - kprintf("\tResponseInfo 0x%08x\n", (unsigned)msg->ResponseInfo); + kprintf("\tTransferCnt 0x%04x\n", msg->TransferCount); + kprintf("\tSenseCnt 0x%04x\n", msg->SenseCount); + kprintf("\tResponseInfo 0x%08x\n", msg->ResponseInfo); } @@ -427,51 +426,50 @@ mpt_print_event_notice(MSG_EVENT_NOTIFY_REPLY *msg) { mpt_print_reply_hdr((MSG_DEFAULT_REPLY *)msg); kprintf("\tEvent: %s\n", mpt_ioc_event(msg->Event)); - kprintf("\tEventContext 0x%04x\n", (unsigned)msg->EventContext); + kprintf("\tEventContext 0x%04x\n", msg->EventContext); kprintf("\tAckRequired %d\n", msg->AckRequired); kprintf("\tEventDataLength %d\n", msg->EventDataLength); kprintf("\tContinuation %d\n", msg->MsgFlags & 0x80); switch(msg->Event) { case MPI_EVENT_LOG_DATA: - kprintf("\tEvtLogData: 0x%04x\n", - (unsigned)msg->Data[0]); + kprintf("\tEvtLogData: 0x%04x\n", msg->Data[0]); break; case MPI_EVENT_UNIT_ATTENTION: kprintf("\tTargetID: 0x%04x\n", - (unsigned)msg->Data[0] & 0xff); + msg->Data[0] & 0xff); kprintf("\tBus: 0x%04x\n", - (unsigned)(msg->Data[0] >> 8) & 0xff); + (msg->Data[0] >> 8) & 0xff); break; case MPI_EVENT_IOC_BUS_RESET: case MPI_EVENT_EXT_BUS_RESET: case MPI_EVENT_RESCAN: - kprintf("\tPort: %u\n", + kprintf("\tPort: %d\n", (msg->Data[0] >> 8) & 0xff); break; case MPI_EVENT_LINK_STATUS_CHANGE: - kprintf("\tLinkState: %u\n", + kprintf("\tLinkState: %d\n", msg->Data[0] & 0xff); - kprintf("\tPort: %u\n", + kprintf("\tPort: %d\n", (msg->Data[1] >> 8) & 0xff); break; case MPI_EVENT_LOOP_STATE_CHANGE: - kprintf("\tType: %u\n", + kprintf("\tType: %d\n", (msg->Data[0] >> 16) & 0xff); kprintf("\tChar3: 0x%02x\n", (msg->Data[0] >> 8) & 0xff); kprintf("\tChar4: 0x%02x\n", (msg->Data[0] ) & 0xff); - kprintf("\tPort: %u\n", + kprintf("\tPort: %d\n", (msg->Data[1] >> 8) & 0xff); break; case MPI_EVENT_LOGOUT: kprintf("\tN_PortId: 0x%04x\n", msg->Data[0]); - kprintf("\tPort: %u\n", + kprintf("\tPort: %d\n", (msg->Data[1] >> 8) & 0xff); break; } @@ -514,8 +512,8 @@ mpt_print_request_hdr(MSG_REQUEST_HEADER *req) { kprintf("%s @ %p\n", mpt_ioc_function(req->Function), req); kprintf("\tChain Offset 0x%02x\n", req->ChainOffset); - kprintf("\tMsgFlags 0x%02x\n", (unsigned)req->MsgFlags); - kprintf("\tMsgContext 0x%08x\n", (unsigned)req->MsgContext); + kprintf("\tMsgFlags 0x%02x\n", req->MsgFlags); + kprintf("\tMsgContext 0x%08x\n", req->MsgContext); } void @@ -530,7 +528,7 @@ mpt_print_scsi_io_request(MSG_SCSI_IO_REQUEST *orig_msg) kprintf("\tTargetID %d\n", msg->TargetID); kprintf("\tSenseBufferLength %d\n", msg->SenseBufferLength); kprintf("\tLUN: 0x%0x\n", msg->LUN[1]); - kprintf("\tControl 0x%08x ", (unsigned)msg->Control); + kprintf("\tControl 0x%08x ", msg->Control); #define MPI_PRINT_FIELD(x) \ case MPI_SCSIIO_CONTROL_ ## x : \ kprintf(" " #x " "); \ @@ -559,8 +557,8 @@ mpt_print_scsi_io_request(MSG_SCSI_IO_REQUEST *orig_msg) kprintf("\n"); #undef MPI_PRINT_FIELD - kprintf("\tDataLength\t0x%08x\n", (unsigned)msg->DataLength); - kprintf("\tSenseBufAddr\t0x%08x\n", (unsigned)msg->SenseBufferLowAddr); + kprintf("\tDataLength\t0x%08x\n", msg->DataLength); + kprintf("\tSenseBufAddr\t0x%08x\n", msg->SenseBufferLowAddr); kprintf("\tCDB[0:%d]\t", msg->CDBLength); for (i = 0; i < msg->CDBLength; i++) kprintf("%02x ", msg->CDB[i]); @@ -579,7 +577,7 @@ mpt_print_scsi_tmf_request(MSG_SCSI_TASK_MGMT *msg) mpt_print_request_hdr((MSG_REQUEST_HEADER *)msg); kprintf("\tLun 0x%02x\n", msg->LUN[1]); kprintf("\tTaskType %s\n", mpt_scsi_tm_type(msg->TaskType)); - kprintf("\tTaskMsgContext 0x%08x\n", (unsigned)msg->TaskMsgContext); + kprintf("\tTaskMsgContext 0x%08x\n", msg->TaskMsgContext); } @@ -590,10 +588,10 @@ mpt_print_scsi_target_assist_request(PTR_MSG_TARGET_ASSIST_REQUEST msg) kprintf("\tStatusCode 0x%02x\n", msg->StatusCode); kprintf("\tTargetAssist 0x%02x\n", msg->TargetAssistFlags); kprintf("\tQueueTag 0x%04x\n", msg->QueueTag); - kprintf("\tReplyWord 0x%08x\n", (unsigned)msg->ReplyWord); + kprintf("\tReplyWord 0x%08x\n", msg->ReplyWord); kprintf("\tLun 0x%02x\n", msg->LUN[1]); - kprintf("\tRelativeOff 0x%08x\n", (unsigned)msg->RelativeOffset); - kprintf("\tDataLength 0x%08x\n", (unsigned)msg->DataLength); + kprintf("\tRelativeOff 0x%08x\n", msg->RelativeOffset); + kprintf("\tDataLength 0x%08x\n", msg->DataLength); mpt_dump_sgl(msg->SGL, 0); } @@ -605,7 +603,7 @@ mpt_print_scsi_target_status_send_request(MSG_TARGET_STATUS_SEND_REQUEST *msg) kprintf("\tStatusCode 0x%02x\n", msg->StatusCode); kprintf("\tStatusFlags 0x%02x\n", msg->StatusFlags); kprintf("\tQueueTag 0x%04x\n", msg->QueueTag); - kprintf("\tReplyWord 0x%08x\n", (unsigned)msg->ReplyWord); + kprintf("\tReplyWord 0x%08x\n", msg->ReplyWord); kprintf("\tLun 0x%02x\n", msg->LUN[1]); x.u.Simple = msg->StatusDataSGE; mpt_dump_sgl(&x, 0); @@ -744,16 +742,12 @@ mpt_dump_sgl(SGE_IO_UNION *su, int offset) if (flags & MPI_SGE_FLAGS_64_BIT_ADDRESSING) { SGE_SIMPLE64 *se64 = (SGE_SIMPLE64 *)se; kprintf("SE64 %p: Addr=0x%08x%08x FlagsLength" - "=0x%0x\n", se64, - (unsigned)se64->Address.High, - (unsigned)se64->Address.Low, - (unsigned)se64->FlagsLength); + "=0x%0x\n", se64, se64->Address.High, + se64->Address.Low, se64->FlagsLength); nxtaddr = se64 + 1; } else { kprintf("SE32 %p: Addr=0x%0x FlagsLength=0x%0x" - "\n", se, - (unsigned)se->Address, - (unsigned)se->FlagsLength); + "\n", se, se->Address, se->FlagsLength); } kprintf(" "); break; @@ -762,20 +756,15 @@ mpt_dump_sgl(SGE_IO_UNION *su, int offset) SGE_CHAIN64 *ce64 = (SGE_CHAIN64 *) se; kprintf("CE64 %p: Addr=0x%08x%08x NxtChnO=0x%x " "Flgs=0x%x Len=0x%0x\n", ce64, - (unsigned)ce64->Address.High, - (unsigned)ce64->Address.Low, + ce64->Address.High, ce64->Address.Low, ce64->NextChainOffset, - (unsigned)ce64->Flags, - (unsigned)ce64->Length); + ce64->Flags, ce64->Length); nxtaddr = ce64 + 1; } else { SGE_CHAIN32 *ce = (SGE_CHAIN32 *) se; kprintf("CE32 %p: Addr=0x%0x NxtChnO=0x%x " - " Flgs=0x%x Len=0x%0x\n", ce, - (unsigned)ce->Address, - ce->NextChainOffset, - ce->Flags, - ce->Length); + " Flgs=0x%x Len=0x%0x\n", ce, ce->Address, + ce->NextChainOffset, ce->Flags, ce->Length); } flags = 0; break; @@ -830,13 +819,8 @@ mpt_dump_request(struct mpt_softc *mpt, request_t *req) { uint32_t *pReq = req->req_vbuf; int o; -#if __FreeBSD_version >= 500000 mpt_prt(mpt, "Send Request %d (%jx):", req->index, (uintmax_t) req->req_pbuf); -#else - mpt_prt(mpt, "Send Request %d (%llx):", - req->index, (unsigned long long) req->req_pbuf); -#endif for (o = 0; o < mpt->ioc_facts.RequestFrameSize; o++) { if ((o & 0x7) == 0) { mpt_prtc(mpt, "\n"); @@ -847,31 +831,6 @@ mpt_dump_request(struct mpt_softc *mpt, request_t *req) mpt_prtc(mpt, "\n"); } -#if __FreeBSD_version < 500000 -void -mpt_lprt(struct mpt_softc *mpt, int level, const char *fmt, ...) -{ - __va_list ap; - if (level <= mpt->verbose) { - kprintf("%s: ", device_get_nameunit(mpt->dev)); - __va_start(ap, fmt); - kvprintf(fmt, ap); - __va_end(ap); - } -} - -void -mpt_lprtc(struct mpt_softc *mpt, int level, const char *fmt, ...) -{ - __va_list ap; - if (level <= mpt->verbose) { - __va_start(ap, fmt); - kvprintf(fmt, ap); - __va_end(ap); - } -} -#endif - void mpt_prt(struct mpt_softc *mpt, const char *fmt, ...) { diff --git a/sys/dev/disk/mpt/mpt_pci.c b/sys/dev/disk/mpt/mpt_pci.c index 3ffbdcc66a..1af5ec4e71 100644 --- a/sys/dev/disk/mpt/mpt_pci.c +++ b/sys/dev/disk/mpt/mpt_pci.c @@ -97,21 +97,13 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF THE COPYRIGHT * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/sys/dev/mpt/mpt_pci.c,v 1.54 2009/07/10 08:18:08 scottl Exp $ + * $FreeBSD: src/sys/dev/mpt/mpt_pci.c,v 1.61 2011/04/22 09:59:16 marius Exp $ */ #include #include #include -#if __FreeBSD_version < 700000 -#define pci_msix_count(x) 0 -#define pci_msi_count(x) 0 -#define pci_alloc_msi(x, y) 1 -#define pci_alloc_msix(x, y) 1 -#define pci_release_msi(x) do { ; } while (0) -#endif - #ifndef PCI_VENDOR_LSI #define PCI_VENDOR_LSI 0x1000 #endif @@ -193,8 +185,6 @@ #endif -#define MPT_IO_BAR 0 -#define MPT_MEM_BAR 1 static int mpt_pci_probe(device_t); static int mpt_pci_attach(device_t); @@ -279,7 +269,6 @@ mpt_pci_probe(device_t dev) return (0); } -#if __FreeBSD_version < 500000 static void mpt_set_options(struct mpt_softc *mpt) { @@ -340,38 +329,6 @@ mpt_set_options(struct mpt_softc *mpt) } mpt->msi_enable = 0; } -#else -static void -mpt_set_options(struct mpt_softc *mpt) -{ - int tval; - - tval = 0; - if (resource_int_value(device_get_name(mpt->dev), - device_get_unit(mpt->dev), "disable", &tval) == 0 && tval != 0) { - mpt->disabled = 1; - } - tval = 0; - if (resource_int_value(device_get_name(mpt->dev), - device_get_unit(mpt->dev), "debug", &tval) == 0 && tval != 0) { - mpt->verbose = tval; - } - tval = -1; - if (resource_int_value(device_get_name(mpt->dev), - device_get_unit(mpt->dev), "role", &tval) == 0 && tval >= 0 && - tval <= 3) { - mpt->cfg_role = tval; - mpt->do_cfg_role = 1; - } - - tval = 0; - mpt->msi_enable = 0; - if (resource_int_value(device_get_name(mpt->dev), - device_get_unit(mpt->dev), "msi_enable", &tval) == 0 && tval == 1) { - mpt->msi_enable = 1; - } -} -#endif static void @@ -419,6 +376,7 @@ mpt_pci_attach(device_t dev) struct mpt_softc *mpt; int iqd; uint32_t data, cmd; + int mpt_io_bar, mpt_mem_bar; /* Allocate the softc structure */ mpt = (struct mpt_softc*)device_get_softc(dev); @@ -459,6 +417,7 @@ mpt_pci_attach(device_t dev) mpt->raid_queue_depth = MPT_RAID_QUEUE_DEPTH_DEFAULT; mpt->verbose = MPT_PRT_NONE; mpt->role = MPT_ROLE_NONE; + mpt->mpt_ini_id = MPT_INI_ID_NONE; mpt_set_options(mpt); if (mpt->verbose == MPT_PRT_NONE) { mpt->verbose = MPT_PRT_WARN; @@ -484,7 +443,7 @@ mpt_pci_attach(device_t dev) * Make sure we've disabled the ROM. */ data = pci_read_config(dev, PCIR_BIOS, 4); - data &= ~1; + data &= ~PCIM_BIOS_ENABLE; pci_write_config(dev, PCIR_BIOS, data, 4); /* @@ -498,14 +457,28 @@ mpt_pci_attach(device_t dev) mpt_link_peer(mpt); } + /* + * Figure out which are the I/O and MEM Bars + */ + data = pci_read_config(dev, PCIR_BAR(0), 4); + if (PCI_BAR_IO(data)) { + /* BAR0 is IO, BAR1 is memory */ + mpt_io_bar = 0; + mpt_mem_bar = 1; + } else { + /* BAR0 is memory, BAR1 is IO */ + mpt_mem_bar = 0; + mpt_io_bar = 1; + } + /* * Set up register access. PIO mode is required for * certain reset operations (but must be disabled for * some cards otherwise). */ - mpt->pci_pio_rid = PCIR_BAR(MPT_IO_BAR); - mpt->pci_pio_reg = bus_alloc_resource(dev, SYS_RES_IOPORT, - &mpt->pci_pio_rid, 0, ~0, 0, RF_ACTIVE); + mpt->pci_pio_rid = PCIR_BAR(mpt_io_bar); + mpt->pci_pio_reg = bus_alloc_resource_any(dev, SYS_RES_IOPORT, + &mpt->pci_pio_rid, RF_ACTIVE); if (mpt->pci_pio_reg == NULL) { device_printf(dev, "unable to map registers in PIO mode\n"); goto bad; @@ -514,9 +487,9 @@ mpt_pci_attach(device_t dev) mpt->pci_pio_sh = rman_get_bushandle(mpt->pci_pio_reg); /* Allocate kernel virtual memory for the 9x9's Mem0 region */ - mpt->pci_mem_rid = PCIR_BAR(MPT_MEM_BAR); - mpt->pci_reg = bus_alloc_resource(dev, SYS_RES_MEMORY, - &mpt->pci_mem_rid, 0, ~0, 0, RF_ACTIVE); + mpt->pci_mem_rid = PCIR_BAR(mpt_mem_bar); + mpt->pci_reg = bus_alloc_resource_any(dev, SYS_RES_MEMORY, + &mpt->pci_mem_rid, RF_ACTIVE); if (mpt->pci_reg == NULL) { device_printf(dev, "Unable to memory map registers.\n"); if (mpt->is_sas) { @@ -568,14 +541,14 @@ mpt_pci_attach(device_t dev) mpt_disable_ints(mpt); /* Register the interrupt handler */ - if (mpt_setup_intr(dev, mpt->pci_irq, MPT_IFLAGS, NULL, mpt_pci_intr, + if (mpt_setup_intr(dev, mpt->pci_irq, 0, NULL, mpt_pci_intr, mpt, &mpt->ih)) { device_printf(dev, "could not setup interrupt\n"); goto bad; } /* Allocate dma memory */ - /* XXX JGibbs -Should really be done based on IOCFacts. */ +/* XXX JGibbs -Should really be done based on IOCFacts. */ if (mpt_dma_mem_alloc(mpt)) { mpt_prt(mpt, "Could not allocate DMA memory\n"); goto bad; @@ -587,7 +560,7 @@ mpt_pci_attach(device_t dev) * Hard resets are known to screw up the BAR for diagnostic * memory accesses (Mem1). * - * Using Mem1 is known to make the chip stop responding to + * Using Mem1 is known to make the chip stop responding to * configuration space transfers, so we need to save it now */ @@ -714,9 +687,6 @@ mpt_pci_shutdown(device_t dev) static int mpt_dma_mem_alloc(struct mpt_softc *mpt) { - int i, error, nsegs; - uint8_t *vptr; - uint32_t pptr, end; size_t len; struct mpt_map_info mi; @@ -726,20 +696,11 @@ mpt_dma_mem_alloc(struct mpt_softc *mpt) } len = sizeof (request_t) * MPT_MAX_REQUESTS(mpt); -#ifdef RELENG_4 - mpt->request_pool = (request_t *)kmalloc(len, M_DEVBUF, M_WAITOK); - if (mpt->request_pool == NULL) { - mpt_prt(mpt, "cannot allocate request pool\n"); - return (1); - } - memset(mpt->request_pool, 0, len); -#else mpt->request_pool = (request_t *)kmalloc(len, M_DEVBUF, M_WAITOK|M_ZERO); if (mpt->request_pool == NULL) { mpt_prt(mpt, "cannot allocate request pool\n"); return (1); } -#endif /* * Create a parent dma tag for this device. @@ -747,12 +708,12 @@ mpt_dma_mem_alloc(struct mpt_softc *mpt) * Align at byte boundaries, * Limit to 32-bit addressing for request/reply queues. */ - if (mpt_dma_tag_create(mpt, /*parent*/bus_get_dma_tag(mpt->dev), + if (mpt_dma_tag_create(mpt, /*parent*/NULL, /*alignment*/1, /*boundary*/0, /*lowaddr*/BUS_SPACE_MAXADDR, /*highaddr*/BUS_SPACE_MAXADDR, /*filter*/NULL, /*filterarg*/NULL, /*maxsize*/BUS_SPACE_MAXSIZE_32BIT, - /*nsegments*/BUS_SPACE_MAXSIZE_32BIT, - /*maxsegsz*/BUS_SPACE_UNRESTRICTED, /*flags*/0, + /*nsegments*/BUS_SPACE_UNRESTRICTED, + /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT, /*flags*/0, &mpt->parent_dmat) != 0) { mpt_prt(mpt, "cannot create parent dma tag\n"); return (1); @@ -767,7 +728,7 @@ mpt_dma_mem_alloc(struct mpt_softc *mpt) return (1); } - /* Allocate some DMA accessable memory for replies */ + /* Allocate some DMA accessible memory for replies */ if (bus_dmamem_alloc(mpt->reply_dmat, (void **)&mpt->reply, BUS_DMA_NOWAIT, &mpt->reply_dmap) != 0) { mpt_prt(mpt, "cannot allocate %lu bytes of reply memory\n", @@ -789,107 +750,23 @@ mpt_dma_mem_alloc(struct mpt_softc *mpt) } mpt->reply_phys = mi.phys; - /* Create a child tag for data buffers */ - - /* - * XXX: we should say that nsegs is 'unrestricted, but that - * XXX: tickles a horrible bug in the busdma code. Instead, - * XXX: we'll derive a reasonable segment limit from MPT_MAXPHYS - */ - nsegs = (MPT_MAXPHYS / PAGE_SIZE) + 1; - if (mpt_dma_tag_create(mpt, mpt->parent_dmat, 1, - 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, - NULL, NULL, MAXBSIZE, nsegs, BUS_SPACE_MAXSIZE_32BIT, 0, - &mpt->buffer_dmat) != 0) { - mpt_prt(mpt, "cannot create a dma tag for data buffers\n"); - return (1); - } - - /* Create a child tag for request buffers */ - if (mpt_dma_tag_create(mpt, mpt->parent_dmat, PAGE_SIZE, 0, - BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR, - NULL, NULL, MPT_REQ_MEM_SIZE(mpt), 1, BUS_SPACE_MAXSIZE_32BIT, 0, - &mpt->request_dmat) != 0) { - mpt_prt(mpt, "cannot create a dma tag for requests\n"); - return (1); - } - - /* Allocate some DMA accessable memory for requests */ - if (bus_dmamem_alloc(mpt->request_dmat, (void **)&mpt->request, - BUS_DMA_NOWAIT, &mpt->request_dmap) != 0) { - mpt_prt(mpt, "cannot allocate %d bytes of request memory\n", - MPT_REQ_MEM_SIZE(mpt)); - return (1); - } - - mi.mpt = mpt; - mi.error = 0; - - /* Load and lock it into "bus space" */ - bus_dmamap_load(mpt->request_dmat, mpt->request_dmap, mpt->request, - MPT_REQ_MEM_SIZE(mpt), mpt_map_rquest, &mi, 0); - - if (mi.error) { - mpt_prt(mpt, "error %d loading dma map for DMA request queue\n", - mi.error); - return (1); - } - mpt->request_phys = mi.phys; - - /* - * Now create per-request dma maps - */ - i = 0; - pptr = mpt->request_phys; - vptr = mpt->request; - end = pptr + MPT_REQ_MEM_SIZE(mpt); - while(pptr < end) { - request_t *req = &mpt->request_pool[i]; - req->index = i++; - - /* Store location of Request Data */ - req->req_pbuf = pptr; - req->req_vbuf = vptr; - - pptr += MPT_REQUEST_AREA; - vptr += MPT_REQUEST_AREA; - - req->sense_pbuf = (pptr - MPT_SENSE_SIZE); - req->sense_vbuf = (vptr - MPT_SENSE_SIZE); - - error = bus_dmamap_create(mpt->buffer_dmat, 0, &req->dmap); - if (error) { - mpt_prt(mpt, "error %d creating per-cmd DMA maps\n", - error); - return (1); - } - } - return (0); } -/* Deallocate memory that was allocated by mpt_dma_mem_alloc +/* Deallocate memory that was allocated by mpt_dma_mem_alloc */ static void mpt_dma_mem_free(struct mpt_softc *mpt) { - int i; /* Make sure we aren't double destroying */ if (mpt->reply_dmat == 0) { mpt_lprt(mpt, MPT_PRT_DEBUG, "already released dma memory\n"); return; } - - for (i = 0; i < MPT_MAX_REQUESTS(mpt); i++) { - bus_dmamap_destroy(mpt->buffer_dmat, mpt->request_pool[i].dmap); - } - bus_dmamap_unload(mpt->request_dmat, mpt->request_dmap); - bus_dmamem_free(mpt->request_dmat, mpt->request, mpt->request_dmap); - bus_dma_tag_destroy(mpt->request_dmat); - bus_dma_tag_destroy(mpt->buffer_dmat); + bus_dmamap_unload(mpt->reply_dmat, mpt->reply_dmap); bus_dmamem_free(mpt->reply_dmat, mpt->reply, mpt->reply_dmap); bus_dma_tag_destroy(mpt->reply_dmat); diff --git a/sys/dev/disk/mpt/mpt_raid.c b/sys/dev/disk/mpt/mpt_raid.c index 5af4bd0413..a0662bbcca 100644 --- a/sys/dev/disk/mpt/mpt_raid.c +++ b/sys/dev/disk/mpt/mpt_raid.c @@ -39,7 +39,7 @@ * Support from LSI-Logic has also gone a great deal toward making this a * workable subsystem and is gratefully acknowledged. * - * $FreeBSD: src/sys/dev/mpt/mpt_raid.c,v 1.20 2009/05/21 12:36:40 jhb Exp $ + * $FreeBSD: src/sys/dev/mpt/mpt_raid.c,v 1.28 2011/01/12 19:53:56 mdf Exp $ */ #include @@ -51,13 +51,9 @@ #include #include #include -#include #include -#if __FreeBSD_version < 500000 #include -#define GIANT_REQUIRED -#endif #include #include @@ -119,11 +115,7 @@ static void mpt_enable_vol(struct mpt_softc *mpt, static void mpt_verify_mwce(struct mpt_softc *, struct mpt_raid_volume *); static void mpt_adjust_queue_depth(struct mpt_softc *, struct mpt_raid_volume *, struct cam_path *); -#if __FreeBSD_version < 500000 -#define mpt_raid_sysctl_attach(x) do { } while (0) -#else static void mpt_raid_sysctl_attach(struct mpt_softc *); -#endif static uint32_t raid_handler_id = MPT_HANDLER_ID_NONE; @@ -270,7 +262,7 @@ mpt_raid_attach(struct mpt_softc *mpt) mpt_handler_t handler; int error; - mpt_callout_init(&mpt->raid_timer); + mpt_callout_init(mpt, &mpt->raid_timer); error = mpt_spawn_raid_thread(mpt); if (error != 0) { @@ -320,9 +312,9 @@ mpt_raid_detach(struct mpt_softc *mpt) mpt_handler_t handler; callout_stop(&mpt->raid_timer); + MPT_LOCK(mpt); mpt_terminate_raid_thread(mpt); - handler.reply_handler = mpt_raid_reply_handler; mpt_deregister_handler(mpt, MPT_HANDLER_REPLY, handler, raid_handler_id); @@ -450,9 +442,9 @@ mpt_raid_event(struct mpt_softc *mpt, request_t *req, if (print_event) { if (mpt_disk != NULL) { - mpt_disk_prt(mpt, mpt_disk, NULL); + mpt_disk_prt(mpt, mpt_disk, ""); } else if (mpt_vol != NULL) { - mpt_vol_prt(mpt, mpt_vol, NULL); + mpt_vol_prt(mpt, mpt_vol, ""); } else { mpt_prt(mpt, "Volume(%d:%d", raid_event->VolumeBus, raid_event->VolumeID); @@ -475,7 +467,7 @@ mpt_raid_event(struct mpt_softc *mpt, request_t *req, if (raid_event->ReasonCode == MPI_EVENT_RAID_RC_SMART_DATA) { /* XXX Use CAM's print sense for this... */ if (mpt_disk != NULL) - mpt_disk_prt(mpt, mpt_disk, NULL); + mpt_disk_prt(mpt, mpt_disk, ""); else mpt_prt(mpt, "Volume(%d:%d:%d: ", raid_event->VolumeBus, raid_event->VolumeID, @@ -646,20 +638,19 @@ mpt_terminate_raid_thread(struct mpt_softc *mpt) return; } mpt->shutdwn_raid = 1; - wakeup(mpt->raid_volumes); + wakeup(&mpt->raid_volumes); /* * Sleep on a slightly different location * for this interlock just for added safety. */ - mpt_sleep(mpt, &mpt->raid_thread, PUSER, "thtrm", 0); + mpt_sleep(mpt, &mpt->raid_thread, 0, "thtrm", 0); } static void mpt_cam_rescan_callback(struct cam_periph *periph, union ccb *ccb) { - - xpt_free_path(ccb->ccb_h.path); - xpt_free_ccb(ccb); + xpt_free_path(ccb->ccb_h.path); + kfree(ccb, M_TEMP); } static void @@ -670,14 +661,11 @@ mpt_raid_thread(void *arg) mpt = (struct mpt_softc *)arg; firstrun = 1; - - get_mplock(); MPT_LOCK(mpt); - while (mpt->shutdwn_raid == 0) { if (mpt->raid_wakeup == 0) { - mpt_sleep(mpt, &mpt->raid_volumes, PUSER, "idle", 0); + mpt_sleep(mpt, &mpt->raid_volumes, 0, "idle", 0); continue; } @@ -701,36 +689,37 @@ mpt_raid_thread(void *arg) if (mpt->raid_rescan != 0) { union ccb *ccb; - struct cam_path *path; int error; mpt->raid_rescan = 0; MPT_UNLOCK(mpt); - ccb = xpt_alloc_ccb(); + ccb = kmalloc(sizeof(union ccb), M_TEMP, + M_WAITOK | M_ZERO); MPT_LOCK(mpt); - error = xpt_create_path(&path, xpt_periph, + error = xpt_create_path(&ccb->ccb_h.path, xpt_periph, cam_sim_path(mpt->phydisk_sim), CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD); if (error != CAM_REQ_CMP) { - xpt_free_ccb(ccb); + kfree(ccb, M_TEMP); mpt_prt(mpt, "Unable to rescan RAID Bus!\n"); } else { - xpt_setup_ccb(&ccb->ccb_h, path, 5); + xpt_setup_ccb(&ccb->ccb_h, ccb->ccb_h.path, + 5/*priority (low)*/); ccb->ccb_h.func_code = XPT_SCAN_BUS; ccb->ccb_h.cbfcnp = mpt_cam_rescan_callback; ccb->crcn.flags = CAM_FLAG_NONE; - MPTLOCK_2_CAMLOCK(mpt); xpt_action(ccb); - CAMLOCK_2_MPTLOCK(mpt); + + /* scan is now in progress */ } } } mpt->raid_thread = NULL; wakeup(&mpt->raid_thread); MPT_UNLOCK(mpt); - rel_mplock(); + mpt_kthread_exit(0); } #if 0 @@ -1064,6 +1053,7 @@ mpt_adjust_queue_depth(struct mpt_softc *mpt, struct mpt_raid_volume *mpt_vol, xpt_setup_ccb(&crs.ccb_h, path, /*priority*/5); crs.ccb_h.func_code = XPT_REL_SIMQ; + crs.ccb_h.flags = CAM_DEV_QFREEZE; crs.release_flags = RELSIM_ADJUST_OPENINGS; crs.openings = mpt->raid_queue_depth; xpt_action((union ccb *)&crs); @@ -1190,10 +1180,10 @@ mpt_announce_disk(struct mpt_softc *mpt, struct mpt_raid_disk *mpt_disk) disk_pg = &mpt_disk->config_page; mpt_disk_prt(mpt, mpt_disk, - "Physical (%s:%d:%d:0), Pass-thru (%s:%d:%jd:0)\n", + "Physical (%s:%d:%d:0), Pass-thru (%s:%d:%d:0)\n", device_get_nameunit(mpt->dev), rd_bus, disk_pg->PhysDiskID, device_get_nameunit(mpt->dev), - pt_bus, (intmax_t)(mpt_disk - mpt->raid_disks)); + pt_bus, mpt_disk - mpt->raid_disks); if (disk_pg->PhysDiskSettings.HotSparePool == 0) return; mpt_disk_prt(mpt, mpt_disk, "Member of Hot Spare Pool%s", @@ -1566,9 +1556,8 @@ mpt_raid_timer(void *arg) struct mpt_softc *mpt; mpt = (struct mpt_softc *)arg; - MPT_LOCK(mpt); + MPT_LOCK_ASSERT(mpt); mpt_raid_wakeup(mpt); - MPT_UNLOCK(mpt); } void @@ -1611,7 +1600,6 @@ mpt_raid_free_mem(struct mpt_softc *mpt) mpt->raid_max_disks = 0; } -#if __FreeBSD_version >= 500000 static int mpt_raid_set_vol_resync_rate(struct mpt_softc *mpt, u_int rate) { @@ -1743,8 +1731,6 @@ mpt_raid_sysctl_vol_member_wce(SYSCTL_HANDLER_ARGS) u_int size; u_int i; - GIANT_REQUIRED; - mpt = (struct mpt_softc *)arg1; str = mpt_vol_mwce_strs[mpt->raid_mwce_setting]; error = SYSCTL_OUT(req, str, strlen(str) + 1); @@ -1777,8 +1763,6 @@ mpt_raid_sysctl_vol_resync_rate(SYSCTL_HANDLER_ARGS) u_int raid_resync_rate; int error; - GIANT_REQUIRED; - mpt = (struct mpt_softc *)arg1; raid_resync_rate = mpt->raid_resync_rate; @@ -1797,8 +1781,6 @@ mpt_raid_sysctl_vol_queue_depth(SYSCTL_HANDLER_ARGS) u_int raid_queue_depth; int error; - GIANT_REQUIRED; - mpt = (struct mpt_softc *)arg1; raid_queue_depth = mpt->raid_queue_depth; @@ -1813,26 +1795,26 @@ mpt_raid_sysctl_vol_queue_depth(SYSCTL_HANDLER_ARGS) static void mpt_raid_sysctl_attach(struct mpt_softc *mpt) { - struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(mpt->dev); - struct sysctl_oid *tree = device_get_sysctl_tree(mpt->dev); - - SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + SYSCTL_ADD_PROC(&mpt->mpt_sysctl_ctx, + SYSCTL_CHILDREN(mpt->mpt_sysctl_tree), OID_AUTO, "vol_member_wce", CTLTYPE_STRING | CTLFLAG_RW, mpt, 0, mpt_raid_sysctl_vol_member_wce, "A", "volume member WCE(On,Off,On-During-Rebuild,NC)"); - SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + SYSCTL_ADD_PROC(&mpt->mpt_sysctl_ctx, + SYSCTL_CHILDREN(mpt->mpt_sysctl_tree), OID_AUTO, "vol_queue_depth", CTLTYPE_INT | CTLFLAG_RW, mpt, 0, mpt_raid_sysctl_vol_queue_depth, "I", "default volume queue depth"); - SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + SYSCTL_ADD_PROC(&mpt->mpt_sysctl_ctx, + SYSCTL_CHILDREN(mpt->mpt_sysctl_tree), OID_AUTO, "vol_resync_rate", CTLTYPE_INT | CTLFLAG_RW, mpt, 0, mpt_raid_sysctl_vol_resync_rate, "I", "volume resync priority (0 == NC, 1 - 255)"); - SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + SYSCTL_ADD_UINT(&mpt->mpt_sysctl_ctx, + SYSCTL_CHILDREN(mpt->mpt_sysctl_tree), OID_AUTO, "nonoptimal_volumes", CTLFLAG_RD, &mpt->raid_nonopt_volumes, 0, "number of nonoptimal volumes"); } -#endif diff --git a/sys/dev/disk/mpt/mpt_raid.h b/sys/dev/disk/mpt/mpt_raid.h index d16e127007..24f18e43a1 100644 --- a/sys/dev/disk/mpt/mpt_raid.h +++ b/sys/dev/disk/mpt/mpt_raid.h @@ -56,10 +56,10 @@ typedef enum { const char *mpt_vol_type(struct mpt_raid_volume *); const char *mpt_vol_state(struct mpt_raid_volume *); const char *mpt_disk_state(struct mpt_raid_disk *); -void mpt_vol_prt(struct mpt_softc *, struct mpt_raid_volume *, - const char *, ...) __printf0like(3, 4); -void mpt_disk_prt(struct mpt_softc *, struct mpt_raid_disk *, - const char *, ...) __printf0like(3, 4); +void +mpt_vol_prt(struct mpt_softc *, struct mpt_raid_volume *, const char *fmt, ...); +void +mpt_disk_prt(struct mpt_softc *, struct mpt_raid_disk *, const char *, ...); int mpt_issue_raid_req(struct mpt_softc *, struct mpt_raid_volume *, diff --git a/sys/dev/disk/mpt/mpt_user.c b/sys/dev/disk/mpt/mpt_user.c index 5f72aa33e6..50d51af8ce 100644 --- a/sys/dev/disk/mpt/mpt_user.c +++ b/sys/dev/disk/mpt/mpt_user.c @@ -29,14 +29,14 @@ * * LSI MPT-Fusion Host Adapter FreeBSD userland interface * - * $FreeBSD: src/sys/dev/mpt/mpt_user.c,v 1.4 2009/05/20 17:29:21 imp Exp $ + * $FreeBSD: src/sys/dev/mpt/mpt_user.c,v 1.5 2011/03/06 12:48:15 marius Exp $ */ #include #include +#include #include #include -#include #include #include @@ -77,11 +77,12 @@ DECLARE_MPT_PERSONALITY(mpt_user, SI_ORDER_SECOND); static mpt_reply_handler_t mpt_user_reply_handler; -static int mpt_open(struct dev_open_args *ap); -static int mpt_close(struct dev_close_args *ap); -static int mpt_ioctl(struct dev_ioctl_args *ap); +static d_open_t mpt_open; +static d_close_t mpt_close; +static d_ioctl_t mpt_ioctl; -static struct dev_ops mpt_cdevsw = { +static struct dev_ops mpt_ops = { + { "mpt", 0, 0 }, .d_open = mpt_open, .d_close = mpt_close, .d_ioctl = mpt_ioctl, @@ -115,7 +116,7 @@ mpt_user_attach(struct mpt_softc *mpt) return (error); } unit = device_get_unit(mpt->dev); - mpt->cdev = make_dev(&mpt_cdevsw, unit, UID_ROOT, GID_OPERATOR, 0640, + mpt->cdev = make_dev(&mpt_ops, unit, UID_ROOT, GID_OPERATOR, 0640, "mpt%d", unit); if (mpt->cdev == NULL) { MPT_LOCK(mpt); @@ -201,7 +202,7 @@ mpt_alloc_buffer(struct mpt_softc *mpt, struct mpt_page_memory *page_mem, if (error) return (error); error = bus_dmamem_alloc(page_mem->tag, &page_mem->vaddr, - BUS_DMA_NOWAIT, &page_mem->map); + BUS_DMA_NOWAIT | BUS_DMA_COHERENT, &page_mem->map); if (error) { bus_dma_tag_destroy(page_mem->tag); return (error); @@ -299,6 +300,8 @@ mpt_user_read_cfg_page(struct mpt_softc *mpt, struct mpt_cfg_page_req *page_req, params.PageNumber = hdr->PageNumber; params.PageType = hdr->PageType & MPI_CONFIG_PAGETYPE_MASK; params.PageAddress = le32toh(page_req->page_address); + bus_dmamap_sync(mpt_page->tag, mpt_page->map, + BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); error = mpt_issue_cfg_req(mpt, req, ¶ms, mpt_page->paddr, le32toh(page_req->len), TRUE, 5000); if (error != 0) { @@ -309,7 +312,7 @@ mpt_user_read_cfg_page(struct mpt_softc *mpt, struct mpt_cfg_page_req *page_req, page_req->ioc_status = htole16(req->IOCStatus); if ((req->IOCStatus & MPI_IOCSTATUS_MASK) == MPI_IOCSTATUS_SUCCESS) bus_dmamap_sync(mpt_page->tag, mpt_page->map, - BUS_DMASYNC_POSTREAD); + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); mpt_free_request(mpt, req); return (0); } @@ -387,6 +390,8 @@ mpt_user_read_extcfg_page(struct mpt_softc *mpt, params.PageAddress = le32toh(ext_page_req->page_address); params.ExtPageType = hdr->ExtPageType; params.ExtPageLength = hdr->ExtPageLength; + bus_dmamap_sync(mpt_page->tag, mpt_page->map, + BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); error = mpt_issue_cfg_req(mpt, req, ¶ms, mpt_page->paddr, le32toh(ext_page_req->len), TRUE, 5000); if (error != 0) { @@ -397,7 +402,7 @@ mpt_user_read_extcfg_page(struct mpt_softc *mpt, ext_page_req->ioc_status = htole16(req->IOCStatus); if ((req->IOCStatus & MPI_IOCSTATUS_MASK) == MPI_IOCSTATUS_SUCCESS) bus_dmamap_sync(mpt_page->tag, mpt_page->map, - BUS_DMASYNC_POSTREAD); + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); mpt_free_request(mpt, req); return (0); } @@ -432,7 +437,8 @@ mpt_user_write_cfg_page(struct mpt_softc *mpt, if (req == NULL) return (ENOMEM); - bus_dmamap_sync(mpt_page->tag, mpt_page->map, BUS_DMASYNC_PREWRITE); + bus_dmamap_sync(mpt_page->tag, mpt_page->map, BUS_DMASYNC_PREREAD | + BUS_DMASYNC_PREWRITE); /* * There isn't any point in restoring stripped out attributes @@ -459,6 +465,8 @@ mpt_user_write_cfg_page(struct mpt_softc *mpt, } page_req->ioc_status = htole16(req->IOCStatus); + bus_dmamap_sync(mpt_page->tag, mpt_page->map, BUS_DMASYNC_POSTREAD | + BUS_DMASYNC_POSTWRITE); mpt_free_request(mpt, req); return (0); } @@ -474,8 +482,6 @@ mpt_user_reply_handler(struct mpt_softc *mpt, request_t *req, return (TRUE); if (reply_frame != NULL) { - bus_dmamap_sync(mpt->request_dmat, mpt->request_dmap, - BUS_DMASYNC_POSTREAD); reply = (MSG_RAID_ACTION_REPLY *)reply_frame; req->IOCStatus = le16toh(reply->IOCStatus); res = (struct mpt_user_raid_action_result *) @@ -532,7 +538,7 @@ mpt_user_raid_action(struct mpt_softc *mpt, struct mpt_raid_action *raid_act, se = (SGE_SIMPLE32 *)&rap->ActionDataSGE; if (mpt_page->vaddr != NULL && raid_act->len != 0) { bus_dmamap_sync(mpt_page->tag, mpt_page->map, - BUS_DMASYNC_PREWRITE); + BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); se->Address = htole32(mpt_page->paddr); MPI_pSGE_SET_LENGTH(se, le32toh(raid_act->len)); MPI_pSGE_SET_FLAGS(se, (MPI_SGE_FLAGS_SIMPLE_ELEMENT | @@ -571,7 +577,7 @@ mpt_user_raid_action(struct mpt_softc *mpt, struct mpt_raid_action *raid_act, sizeof(res->action_data)); if (mpt_page->vaddr != NULL) bus_dmamap_sync(mpt_page->tag, mpt_page->map, - BUS_DMASYNC_POSTREAD); + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); mpt_free_request(mpt, req); return (0); } @@ -584,6 +590,9 @@ mpt_user_raid_action(struct mpt_softc *mpt, struct mpt_raid_action *raid_act, static int mpt_ioctl(struct dev_ioctl_args *ap) { + cdev_t dev = ap->a_head.a_dev; + u_long cmd = ap->a_cmd; + caddr_t arg = ap->a_data; struct mpt_softc *mpt; struct mpt_cfg_page_req *page_req; struct mpt_ext_cfg_page_req *ext_page_req; @@ -597,12 +606,9 @@ mpt_ioctl(struct dev_ioctl_args *ap) struct mpt_raid_action32 *raid_act32; struct mpt_raid_action raid_act_swab; #endif - u_long cmd = ap->a_cmd; - caddr_t arg = ap->a_data; - struct cdev *kdev = ap->a_head.a_dev; int error; - mpt = kdev->si_drv1; + mpt = dev->si_drv1; page_req = (void *)arg; ext_page_req = (void *)arg; raid_act = (void *)arg; diff --git a/usr.sbin/mptutil/mpt_cam.c b/usr.sbin/mptutil/mpt_cam.c index 69573c74ea..29af5dd07e 100644 --- a/usr.sbin/mptutil/mpt_cam.c +++ b/usr.sbin/mptutil/mpt_cam.c @@ -27,7 +27,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/usr.sbin/mptutil/mpt_cam.c,v 1.2 2010/02/19 15:16:00 jhb Exp $ + * $FreeBSD: src/usr.sbin/mptutil/mpt_cam.c,v 1.3 2010/11/09 19:28:06 jhb Exp $ */ #include @@ -62,6 +62,7 @@ fetch_path_id(path_id_t *path_id) struct bus_match_pattern *b; union ccb ccb; size_t bufsize; + int error; if (xpt_open() < 0) return (ENXIO); @@ -90,9 +91,10 @@ fetch_path_id(path_id_t *path_id) b->flags = BUS_MATCH_NAME | BUS_MATCH_UNIT | BUS_MATCH_BUS_ID; if (ioctl(xptfd, CAMIOCOMMAND, &ccb) < 0) { + error = errno; free(ccb.cdm.matches); free(ccb.cdm.patterns); - return (errno); + return (error); } free(ccb.cdm.patterns); @@ -123,7 +125,7 @@ mpt_query_disk(U8 VolumeBus, U8 VolumeID, struct mpt_query_disk *qd) union ccb ccb; path_id_t path_id; size_t bufsize; - int error, i; + int error; /* mpt(4) only handles devices on bus 0. */ if (VolumeBus != 0) @@ -163,10 +165,10 @@ mpt_query_disk(U8 VolumeBus, U8 VolumeID, struct mpt_query_disk *qd) p->flags = PERIPH_MATCH_PATH | PERIPH_MATCH_NAME | PERIPH_MATCH_TARGET; if (ioctl(xptfd, CAMIOCOMMAND, &ccb) < 0) { - i = errno; + error = errno; free(ccb.cdm.matches); free(ccb.cdm.patterns); - return (i); + return (error); } free(ccb.cdm.patterns); @@ -396,8 +398,8 @@ mpt_fetch_disks(int fd, int *ndisks, struct mpt_standalone_disk **disksp) union ccb ccb; path_id_t path_id; size_t bufsize; - u_int i; int count, error; + uint32_t i; if (xpt_open() < 0) return (ENXIO); @@ -430,10 +432,10 @@ mpt_fetch_disks(int fd, int *ndisks, struct mpt_standalone_disk **disksp) p->flags = PERIPH_MATCH_PATH | PERIPH_MATCH_NAME; if (ioctl(xptfd, CAMIOCOMMAND, &ccb) < 0) { - i = errno; + error = errno; free(ccb.cdm.matches); free(ccb.cdm.patterns); - return (i); + return (error); } free(ccb.cdm.patterns); @@ -480,6 +482,8 @@ mpt_fetch_disks(int fd, int *ndisks, struct mpt_standalone_disk **disksp) * exclude them from the list. */ ioc2 = mpt_read_ioc_page(fd, 2, NULL); + if (ioc2 == NULL) + return (errno); disks = calloc(ccb.cdm.num_matches, sizeof(*disks)); count = 0; for (i = 0; i < ccb.cdm.num_matches; i++) { diff --git a/usr.sbin/mptutil/mpt_cmd.c b/usr.sbin/mptutil/mpt_cmd.c index eeb9297999..8b138c3bef 100644 --- a/usr.sbin/mptutil/mpt_cmd.c +++ b/usr.sbin/mptutil/mpt_cmd.c @@ -27,7 +27,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/usr.sbin/mptutil/mpt_cmd.c,v 1.1 2009/08/14 13:13:12 scottl Exp $ + * $FreeBSD: src/usr.sbin/mptutil/mpt_cmd.c,v 1.2 2010/11/09 19:28:06 jhb Exp $ */ #include @@ -309,18 +309,15 @@ mpt_lookup_volume(int fd, const char *name, U8 *VolumeBus, U8 *VolumeID) id = strtol(cp + 1, &cp, 0); if (*cp == '\0') { if (bus < 0 || bus > 0xff || id < 0 || id > 0xff) { - errno = EINVAL; - return (-1); + return (EINVAL); } *VolumeBus = bus; *VolumeID = id; return (0); } } else if (*cp == '\0') { - if (bus < 0 || bus > 0xff) { - errno = EINVAL; - return (-1); - } + if (bus < 0 || bus > 0xff) + return (EINVAL); *VolumeBus = 0; *VolumeID = bus; return (0); @@ -328,7 +325,7 @@ mpt_lookup_volume(int fd, const char *name, U8 *VolumeBus, U8 *VolumeID) ioc2 = mpt_read_ioc_page(fd, 2, NULL); if (ioc2 == NULL) - return (-1); + return (errno); vol = ioc2->RaidVolume; for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) { @@ -342,8 +339,7 @@ mpt_lookup_volume(int fd, const char *name, U8 *VolumeBus, U8 *VolumeID) } } free(ioc2); - errno = EINVAL; - return (-1); + return (EINVAL); } int @@ -359,15 +355,14 @@ mpt_read_config_page_header(int fd, U8 PageType, U8 PageNumber, U32 PageAddress, req.header.PageNumber = PageNumber; req.page_address = PageAddress; if (ioctl(fd, MPTIO_READ_CFG_HEADER, &req) < 0) - return (-1); + return (errno); if (!IOC_STATUS_SUCCESS(req.ioc_status)) { if (IOCStatus != NULL) *IOCStatus = req.ioc_status; else warnx("Reading config page header failed: %s", mpt_ioc_status(req.ioc_status)); - errno = EIO; - return (-1); + return (EIO); } *header = req.header; return (0); @@ -379,7 +374,7 @@ mpt_read_config_page(int fd, U8 PageType, U8 PageNumber, U32 PageAddress, { struct mpt_cfg_page_req req; void *buf; - int save_errno; + int error; if (IOCStatus != NULL) *IOCStatus = MPI_IOCSTATUS_SUCCESS; @@ -403,9 +398,9 @@ mpt_read_config_page(int fd, U8 PageType, U8 PageNumber, U32 PageAddress, req.buf = buf; bcopy(&req.header, buf, sizeof(req.header)); if (ioctl(fd, MPTIO_READ_CFG_PAGE, &req) < 0) { - save_errno = errno; + error = errno; free(buf); - errno = save_errno; + errno = error; return (NULL); } if (!IOC_STATUS_SUCCESS(req.ioc_status)) { @@ -427,7 +422,7 @@ mpt_read_extended_config_page(int fd, U8 ExtPageType, U8 PageVersion, { struct mpt_ext_cfg_page_req req; void *buf; - int save_errno; + int error; if (IOCStatus != NULL) *IOCStatus = MPI_IOCSTATUS_SUCCESS; @@ -452,9 +447,9 @@ mpt_read_extended_config_page(int fd, U8 ExtPageType, U8 PageVersion, req.buf = buf; bcopy(&req.header, buf, sizeof(req.header)); if (ioctl(fd, MPTIO_READ_EXT_CFG_PAGE, &req) < 0) { - save_errno = errno; + error = errno; free(buf); - errno = save_errno; + errno = error; return (NULL); } if (!IOC_STATUS_SUCCESS(req.ioc_status)) { @@ -483,7 +478,7 @@ mpt_write_config_page(int fd, void *buf, U16 *IOCStatus) hdr = buf; req.len = hdr->PageLength * 4; if (ioctl(fd, MPTIO_WRITE_CFG_PAGE, &req) < 0) - return (-1); + return (errno); if (!IOC_STATUS_SUCCESS(req.ioc_status)) { if (IOCStatus != NULL) { *IOCStatus = req.ioc_status; @@ -491,8 +486,7 @@ mpt_write_config_page(int fd, void *buf, U16 *IOCStatus) } warnx("Writing config page failed: %s", mpt_ioc_status(req.ioc_status)); - errno = EIO; - return (-1); + return (EIO); } return (0); } @@ -506,10 +500,8 @@ mpt_raid_action(int fd, U8 Action, U8 VolumeBus, U8 VolumeID, U8 PhysDiskNum, if (IOCStatus != NULL) *IOCStatus = MPI_IOCSTATUS_SUCCESS; - if (datalen < 0 || (unsigned)datalen > sizeof(raid_act.action_data)) { - errno = EINVAL; - return (-1); - } + if (datalen < 0 || (unsigned)datalen > sizeof(raid_act.action_data)) + return (EINVAL); bzero(&raid_act, sizeof(raid_act)); raid_act.action = Action; raid_act.volume_bus = VolumeBus; @@ -523,7 +515,7 @@ mpt_raid_action(int fd, U8 Action, U8 VolumeBus, U8 VolumeID, U8 PhysDiskNum, } if (ioctl(fd, MPTIO_RAID_ACTION, &raid_act) < 0) - return (-1); + return (errno); if (!IOC_STATUS_SUCCESS(raid_act.ioc_status)) { if (IOCStatus != NULL) { @@ -532,8 +524,7 @@ mpt_raid_action(int fd, U8 Action, U8 VolumeBus, U8 VolumeID, U8 PhysDiskNum, } warnx("RAID action failed: %s", mpt_ioc_status(raid_act.ioc_status)); - errno = EIO; - return (-1); + return (EIO); } if (ActionStatus != NULL) @@ -543,8 +534,7 @@ mpt_raid_action(int fd, U8 Action, U8 VolumeBus, U8 VolumeID, U8 PhysDiskNum, return (0); warnx("RAID action failed: %s", mpt_raid_status(raid_act.action_status)); - errno = EIO; - return (-1); + return (EIO); } if (VolumeStatus != NULL) diff --git a/usr.sbin/mptutil/mpt_config.c b/usr.sbin/mptutil/mpt_config.c index f2a8d6ca82..74c68f6b2d 100644 --- a/usr.sbin/mptutil/mpt_config.c +++ b/usr.sbin/mptutil/mpt_config.c @@ -27,7 +27,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/usr.sbin/mptutil/mpt_config.c,v 1.1 2009/08/14 13:13:12 scottl Exp $ + * $FreeBSD: src/usr.sbin/mptutil/mpt_config.c,v 1.3 2010/11/22 14:36:04 jhb Exp $ */ #include @@ -49,8 +49,6 @@ static void dump_config(CONFIG_PAGE_RAID_VOL_0 *vol); #endif -#define powerof2(x) ((((x)-1)&(x))==0) - static long dehumanize(const char *value) { @@ -101,15 +99,15 @@ mpt_lock_volume(U8 VolumeBus, U8 VolumeID) */ return (0); if (error) { - errno = error; - warn("Unable to lookup volume device name"); - return (-1); + warnc(error, "Unable to lookup volume device name"); + return (error); } snprintf(path, sizeof(path), "%s%s", _PATH_DEV, qd.devname); vfd = open(path, O_RDWR); if (vfd < 0) { + error = errno; warn("Unable to lock volume %s", qd.devname); - return (-1); + return (error); } return (0); } @@ -118,13 +116,14 @@ static int mpt_lock_physdisk(struct mpt_standalone_disk *disk) { char path[MAXPATHLEN]; - int dfd; + int dfd, error; snprintf(path, sizeof(path), "%s%s", _PATH_DEV, disk->devname); dfd = open(path, O_RDWR); if (dfd < 0) { + error = errno; warn("Unable to lock disk %s", disk->devname); - return (-1); + return (error); } return (0); } @@ -143,8 +142,7 @@ mpt_lookup_standalone_disk(const char *name, struct mpt_standalone_disk *disks, id = strtol(cp + 1, &cp, 0); if (*cp == '\0') { if (bus < 0 || bus > 0xff || id < 0 || id > 0xff) { - errno = EINVAL; - return (-1); + return (EINVAL); } for (i = 0; i < ndisks; i++) { if (disks[i].bus == (U8)bus && @@ -153,8 +151,7 @@ mpt_lookup_standalone_disk(const char *name, struct mpt_standalone_disk *disks, return (0); } } - errno = ENOENT; - return (-1); + return (ENOENT); } } @@ -165,12 +162,10 @@ mpt_lookup_standalone_disk(const char *name, struct mpt_standalone_disk *disks, return (0); } } - errno = ENOENT; - return (-1); + return (ENOENT); } - errno = EINVAL; - return (-1); + return (EINVAL); } /* @@ -181,16 +176,17 @@ mpt_create_physdisk(int fd, struct mpt_standalone_disk *disk, U8 *PhysDiskNum) { CONFIG_PAGE_HEADER header; CONFIG_PAGE_RAID_PHYS_DISK_0 *config_page; + int error; U32 ActionData; - if (mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_PHYSDISK, - 0, 0, &header, NULL) < 0) - return (-1); + error = mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_PHYSDISK, + 0, 0, &header, NULL); + if (error) + return (error); if (header.PageVersion > MPI_RAIDPHYSDISKPAGE0_PAGEVERSION) { warnx("Unsupported RAID physdisk page 0 version %d", header.PageVersion); - errno = EOPNOTSUPP; - return (-1); + return (EOPNOTSUPP); } config_page = calloc(1, sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0)); config_page->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK; @@ -202,10 +198,11 @@ mpt_create_physdisk(int fd, struct mpt_standalone_disk *disk, U8 *PhysDiskNum) config_page->PhysDiskID = disk->target; /* XXX: Enclosure info for PhysDiskSettings? */ - if (mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_PHYSDISK, 0, 0, 0, 0, + error = mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_PHYSDISK, 0, 0, 0, 0, config_page, sizeof(CONFIG_PAGE_RAID_PHYS_DISK_0), NULL, - &ActionData, sizeof(ActionData), NULL, NULL, 1) < 0) - return (-1); + &ActionData, sizeof(ActionData), NULL, NULL, 1); + if (error) + return (error); *PhysDiskNum = ActionData & 0xff; return (0); } @@ -231,18 +228,20 @@ clear_config(int ac __unused, char **av __unused) IOC_3_PHYS_DISK *disk; CONFIG_PAGE_IOC_5 *ioc5; IOC_5_HOT_SPARE *spare; - int ch, fd, i; + int ch, error, fd, i; fd = mpt_open(mpt_unit); if (fd < 0) { + error = errno; warn("mpt_open"); - return (errno); + return (error); } ioc2 = mpt_read_ioc_page(fd, 2, NULL); if (ioc2 == NULL) { + error = errno; warn("Failed to fetch volume list"); - return (errno); + return (error); } /* Lock all the volumes first. */ @@ -266,14 +265,16 @@ clear_config(int ac __unused, char **av __unused) /* Delete all the volumes. */ vol = ioc2->RaidVolume; - for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) - if (mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME, + for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) { + error = mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME, vol->VolumeBus, vol->VolumeID, 0, MPI_RAID_ACTION_ADATA_DEL_PHYS_DISKS | MPI_RAID_ACTION_ADATA_ZERO_LBA0, NULL, 0, NULL, NULL, 0, - NULL, NULL, 0) < 0) - warn("Failed to delete volume %s", + NULL, NULL, 0); + if (error) + warnc(error, "Failed to delete volume %s", mpt_volume_name(vol->VolumeBus, vol->VolumeID)); + } free(ioc2); /* Delete all the spares. */ @@ -410,8 +411,9 @@ parse_volume(int fd, int raid_type, struct config_id_state *state, /* See if it is a standalone disk. */ if (mpt_lookup_standalone_disk(cp, state->sdisks, state->nsdisks, &i) < 0) { + error = errno; warn("Unable to lookup drive %s", cp); - return (errno); + return (error); } dinfo->sdisk = &state->sdisks[i]; @@ -432,17 +434,18 @@ add_drives(int fd, struct volume_info *info, int verbose) { struct drive_info *dinfo; U8 PhysDiskNum; - int i; + int error, i; for (i = 0, dinfo = info->drives; i < info->drive_count; i++, dinfo++) { if (dinfo->info == NULL) { if (mpt_create_physdisk(fd, dinfo->sdisk, &PhysDiskNum) < 0) { + error = errno; warn( "Failed to create physical disk page for %s", dinfo->sdisk->devname); - return (errno); + return (error); } if (verbose) printf("Added drive %s with PhysDiskNum %u\n", @@ -499,11 +502,14 @@ build_volume(int fd, struct volume_info *info, int raid_type, long stripe_size, U32 MinLBA; uint64_t MaxLBA; size_t page_size; - int i; + int error, i; - if (mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_VOLUME, - 0, 0, &header, NULL) < 0) + error = mpt_read_config_page_header(fd, MPI_CONFIG_PAGETYPE_RAID_VOLUME, + 0, 0, &header, NULL); + if (error) { + errno = error; return (NULL); + } if (header.PageVersion > MPI_RAIDVOLPAGE0_PAGEVERSION) { warnx("Unsupported RAID volume page 0 version %d", header.PageVersion); @@ -513,6 +519,8 @@ build_volume(int fd, struct volume_info *info, int raid_type, long stripe_size, page_size = sizeof(CONFIG_PAGE_RAID_VOL_0) + sizeof(RAID_VOL0_PHYS_DISK) * (info->drive_count - 1); vol = calloc(1, page_size); + if (vol == NULL) + return (NULL); /* Header */ vol->Header.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME; @@ -606,8 +614,8 @@ create_volume(int ac, char **av) CONFIG_PAGE_RAID_VOL_0 *vol; struct config_id_state state; struct volume_info *info; - int ch, error, fd, i, raid_type, verbose, quick; long stripe_size; + int ch, error, fd, i, quick, raid_type, verbose; #ifdef DEBUG int dump; #endif @@ -619,8 +627,9 @@ create_volume(int ac, char **av) fd = mpt_open(mpt_unit); if (fd < 0) { + error = errno; warn("mpt_open"); - return (errno); + return (error); } /* Lookup the RAID type first. */ @@ -676,8 +685,9 @@ create_volume(int ac, char **av) /* Fetch existing config data. */ state.ioc2 = mpt_read_ioc_page(fd, 2, NULL); if (state.ioc2 == NULL) { + error = errno; warn("Failed to read volume list"); - return (errno); + return (error); } state.list = mpt_pd_list(fd); if (state.list == NULL) @@ -695,6 +705,8 @@ create_volume(int ac, char **av) return (EINVAL); } info = calloc(1, sizeof(*info)); + if (info == NULL) + return (ENOMEM); error = parse_volume(fd, raid_type, &state, av[0], info); if (error) return (error); @@ -706,6 +718,8 @@ create_volume(int ac, char **av) /* Build the volume. */ vol = build_volume(fd, info, raid_type, stripe_size, &state, verbose); + if (vol == NULL) + return (errno); #ifdef DEBUG if (dump) { @@ -715,12 +729,13 @@ create_volume(int ac, char **av) #endif /* Send the new volume to the controller. */ - if (mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_VOLUME, vol->VolumeBus, + error = mpt_raid_action(fd, MPI_RAID_ACTION_CREATE_VOLUME, vol->VolumeBus, vol->VolumeID, 0, quick ? MPI_RAID_ACTION_ADATA_DO_NOT_SYNC : 0, - vol, vol->Header.PageLength * 4, NULL, NULL, 0, NULL, NULL, 1) < - 0) { + vol, vol->Header.PageLength * 4, NULL, NULL, 0, NULL, NULL, 1); + if (error) { + errno = error; warn("Failed to add volume"); - return (errno); + return (error); } #ifdef DEBUG @@ -744,7 +759,7 @@ static int delete_volume(int ac, char **av) { U8 VolumeBus, VolumeID; - int fd; + int error, fd; if (ac != 2) { warnx("delete: volume required"); @@ -753,24 +768,27 @@ delete_volume(int ac, char **av) fd = mpt_open(mpt_unit); if (fd < 0) { + error = errno; warn("mpt_open"); - return (errno); + return (error); } - if (mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID) < 0) { - warn("Invalid volume %s", av[1]); - return (errno); + error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID); + if (error) { + warnc(error, "Invalid volume %s", av[1]); + return (error); } if (mpt_lock_volume(VolumeBus, VolumeID) < 0) return (errno); - if (mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME, VolumeBus, + error = mpt_raid_action(fd, MPI_RAID_ACTION_DELETE_VOLUME, VolumeBus, VolumeID, 0, MPI_RAID_ACTION_ADATA_DEL_PHYS_DISKS | MPI_RAID_ACTION_ADATA_ZERO_LBA0, NULL, 0, NULL, NULL, 0, NULL, - NULL, 0) < 0) { - warn("Failed to delete volume"); - return (errno); + NULL, 0); + if (error) { + warnc(error, "Failed to delete volume"); + return (error); } mpt_rescan_bus(-1, -1); @@ -787,16 +805,17 @@ find_volume_spare_pool(int fd, const char *name, int *pool) CONFIG_PAGE_IOC_2 *ioc2; CONFIG_PAGE_IOC_2_RAID_VOL *vol; U8 VolumeBus, VolumeID; - int i, j, new_pool, pool_count[7]; + int error, i, j, new_pool, pool_count[7]; - if (mpt_lookup_volume(fd, name, &VolumeBus, &VolumeID) < 0) { - warn("Invalid volume %s", name); - return (-1); + error = mpt_lookup_volume(fd, name, &VolumeBus, &VolumeID); + if (error) { + warnc(error, "Invalid volume %s", name); + return (error); } info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL); if (info == NULL) - return (-1); + return (errno); /* * Check for an existing pool other than pool 0 (used for @@ -816,15 +835,16 @@ find_volume_spare_pool(int fd, const char *name, int *pool) */ ioc2 = mpt_read_ioc_page(fd, 2, NULL); if (ioc2 == NULL) { + error = errno; warn("Failed to fetch volume list"); - return (-1); + return (error); } bzero(pool_count, sizeof(pool_count)); vol = ioc2->RaidVolume; for (i = 0; i < ioc2->NumActiveVolumes; vol++, i++) { info = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID, NULL); if (info == NULL) - return (-1); + return (errno); for (j = 0; j < 7; j++) if (info->VolumeSettings.HotSparePool & (1 << (j + 1))) pool_count[j]++; @@ -842,14 +862,15 @@ find_volume_spare_pool(int fd, const char *name, int *pool) /* Add this pool to the volume. */ info = mpt_vol_info(fd, VolumeBus, VolumeID, NULL); if (info == NULL) - return (-1); + return (error); info->VolumeSettings.HotSparePool |= (1 << new_pool); - if (mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS, + error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS, VolumeBus, VolumeID, 0, *(U32 *)&info->VolumeSettings, NULL, 0, - NULL, NULL, 0, NULL, NULL, 0) < 0) { + NULL, NULL, 0, NULL, NULL, 0); + if (error) { warnx("Failed to add spare pool %d to %s", new_pool, mpt_volume_name(VolumeBus, VolumeID)); - return (-1); + return (error); } free(info); @@ -864,7 +885,7 @@ add_spare(int ac, char **av) struct mpt_standalone_disk *sdisks; struct mpt_drive_list *list; U8 PhysDiskNum; - int error, fd, i, nsdisks, pool; + int error, fd, i, nsdisks, pool = 0; if (ac < 2) { warnx("add spare: drive required"); @@ -877,13 +898,15 @@ add_spare(int ac, char **av) fd = mpt_open(mpt_unit); if (fd < 0) { + error = errno; warn("mpt_open"); - return (errno); + return (error); } if (ac == 3) { - if (find_volume_spare_pool(fd, av[2], &pool) < 0) - return (errno); + error = find_volume_spare_pool(fd, av[2], &pool); + if (error) + return (error); } else pool = MPI_RAID_HOT_SPARE_POOL_0; @@ -901,16 +924,18 @@ add_spare(int ac, char **av) if (mpt_lookup_standalone_disk(av[1], sdisks, nsdisks, &i) < 0) { + error = errno; warn("Unable to lookup drive %s", av[1]); - return (errno); + return (error); } if (mpt_lock_physdisk(&sdisks[i]) < 0) return (errno); if (mpt_create_physdisk(fd, &sdisks[i], &PhysDiskNum) < 0) { + error = errno; warn("Failed to create physical disk page"); - return (errno); + return (error); } free(sdisks); } @@ -918,8 +943,9 @@ add_spare(int ac, char **av) info = mpt_pd_info(fd, PhysDiskNum, NULL); if (info == NULL) { + error = errno; warn("Failed to fetch drive info"); - return (errno); + return (error); } info->PhysDiskSettings.HotSparePool = pool; @@ -927,8 +953,8 @@ add_spare(int ac, char **av) 0, PhysDiskNum, *(U32 *)&info->PhysDiskSettings, NULL, 0, NULL, NULL, 0, NULL, NULL, 0); if (error) { - warn("Failed to assign spare"); - return (errno); + warnc(error, "Failed to assign spare"); + return (error); } free(info); @@ -953,8 +979,9 @@ remove_spare(int ac, char **av) fd = mpt_open(mpt_unit); if (fd < 0) { + error = errno; warn("mpt_open"); - return (errno); + return (error); } list = mpt_pd_list(fd); @@ -971,8 +998,9 @@ remove_spare(int ac, char **av) info = mpt_pd_info(fd, PhysDiskNum, NULL); if (info == NULL) { + error = errno; warn("Failed to fetch drive info"); - return (errno); + return (error); } if (info->PhysDiskSettings.HotSparePool == 0) { @@ -981,8 +1009,9 @@ remove_spare(int ac, char **av) } if (mpt_delete_physdisk(fd, PhysDiskNum) < 0) { + error = errno; warn("Failed to delete physical disk page"); - return (errno); + return (error); } mpt_rescan_bus(info->PhysDiskBus, info->PhysDiskID); @@ -1010,8 +1039,9 @@ pd_create(int ac, char **av) fd = mpt_open(mpt_unit); if (fd < 0) { + error = errno; warn("mpt_open"); - return (errno); + return (error); } error = mpt_fetch_disks(fd, &ndisks, &disks); @@ -1021,16 +1051,18 @@ pd_create(int ac, char **av) } if (mpt_lookup_standalone_disk(av[1], disks, ndisks, &i) < 0) { + error = errno; warn("Unable to lookup drive"); - return (errno); + return (error); } if (mpt_lock_physdisk(&disks[i]) < 0) return (errno); if (mpt_create_physdisk(fd, &disks[i], &PhysDiskNum) < 0) { + error = errno; warn("Failed to create physical disk page"); - return (errno); + return (error); } free(disks); @@ -1047,7 +1079,7 @@ pd_delete(int ac, char **av) { CONFIG_PAGE_RAID_PHYS_DISK_0 *info; struct mpt_drive_list *list; - int fd; + int error, fd; U8 PhysDiskNum; if (ac != 2) { @@ -1057,8 +1089,9 @@ pd_delete(int ac, char **av) fd = mpt_open(mpt_unit); if (fd < 0) { + error = errno; warn("mpt_open"); - return (errno); + return (error); } list = mpt_pd_list(fd); @@ -1066,20 +1099,23 @@ pd_delete(int ac, char **av) return (errno); if (mpt_lookup_drive(list, av[1], &PhysDiskNum) < 0) { + error = errno; warn("Failed to find drive %s", av[1]); - return (errno); + return (error); } mpt_free_pd_list(list); info = mpt_pd_info(fd, PhysDiskNum, NULL); if (info == NULL) { + error = errno; warn("Failed to fetch drive info"); - return (errno); + return (error); } if (mpt_delete_physdisk(fd, PhysDiskNum) < 0) { + error = errno; warn("Failed to delete physical disk page"); - return (errno); + return (error); } mpt_rescan_bus(info->PhysDiskBus, info->PhysDiskID); @@ -1125,7 +1161,7 @@ debug_config(int ac, char **av) { CONFIG_PAGE_RAID_VOL_0 *vol; U8 VolumeBus, VolumeID; - int fd; + int error, fd; if (ac != 2) { warnx("debug: volume required"); @@ -1134,19 +1170,22 @@ debug_config(int ac, char **av) fd = mpt_open(mpt_unit); if (fd < 0) { + error = errno; warn("mpt_open"); - return (errno); + return (error); } - if (mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID) < 0) { - warn("Invalid volume: %s", av[1]); - return (errno); + error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID); + if (error) { + warnc(error, "Invalid volume: %s", av[1]); + return (error); } vol = mpt_vol_info(fd, VolumeBus, VolumeID, NULL); if (vol == NULL) { + error = errno; warn("Failed to get volume info"); - return (errno); + return (error); } dump_config(vol); diff --git a/usr.sbin/mptutil/mpt_drive.c b/usr.sbin/mptutil/mpt_drive.c index 90dc40b24d..15de48b58a 100644 --- a/usr.sbin/mptutil/mpt_drive.c +++ b/usr.sbin/mptutil/mpt_drive.c @@ -27,7 +27,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/usr.sbin/mptutil/mpt_drive.c,v 1.1 2009/08/14 13:13:12 scottl Exp $ + * $FreeBSD: src/usr.sbin/mptutil/mpt_drive.c,v 1.2 2010/11/09 19:28:06 jhb Exp $ */ #include @@ -128,7 +128,7 @@ mpt_pd_insert(int fd, struct mpt_drive_list *list, U8 PhysDiskNum) list->drives[j + 1] = list->drives[j]; list->drives[i] = mpt_pd_info(fd, PhysDiskNum, NULL); if (list->drives[i] == NULL) - return (-1); + return (errno); list->ndrives++; return (0); } @@ -145,26 +145,32 @@ mpt_pd_list(int fd) CONFIG_PAGE_IOC_5 *ioc5; IOC_5_HOT_SPARE *spare; struct mpt_drive_list *list; - int count, i, j; + int count, error, i, j; ioc2 = mpt_read_ioc_page(fd, 2, NULL); if (ioc2 == NULL) { + error = errno; warn("Failed to fetch volume list"); + errno = error; return (NULL); } ioc3 = mpt_read_ioc_page(fd, 3, NULL); if (ioc3 == NULL) { + error = errno; warn("Failed to fetch drive list"); free(ioc2); + errno = error; return (NULL); } ioc5 = mpt_read_ioc_page(fd, 5, NULL); if (ioc5 == NULL) { + error = errno; warn("Failed to fetch spare list"); free(ioc3); free(ioc2); + errno = error; return (NULL); } @@ -179,7 +185,9 @@ mpt_pd_list(int fd) volumes[i] = mpt_vol_info(fd, vol->VolumeBus, vol->VolumeID, NULL); if (volumes[i] == NULL) { + error = errno; warn("Failed to read volume info"); + errno = error; return (NULL); } count += volumes[i]->NumPhysDisks; @@ -263,13 +271,11 @@ mpt_lookup_drive(struct mpt_drive_list *list, const char *drive, return (0); } } - errno = ENOENT; - return (-1); + return (ENOENT); } bad: - errno = EINVAL; - return (-1); + return (EINVAL); } /* Borrowed heavily from scsi_all.c:scsi_print_inquiry(). */ @@ -305,12 +311,13 @@ drive_set_state(char *drive, U8 Action, U8 State, const char *name) CONFIG_PAGE_RAID_PHYS_DISK_0 *info; struct mpt_drive_list *list; U8 PhysDiskNum; - int fd; + int error, fd; fd = mpt_open(mpt_unit); if (fd < 0) { + error = errno; warn("mpt_open"); - return (errno); + return (error); } list = mpt_pd_list(fd); @@ -318,16 +325,18 @@ drive_set_state(char *drive, U8 Action, U8 State, const char *name) return (errno); if (mpt_lookup_drive(list, drive, &PhysDiskNum) < 0) { + error = errno; warn("Failed to find drive %s", drive); - return (errno); + return (error); } mpt_free_pd_list(list); /* Get the info for this drive. */ info = mpt_pd_info(fd, PhysDiskNum, NULL); if (info == NULL) { + error = errno; warn("Failed to fetch info for drive %u", PhysDiskNum); - return (errno); + return (error); } /* Try to change the state. */ @@ -336,10 +345,11 @@ drive_set_state(char *drive, U8 Action, U8 State, const char *name) return (EINVAL); } - if (mpt_raid_action(fd, Action, 0, 0, PhysDiskNum, 0, NULL, 0, NULL, - NULL, 0, NULL, NULL, 0) < 0) { - warn("Failed to set drive %u to %s", PhysDiskNum, name); - return (errno); + error = mpt_raid_action(fd, Action, 0, 0, PhysDiskNum, 0, NULL, 0, NULL, + NULL, 0, NULL, NULL, 0); + if (error) { + warnc(error, "Failed to set drive %u to %s", PhysDiskNum, name); + return (error); } free(info); diff --git a/usr.sbin/mptutil/mpt_evt.c b/usr.sbin/mptutil/mpt_evt.c index 5bd6beea3a..75fec8d5a0 100644 --- a/usr.sbin/mptutil/mpt_evt.c +++ b/usr.sbin/mptutil/mpt_evt.c @@ -27,7 +27,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/usr.sbin/mptutil/mpt_evt.c,v 1.1 2009/08/14 13:13:12 scottl Exp $ + * $FreeBSD: src/usr.sbin/mptutil/mpt_evt.c,v 1.2 2010/11/09 19:28:06 jhb Exp $ */ #include @@ -93,18 +93,20 @@ show_events(int ac, char **av) { CONFIG_PAGE_LOG_0 *log; MPI_LOG_0_ENTRY **entries; - int ch, fd, i, num_events, verbose; + int ch, error, fd, i, num_events, verbose; fd = mpt_open(mpt_unit); if (fd < 0) { + error = errno; warn("mpt_open"); - return (errno); + return (error); } log = mpt_get_events(fd, NULL); if (log == NULL) { + error = errno; warn("Failed to get event log info"); - return (errno); + return (error); } /* Default settings. */ @@ -127,6 +129,8 @@ show_events(int ac, char **av) /* Build a list of valid entries and sort them by sequence. */ entries = malloc(sizeof(MPI_LOG_0_ENTRY *) * log->NumLogEntries); + if (entries == NULL) + return (ENOMEM); num_events = 0; for (i = 0; i < log->NumLogEntries; i++) { if (log->LogEntry[i].LogEntryQualifier == diff --git a/usr.sbin/mptutil/mpt_show.c b/usr.sbin/mptutil/mpt_show.c index a6c84b6aa4..7e6c485599 100644 --- a/usr.sbin/mptutil/mpt_show.c +++ b/usr.sbin/mptutil/mpt_show.c @@ -27,7 +27,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/usr.sbin/mptutil/mpt_show.c,v 1.2 2010/02/19 14:31:01 jhb Exp $ + * $FreeBSD: src/usr.sbin/mptutil/mpt_show.c,v 1.3 2010/11/09 19:28:06 jhb Exp $ */ #include @@ -78,7 +78,7 @@ show_adapter(int ac, char **av __unused) CONFIG_PAGE_IOC_2 *ioc2; CONFIG_PAGE_IOC_6 *ioc6; U16 IOCStatus; - int fd, comma; + int comma, error, fd; if (ac != 1) { warnx("show adapter: extra arguments"); @@ -87,17 +87,19 @@ show_adapter(int ac, char **av __unused) fd = mpt_open(mpt_unit); if (fd < 0) { + error = errno; warn("mpt_open"); - return (errno); + return (error); } man0 = mpt_read_man_page(fd, 0, NULL); if (man0 == NULL) { + error = errno; warn("Failed to get controller info"); - return (errno); + return (error); } if (man0->Header.PageLength < sizeof(*man0) / 4) { - warn("Invalid controller info"); + warnx("Invalid controller info"); return (EINVAL); } printf("mpt%d Adapter:\n", mpt_unit); @@ -282,7 +284,7 @@ show_config(int ac, char **av __unused) CONFIG_PAGE_RAID_VOL_1 *vnames; CONFIG_PAGE_RAID_PHYS_DISK_0 *pinfo; struct mpt_standalone_disk *sdisks; - int fd, i, j, nsdisks; + int error, fd, i, j, nsdisks; if (ac != 1) { warnx("show config: extra arguments"); @@ -291,20 +293,23 @@ show_config(int ac, char **av __unused) fd = mpt_open(mpt_unit); if (fd < 0) { + error = errno; warn("mpt_open"); - return (errno); + return (error); } /* Get the config from the controller. */ ioc2 = mpt_read_ioc_page(fd, 2, NULL); ioc5 = mpt_read_ioc_page(fd, 5, NULL); if (ioc2 == NULL || ioc5 == NULL) { + error = errno; warn("Failed to get config"); - return (errno); + return (error); } if (mpt_fetch_disks(fd, &nsdisks, &sdisks) < 0) { + error = errno; warn("Failed to get standalone drive list"); - return (errno); + return (error); } /* Dump out the configuration. */ @@ -380,7 +385,7 @@ show_volumes(int ac, char **av __unused) CONFIG_PAGE_IOC_2_RAID_VOL *vol; CONFIG_PAGE_RAID_VOL_0 **volumes; CONFIG_PAGE_RAID_VOL_1 *vnames; - int fd, i, len, state_len; + int error, fd, i, len, state_len; if (ac != 1) { warnx("show volumes: extra arguments"); @@ -389,15 +394,17 @@ show_volumes(int ac, char **av __unused) fd = mpt_open(mpt_unit); if (fd < 0) { + error = errno; warn("mpt_open"); - return (errno); + return (error); } /* Get the volume list from the controller. */ ioc2 = mpt_read_ioc_page(fd, 2, NULL); if (ioc2 == NULL) { + error = errno; warn("Failed to get volume list"); - return (errno); + return (error); } /* @@ -465,7 +472,7 @@ show_drives(int ac, char **av __unused) { struct mpt_drive_list *list; struct mpt_standalone_disk *sdisks; - int fd, i, len, nsdisks, state_len; + int error, fd, i, len, nsdisks, state_len; if (ac != 1) { warnx("show drives: extra arguments"); @@ -474,15 +481,17 @@ show_drives(int ac, char **av __unused) fd = mpt_open(mpt_unit); if (fd < 0) { + error = errno; warn("mpt_open"); - return (errno); + return (error); } /* Get the drive list. */ list = mpt_pd_list(fd); if (list == NULL) { + error = errno; warn("Failed to get drive list"); - return (errno); + return (error); } /* Fetch the list of standalone disks for this controller. */ @@ -537,8 +546,9 @@ show_physdisks(int ac, char **av) fd = mpt_open(mpt_unit); if (fd < 0) { + error = errno; warn("mpt_open"); - return (errno); + return (error); } /* Try to find each possible phys disk page. */ diff --git a/usr.sbin/mptutil/mpt_volume.c b/usr.sbin/mptutil/mpt_volume.c index cfbc93c58c..b75e56f0a4 100644 --- a/usr.sbin/mptutil/mpt_volume.c +++ b/usr.sbin/mptutil/mpt_volume.c @@ -27,7 +27,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/usr.sbin/mptutil/mpt_volume.c,v 1.1 2009/08/14 13:13:12 scottl Exp $ + * $FreeBSD: src/usr.sbin/mptutil/mpt_volume.c,v 1.2 2010/11/09 19:28:06 jhb Exp $ */ #include @@ -68,7 +68,7 @@ volume_name(int ac, char **av) { CONFIG_PAGE_RAID_VOL_1 *vnames; U8 VolumeBus, VolumeID; - int fd; + int error, fd; if (ac != 3) { warnx("name: volume and name required"); @@ -82,19 +82,22 @@ volume_name(int ac, char **av) fd = mpt_open(mpt_unit); if (fd < 0) { + error = errno; warn("mpt_open"); - return (errno); + return (error); } - if (mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID) < 0) { - warn("Invalid volume: %s", av[1]); - return (errno); + error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID); + if (error) { + warnc(error, "Invalid volume: %s", av[1]); + return (error); } vnames = mpt_vol_names(fd, VolumeBus, VolumeID, NULL); if (vnames == NULL) { + error = errno; warn("Failed to fetch volume names"); - return (errno); + return (error); } if (vnames->Header.PageType != MPI_CONFIG_PAGEATTR_CHANGEABLE) { @@ -108,8 +111,9 @@ volume_name(int ac, char **av) strcpy(vnames->Name, av[2]); if (mpt_write_config_page(fd, vnames, NULL) < 0) { + error = errno; warn("Failed to set volume name"); - return (errno); + return (error); } free(vnames); @@ -127,7 +131,7 @@ volume_status(int ac, char **av) uint64_t total, remaining; float pct; U8 VolumeBus, VolumeID; - int fd; + int error, fd; if (ac != 2) { warnx("volume status: %s", ac > 2 ? "extra arguments" : @@ -137,20 +141,23 @@ volume_status(int ac, char **av) fd = mpt_open(mpt_unit); if (fd < 0) { + error = errno; warn("mpt_open"); - return (errno); + return (error); } - if (mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID) < 0) { - warn("Invalid volume: %s", av[1]); - return (errno); + error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID); + if (error) { + warnc(error, "Invalid volume: %s", av[1]); + return (error); } - if (mpt_raid_action(fd, MPI_RAID_ACTION_INDICATOR_STRUCT, VolumeBus, + error = mpt_raid_action(fd, MPI_RAID_ACTION_INDICATOR_STRUCT, VolumeBus, VolumeID, 0, 0, NULL, 0, &VolumeStatus, (U32 *)&prog, sizeof(prog), - NULL, NULL, 0) < 0) { - warn("Fetching volume status failed"); - return (errno); + NULL, NULL, 0); + if (error) { + warnc(error, "Fetching volume status failed"); + return (error); } printf("Volume %s status:\n", mpt_volume_name(VolumeBus, VolumeID)); @@ -190,11 +197,11 @@ volume_cache(int ac, char **av) U32 Settings, NewSettings; U8 VolumeBus, VolumeID; char *s1; - int fd; + int error, fd; if (ac != 3) { warnx("volume cache: %s", ac > 3 ? "extra arguments" : - "volume required"); + "missing arguments"); return (EINVAL); } @@ -208,18 +215,20 @@ volume_cache(int ac, char **av) fd = mpt_open(mpt_unit); if (fd < 0) { + error = errno; warn("mpt_open"); - return (errno); + return (error); } - if (mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID) < 0) { - warn("Invalid volume: %s", av[1]); - return (errno); + error = mpt_lookup_volume(fd, av[1], &VolumeBus, &VolumeID); + if (error) { + warnc(error, "Invalid volume: %s", av[1]); + return (error); } volume = mpt_vol_info(fd, VolumeBus, VolumeID, NULL); if (volume == NULL) - return (-1); + return (errno); Settings = volume->VolumeSettings.Settings; @@ -230,18 +239,19 @@ volume_cache(int ac, char **av) NewSettings &= ~0x01; if (NewSettings == Settings) { - warnx("volume cache unchanged\n"); + warnx("volume cache unchanged"); close(fd); return (0); } volume->VolumeSettings.Settings = NewSettings; - if (mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS, + error = mpt_raid_action(fd, MPI_RAID_ACTION_CHANGE_VOLUME_SETTINGS, VolumeBus, VolumeID, 0, *(U32 *)&volume->VolumeSettings, NULL, 0, - NULL, NULL, 0, NULL, NULL, 0) < 0) - warnx("volume cache change failed, errno= %d\n", errno); + NULL, NULL, 0, NULL, NULL, 0); + if (error) + warnc(error, "volume cache change failed"); close(fd); - return (0); + return (error); } MPT_COMMAND(volume, cache, volume_cache); diff --git a/usr.sbin/mptutil/mptutil.8 b/usr.sbin/mptutil/mptutil.8 index ad969d8393..190c59b155 100644 --- a/usr.sbin/mptutil/mptutil.8 +++ b/usr.sbin/mptutil/mptutil.8 @@ -27,9 +27,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $FreeBSD: src/usr.sbin/mptutil/mptutil.8,v 1.2 2009/08/17 06:15:44 scottl Exp $ +.\" $FreeBSD: src/usr.sbin/mptutil/mptutil.8,v 1.6 2010/08/01 09:37:36 joel Exp $ .\" -.Dd April 17, 2010 +.Dd April 28, 2011 .Dt MPTUTIL 8 .Os .Sh NAME @@ -348,6 +348,11 @@ as a global hot spare: .Dl Nm Cm add da3 .Sh SEE ALSO .Xr mpt 4 +.Sh HISTORY +The +.Nm +utility first appeared in +.Fx 8.0 . .Sh BUGS .Pp The handling of spare drives appears to be unreliable. @@ -379,8 +384,14 @@ configurations may not work reliably. .Pp Drive configuration commands result in an excessive flood of messages on the console. -.Sh HISTORY -The +.Pp +The mpt version 1 API that is used by .Nm -utility first appeared in -.Fx 8.0 . +and +.Xr mpt 4 +doesn't support volumes above two terabytes. +This is a limitation of the API. +If you are using this adapter with volumes larger than two terabytes, use the adapter in JBOD mode. +Utilize +.Xr lvm 8 +or another software volume manager to work around this limitation. diff --git a/usr.sbin/mptutil/mptutil.c b/usr.sbin/mptutil/mptutil.c index c9656f464a..1b2be226cc 100644 --- a/usr.sbin/mptutil/mptutil.c +++ b/usr.sbin/mptutil/mptutil.c @@ -27,7 +27,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/usr.sbin/mptutil/mptutil.c,v 1.1 2009/08/14 13:13:12 scottl Exp $ + * $FreeBSD: src/usr.sbin/mptutil/mptutil.c,v 1.2 2010/10/10 20:37:38 randi Exp $ */ #include @@ -113,10 +113,12 @@ main(int ac, char **av) SET_FOREACH(cmd, MPT_DATASET(top)) { if (strcmp((*cmd)->name, av[0]) == 0) { - (*cmd)->handler(ac, av); - return (0); + if ((*cmd)->handler(ac, av)) + return (1); + else + return (0); } } warnx("Unknown command %s.", av[0]); - return (0); + return (1); } diff --git a/usr.sbin/mptutil/mptutil.h b/usr.sbin/mptutil/mptutil.h index f250a97425..4087051e9a 100644 --- a/usr.sbin/mptutil/mptutil.h +++ b/usr.sbin/mptutil/mptutil.h @@ -33,7 +33,6 @@ #ifndef __MPTUTIL_H__ #define __MPTUTIL_H__ -#include #include #include -- 2.41.0