Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/ic add byte-swapping so that this works on BE platfo...



details:   https://anonhg.NetBSD.org/src/rev/06acee75d35b
branches:  trunk
changeset: 754366:06acee75d35b
user:      chs <chs%NetBSD.org@localhost>
date:      Wed Apr 28 22:45:27 2010 +0000

description:
add byte-swapping so that this works on BE platforms.
the logic is based on the current freebsd driver.
fixes PR 42870.

diffstat:

 sys/dev/ic/mpt.c        |  355 ++++++++++++++++++++++++++++++++++++++++++++---
 sys/dev/ic/mpt.h        |   49 ++++++-
 sys/dev/ic/mpt_debug.c  |   61 ++++---
 sys/dev/ic/mpt_netbsd.c |   62 ++++---
 4 files changed, 447 insertions(+), 80 deletions(-)

diffs (truncated from 1066 to 300 lines):

diff -r 28535238d4e7 -r 06acee75d35b sys/dev/ic/mpt.c
--- a/sys/dev/ic/mpt.c  Wed Apr 28 22:21:51 2010 +0000
+++ b/sys/dev/ic/mpt.c  Wed Apr 28 22:45:27 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mpt.c,v 1.13 2009/04/18 14:58:02 tsutsui Exp $ */
+/*     $NetBSD: mpt.c,v 1.14 2010/04/28 22:45:27 chs Exp $     */
 
 /*
  * Copyright (c) 2000, 2001 by Greg Ansley
@@ -27,6 +27,75 @@
 /*
  * Additional Copyright (c) 2002 by Matthew Jacob under same license.
  */
+/*-
+ * Copyright (c) 2002, 2006 by Matthew Jacob
+ * All rights reserved.
+ *
+ * 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, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon including
+ *    a substantially similar Disclaimer requirement for further binary
+ *    redistribution.
+ * 3. Neither the names of the above listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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 THE COPYRIGHT
+ * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Support from Chris Ellsworth in order to make SAS adapters work
+ * is gratefully acknowledged.
+ *
+ *
+ * Support from LSI-Logic has also gone a great deal toward making this a
+ * workable subsystem and is gratefully acknowledged.
+ */
+/*-
+ * Copyright (c) 2004, Avid Technology, Inc. and its contributors.
+ * Copyright (c) 2005, WHEEL Sp. z o.o.
+ * Copyright (c) 2004, 2005 Justin T. Gibbs
+ * All rights reserved.
+ *
+ * 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, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon including
+ *    a substantially similar Disclaimer requirement for further binary
+ *    redistribution.
+ * 3. Neither the names of the above listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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 THE COPYRIGHT
+ * OWNER OR CONTRIBUTOR IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
 
 
 /*
@@ -41,7 +110,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mpt.c,v 1.13 2009/04/18 14:58:02 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mpt.c,v 1.14 2010/04/28 22:45:27 chs Exp $");
 
 #include <dev/ic/mpt.h>
 
@@ -346,7 +415,7 @@
 
        /* Send the command */
        for (i = 0; i < len; i++) {
-               mpt_write(mpt, MPT_OFFSET_DOORBELL, *data32++);
+               mpt_write(mpt, MPT_OFFSET_DOORBELL, htole32(*data32++));
                if (mpt_wait_db_ack(mpt) != MPT_OK) {
                        mpt_prt(mpt,
                            "mpt_send_handshake_cmd timeout! index = %d", i);
@@ -375,7 +444,8 @@
                mpt_prt(mpt, "mpt_recv_handshake_cmd timeout1");
                return ETIMEDOUT;
        }
-       *data16++ = mpt_read(mpt, MPT_OFFSET_DOORBELL) & MPT_DB_DATA_MASK;
+       *data16++ = le16toh(mpt_read(mpt, MPT_OFFSET_DOORBELL) &
+                           MPT_DB_DATA_MASK);
        mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0);
 
        /* Get Second Word */
@@ -383,7 +453,8 @@
                mpt_prt(mpt, "mpt_recv_handshake_cmd timeout2");
                return ETIMEDOUT;
        }
-       *data16++ = mpt_read(mpt, MPT_OFFSET_DOORBELL) & MPT_DB_DATA_MASK;
+       *data16++ = le16toh(mpt_read(mpt, MPT_OFFSET_DOORBELL) &
+                           MPT_DB_DATA_MASK);
        mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0);
 
        /* With the second word, we can now look at the length */
@@ -406,7 +477,7 @@
                datum = mpt_read(mpt, MPT_OFFSET_DOORBELL);
 
                if (reply_left-- > 0)
-                       *data16++ = datum & MPT_DB_DATA_MASK;
+                       *data16++ = le16toh(datum & MPT_DB_DATA_MASK);
 
                mpt_write(mpt, MPT_OFFSET_INTR_STATUS, 0);
        }
@@ -435,7 +506,7 @@
 
        memset(&f_req, 0, sizeof f_req);
        f_req.Function = MPI_FUNCTION_IOC_FACTS;
-       f_req.MsgContext =  0x12071942;
+       f_req.MsgContext = htole32(0x12071942);
        error = mpt_send_handshake_cmd(mpt, sizeof f_req, &f_req);
        if (error)
                return(error);
@@ -452,7 +523,7 @@
        /* XXX: Only getting PORT FACTS for Port 0 */
        memset(&f_req, 0, sizeof f_req);
        f_req.Function = MPI_FUNCTION_PORT_FACTS;
-       f_req.MsgContext =  0x12071943;
+       f_req.MsgContext =  htole32(0x12071943);
        error = mpt_send_handshake_cmd(mpt, sizeof f_req, &f_req);
        if (error)
                return(error);
@@ -478,8 +549,8 @@
        init.Function = MPI_FUNCTION_IOC_INIT;
        init.MaxDevices = mpt->mpt_max_devices;
        init.MaxBuses = 1;
-       init.ReplyFrameSize = MPT_REPLY_SIZE;
-       init.MsgContext = 0x12071941;
+       init.ReplyFrameSize = htole16(MPT_REPLY_SIZE);
+       init.MsgContext = htole32(0x12071941);
 
        if ((error = mpt_send_handshake_cmd(mpt, sizeof init, &init)) != 0) {
                return(error);
@@ -515,11 +586,11 @@
        cfgp->Function = MPI_FUNCTION_CONFIG;
        cfgp->Header.PageNumber = (U8) PageNumber;
        cfgp->Header.PageType = (U8) PageType;
-       cfgp->PageAddress = PageAddress;
+       cfgp->PageAddress = htole32(PageAddress);
        MPI_pSGE_SET_FLAGS(((SGE_SIMPLE32 *) &cfgp->PageBufferSGE),
            (MPI_SGE_FLAGS_LAST_ELEMENT | MPI_SGE_FLAGS_END_OF_BUFFER |
            MPI_SGE_FLAGS_SIMPLE_ELEMENT | MPI_SGE_FLAGS_END_OF_LIST));
-       cfgp->MsgContext = req->index | 0x80000000;
+       cfgp->MsgContext = htole32(req->index | 0x80000000);
 
        mpt_check_doorbell(mpt);
        mpt_send_cmd(mpt, req);
@@ -567,15 +638,16 @@
        cfgp->Header = *hdr;
        amt = (cfgp->Header.PageLength * sizeof (u_int32_t));
        cfgp->Header.PageType &= MPI_CONFIG_PAGETYPE_MASK;
-       cfgp->PageAddress = PageAddress;
+       cfgp->PageAddress = htole32(PageAddress);
        se = (SGE_SIMPLE32 *) &cfgp->PageBufferSGE;
-       se->Address = req->req_pbuf + CFG_DATA_OFF;
+       se->Address = htole32(req->req_pbuf + CFG_DATA_OFF);
        MPI_pSGE_SET_LENGTH(se, amt);
        MPI_pSGE_SET_FLAGS(se, (MPI_SGE_FLAGS_SIMPLE_ELEMENT |
            MPI_SGE_FLAGS_LAST_ELEMENT | MPI_SGE_FLAGS_END_OF_BUFFER |
            MPI_SGE_FLAGS_END_OF_LIST));
+       se->FlagsLength = htole32(se->FlagsLength);
 
-       cfgp->MsgContext = req->index | 0x80000000;
+       cfgp->MsgContext = htole32(req->index | 0x80000000);
 
        mpt_check_doorbell(mpt);
        mpt_send_cmd(mpt, req);
@@ -650,16 +722,17 @@
        cfgp->Function = MPI_FUNCTION_CONFIG;
        cfgp->Header = *hdr;
        amt = (cfgp->Header.PageLength * sizeof (u_int32_t));
-       cfgp->PageAddress = PageAddress;
+       cfgp->PageAddress = htole32(PageAddress);
 
        se = (SGE_SIMPLE32 *) &cfgp->PageBufferSGE;
-       se->Address = req->req_pbuf + CFG_DATA_OFF;
+       se->Address = htole32(req->req_pbuf + CFG_DATA_OFF);
        MPI_pSGE_SET_LENGTH(se, amt);
        MPI_pSGE_SET_FLAGS(se, (MPI_SGE_FLAGS_SIMPLE_ELEMENT |
            MPI_SGE_FLAGS_LAST_ELEMENT | MPI_SGE_FLAGS_END_OF_BUFFER |
            MPI_SGE_FLAGS_END_OF_LIST | MPI_SGE_FLAGS_HOST_TO_IOC));
+       se->FlagsLength = htole32(se->FlagsLength);
 
-       cfgp->MsgContext = req->index | 0x80000000;
+       cfgp->MsgContext = htole32(req->index | 0x80000000);
 
        if (cfgp->Header.PageType == MPI_CONFIG_PAGETYPE_SCSI_PORT &&
            cfgp->Header.PageNumber == 0) {
@@ -697,7 +770,7 @@
        reply = (MSG_CONFIG_REPLY *) MPT_REPLY_PTOV(mpt, req->sequence);
         if ((reply->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
                mpt_prt(mpt, "mpt_write_cfg_page: Config Info Status %x",
-                   reply->IOCStatus);
+                   le16toh(reply->IOCStatus));
                mpt_free_reply(mpt, (req->sequence << 1));
                return (-1);
        }
@@ -792,6 +865,7 @@
         */
 
        rv = mpt_read_cfg_page(mpt, 0, &mpt->mpt_port_page0.Header);
+       mpt2host_config_page_scsi_port_0(&mpt->mpt_port_page0);
        if (rv) {
                mpt_prt(mpt, "failed to read SPI Port Page 0");
        } else if (mpt->verbose > 1) {
@@ -802,6 +876,7 @@
        }
 
        rv = mpt_read_cfg_page(mpt, 0, &mpt->mpt_port_page1.Header);
+       mpt2host_config_page_scsi_port_1(&mpt->mpt_port_page1);
        if (rv) {
                mpt_prt(mpt, "failed to read SPI Port Page 1");
        } else if (mpt->verbose > 1) {
@@ -812,6 +887,7 @@
        }
 
        rv = mpt_read_cfg_page(mpt, 0, &mpt->mpt_port_page2.Header);
+       mpt2host_config_page_scsi_port_2(&mpt->mpt_port_page2);
        if (rv) {
                mpt_prt(mpt, "failed to read SPI Port Page 2");
        } else if (mpt->verbose > 1) {
@@ -819,7 +895,7 @@
                    "SPI Port Page 2: Flags %x Settings %x",
                    mpt->mpt_port_page2.PortFlags,
                    mpt->mpt_port_page2.PortSettings);
-               for (i = 0; i < 16; i++) {
+               for (i = 0; i < 1; i++) {
                        mpt_prt(mpt,
                            "SPI Port Page 2 Tgt %d: timo %x SF %x Flags %x",
                            i, mpt->mpt_port_page2.DeviceSettings[i].Timeout,
@@ -830,6 +906,7 @@
 
        for (i = 0; i < 16; i++) {
                rv = mpt_read_cfg_page(mpt, i, &mpt->mpt_dev_page0[i].Header);
+               mpt2host_config_page_scsi_device_0(&mpt->mpt_dev_page0[i]);
                if (rv) {
                        mpt_prt(mpt, "cannot read SPI Tgt %d Device Page 0", i);
                        continue;
@@ -841,6 +918,7 @@
                            mpt->mpt_dev_page0[i].Information);
                }
                rv = mpt_read_cfg_page(mpt, i, &mpt->mpt_dev_page1[i].Header);
+               mpt2host_config_page_scsi_device_1(&mpt->mpt_dev_page1[i]);
                if (rv) {
                        mpt_prt(mpt, "cannot read SPI Tgt %d Device Page 1", i);
                        continue;
@@ -870,17 +948,20 @@
 
        if (mpt->mpt_port_page1.Configuration != pp1val) {
                fCONFIG_PAGE_SCSI_PORT_1 tmp;
+
                mpt_prt(mpt,
                    "SPI Port Page 1 Config value bad (%x)- should be %x",
                    mpt->mpt_port_page1.Configuration, pp1val);
                tmp = mpt->mpt_port_page1;
                tmp.Configuration = pp1val;
+               host2mpt_config_page_scsi_port_1(&tmp);
                if (mpt_write_cfg_page(mpt, 0, &tmp.Header)) {
                        return (-1);
                }
                if (mpt_read_cfg_page(mpt, 0, &tmp.Header)) {
                        return (-1);
                }
+               mpt2host_config_page_scsi_port_1(&tmp);
                if (tmp.Configuration != pp1val) {
                        mpt_prt(mpt,
                            "failed to reset SPI Port Page 1 Config value");
@@ -889,8 +970,10 @@
                mpt->mpt_port_page1 = tmp;
        }
 
+       i = 0;



Home | Main Index | Thread Index | Old Index