Source-Changes-HG archive

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

[src/netbsd-9]: src Pull up following revision(s) via patch (requested by msa...



details:   https://anonhg.NetBSD.org/src/rev/974bd538f296
branches:  netbsd-9
changeset: 366182:974bd538f296
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Tue May 17 10:29:47 2022 +0000

description:
Pull up following revision(s) via patch (requested by msaitoh in ticket #1454):
        sys/dev/ic/mfi.c: revisions 1.63, 1.66-77
        sys/dev/ic/mfireg.h: revisions 1.11-1.20 via patch
        sys/dev/pci/mfi_pci.c: revision 1.21
        sys/dev/pci/mfii.c: revisions 1.6-1.7, 1.10-1.15
        share/man/man4/mfi.4: revision 1.13

Improve mfi(4) and mfii(4):
- Set 'ld_sync' to NULL as part of 'again', to prevent use-after-free.
- Add some code for the SKINNY variant to make Dell PERC H310 work.
- Print the percentage correctly when the background initialization is
  running.
- Clear mailbox to not to pass garbage data.
- Use union mbox instead of unit8_t xxx[] to avoid unaligned access.
- Set stripe size for BIOCVOL to show the size correctly in bioctl.
- Add support for iBBU-09 to show BBU voltage, current and temperature
  correctly.
- Fix typos in comments.
- Sprinkle static.
- Improve debug printf()s.
- KNF. Remove extra semicolon. Whitespace fixes.

diffstat:

 share/man/man4/mfi.4  |   15 +-
 sys/dev/ic/mfi.c      |  242 +++++++++++++++-------------
 sys/dev/ic/mfireg.h   |  410 +++++++++++++++++++++++++------------------------
 sys/dev/pci/mfi_pci.c |    5 +-
 sys/dev/pci/mfii.c    |  349 +++++++++++++++++++++--------------------
 5 files changed, 526 insertions(+), 495 deletions(-)

diffs (truncated from 2505 to 300 lines):

diff -r d508ef135a6d -r 974bd538f296 share/man/man4/mfi.4
--- a/share/man/man4/mfi.4      Tue May 17 10:23:17 2022 +0000
+++ b/share/man/man4/mfi.4      Tue May 17 10:29:47 2022 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: mfi.4,v 1.12 2017/07/03 21:30:58 wiz Exp $
+.\"    $NetBSD: mfi.4,v 1.12.8.1 2022/05/17 10:29:47 bouyer Exp $
 .\"    $OpenBSD: mfi.4,v 1.7 2006/09/01 09:58:09 jmc Exp $
 .\"
 .\" Written by Marco Peereboom <marco%peereboom.us@localhost>
@@ -24,7 +24,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd March 22, 2012
+.Dd May 5, 2022
 .Dt MFI 4
 .Os
 .Sh NAME
@@ -43,7 +43,10 @@
 Dell PERC 5/e,
 PERC 5/i,
 PERC 6/e,
-PERC 6/i
+PERC 6/i,
+PERC H310,
+PERC H700,
+PERC H800
 .It
 Intel RAID Controller SRCSAS18E,
 SRCSAS144E
@@ -56,9 +59,11 @@
 MegaRAID SAS 8408E,
 MegaRAID SAS 8480E,
 MegaRAID SAS 8708ELP,
+MegaRAID SAS 8880EM2,
 MegaRAID SAS 8888ELP,
-MegaRAID SAS 8880EM2,
-MegaRAID SAS 9260-8i
+MegaRAID SAS 9260-8i,
+MegaRAID SAS 9261-8i,
+MegaRAID SAS 9265-8i
 .It
 IBM ServeRAID M1015,
 ServeRAID M5014
diff -r d508ef135a6d -r 974bd538f296 sys/dev/ic/mfi.c
--- a/sys/dev/ic/mfi.c  Tue May 17 10:23:17 2022 +0000
+++ b/sys/dev/ic/mfi.c  Tue May 17 10:29:47 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mfi.c,v 1.61 2019/07/29 12:07:57 gdt Exp $ */
+/* $NetBSD: mfi.c,v 1.61.2.1 2022/05/17 10:29:47 bouyer Exp $ */
 /* $OpenBSD: mfi.c,v 1.66 2006/11/28 23:59:45 dlg Exp $ */
 
 /*
@@ -73,7 +73,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mfi.c,v 1.61 2019/07/29 12:07:57 gdt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mfi.c,v 1.61.2.1 2022/05/17 10:29:47 bouyer Exp $");
 
 #include "bio.h"
 
@@ -112,7 +112,7 @@
 
 #ifdef MFI_DEBUG
 uint32_t       mfi_debug = 0
-/*                 | MFI_D_CMD  */
+/*                 | MFI_D_CMD */
 /*                 | MFI_D_INTR */
 /*                 | MFI_D_MISC */
 /*                 | MFI_D_DMA */
@@ -156,9 +156,11 @@
 static void            mfi_scsi_ld_done(struct mfi_ccb *);
 static void            mfi_scsi_xs_done(struct mfi_ccb *, int, int);
 static int             mfi_mgmt_internal(struct mfi_softc *, uint32_t,
-                           uint32_t, uint32_t, void *, uint8_t *, bool);
+                           uint32_t, uint32_t, void *, const union mfi_mbox *,
+                           bool);
 static int             mfi_mgmt(struct mfi_ccb *,struct scsipi_xfer *,
-                           uint32_t, uint32_t, uint32_t, void *, uint8_t *);
+                           uint32_t, uint32_t, uint32_t, void *,
+                           const union mfi_mbox *);
 static void            mfi_mgmt_done(struct mfi_ccb *);
 
 #if NBIO > 0
@@ -201,10 +203,10 @@
 };
 
 static uint32_t        mfi_xscale_fw_state(struct mfi_softc *sc);
-static void            mfi_xscale_intr_ena(struct mfi_softc *sc);
-static void            mfi_xscale_intr_dis(struct mfi_softc *sc);
-static int             mfi_xscale_intr(struct mfi_softc *sc);
-static void            mfi_xscale_post(struct mfi_softc *sc, struct mfi_ccb *ccb);
+static void            mfi_xscale_intr_ena(struct mfi_softc *sc);
+static void            mfi_xscale_intr_dis(struct mfi_softc *sc);
+static int             mfi_xscale_intr(struct mfi_softc *sc);
+static void            mfi_xscale_post(struct mfi_softc *sc, struct mfi_ccb *ccb);
 
 static const struct mfi_iop_ops mfi_iop_xscale = {
        mfi_xscale_fw_state,
@@ -216,10 +218,10 @@
 };
 
 static uint32_t        mfi_ppc_fw_state(struct mfi_softc *sc);
-static void            mfi_ppc_intr_ena(struct mfi_softc *sc);
-static void            mfi_ppc_intr_dis(struct mfi_softc *sc);
-static int             mfi_ppc_intr(struct mfi_softc *sc);
-static void            mfi_ppc_post(struct mfi_softc *sc, struct mfi_ccb *ccb);
+static void            mfi_ppc_intr_ena(struct mfi_softc *sc);
+static void            mfi_ppc_intr_dis(struct mfi_softc *sc);
+static int             mfi_ppc_intr(struct mfi_softc *sc);
+static void            mfi_ppc_post(struct mfi_softc *sc, struct mfi_ccb *ccb);
 
 static const struct mfi_iop_ops mfi_iop_ppc = {
        mfi_ppc_fw_state,
@@ -285,11 +287,11 @@
        mfi_tbolt_scsi_ld_io,
 };
 
-#define mfi_fw_state(_s)       ((_s)->sc_iop->mio_fw_state(_s))
-#define mfi_intr_enable(_s)    ((_s)->sc_iop->mio_intr_ena(_s))
-#define mfi_intr_disable(_s)   ((_s)->sc_iop->mio_intr_dis(_s))
-#define mfi_my_intr(_s)        ((_s)->sc_iop->mio_intr(_s))
-#define mfi_post(_s, _c)       ((_s)->sc_iop->mio_post((_s), (_c)))
+#define mfi_fw_state(_s)       ((_s)->sc_iop->mio_fw_state(_s))
+#define mfi_intr_enable(_s)    ((_s)->sc_iop->mio_intr_ena(_s))
+#define mfi_intr_disable(_s)   ((_s)->sc_iop->mio_intr_dis(_s))
+#define mfi_my_intr(_s)                ((_s)->sc_iop->mio_intr(_s))
+#define mfi_post(_s, _c)       ((_s)->sc_iop->mio_post((_s), (_c)))
 
 static struct mfi_ccb *
 mfi_get_ccb(struct mfi_softc *sc)
@@ -439,11 +441,11 @@
                }
 
                DNPRINTF(MFI_D_CCB,
-                   "ccb(%d): %p frame: %#lx (%#lx) sense: %#lx (%#lx) map: %#lx\n",
+                   "ccb(%d): %p frame: %p (%#lx) sense: %p (%#lx) map: %p\n",
                    ccb->ccb_frame->mfr_header.mfh_context, ccb,
-                   (u_long)ccb->ccb_frame, (u_long)ccb->ccb_pframe,
-                   (u_long)ccb->ccb_sense, (u_long)ccb->ccb_psense,
-                   (u_long)ccb->ccb_dmamap);
+                   ccb->ccb_frame, (u_long)ccb->ccb_pframe,
+                   ccb->ccb_sense, (u_long)ccb->ccb_psense,
+                   ccb->ccb_dmamap);
 
                /* add ccb to queue */
                mfi_put_ccb(ccb);
@@ -472,14 +474,14 @@
            BUS_SPACE_BARRIER_READ);
        rv = bus_space_read_4(sc->sc_iot, sc->sc_ioh, r);
 
-       DNPRINTF(MFI_D_RW, "%s: mr 0x%lx 0x08%x ", DEVNAME(sc), (u_long)r, rv);
+       DNPRINTF(MFI_D_RW, "%s: mr %#zx 0x08%x ", DEVNAME(sc), r, rv);
        return rv;
 }
 
 static void
 mfi_write(struct mfi_softc *sc, bus_size_t r, uint32_t v)
 {
-       DNPRINTF(MFI_D_RW, "%s: mw 0x%lx 0x%08x", DEVNAME(sc), (u_long)r, v);
+       DNPRINTF(MFI_D_RW, "%s: mw %#zx 0x%08x", DEVNAME(sc), r, v);
 
        bus_space_write_4(sc->sc_iot, sc->sc_ioh, r, v);
        bus_space_barrier(sc->sc_iot, sc->sc_ioh, r, 4,
@@ -492,8 +494,8 @@
        struct mfi_mem          *mm;
        int                     nsegs;
 
-       DNPRINTF(MFI_D_MEM, "%s: mfi_allocmem: %ld\n", DEVNAME(sc),
-           (long)size);
+       DNPRINTF(MFI_D_MEM, "%s: mfi_allocmem: %zu\n", DEVNAME(sc),
+           size);
 
        mm = malloc(sizeof(struct mfi_mem), M_DEVBUF, M_NOWAIT|M_ZERO);
        if (mm == NULL)
@@ -585,7 +587,7 @@
                case MFI_STATE_OPERATIONAL:
                        if (sc->sc_ioptype == MFI_IOP_SKINNY ||
                            sc->sc_ioptype == MFI_IOP_TBOLT)
-                               mfi_write(sc, MFI_SKINNY_IDB, MFI_INIT_READY);
+                               mfi_write(sc, MFI_SKINNY_IDB, MFI_RESET_FLAGS);
                        else
                                mfi_write(sc, MFI_IDB, MFI_INIT_READY);
                        max_wait = 10;
@@ -687,7 +689,6 @@
                return 1;
 
 #ifdef MFI_DEBUG
-
        for (i = 0; i < sc->sc_info.mci_image_component_count; i++) {
                printf("%s: active FW %s Version %s date %s time %s\n",
                    DEVNAME(sc),
@@ -848,7 +849,7 @@
            "status 0x%x\n", stat->battery_type, stat->voltage, stat->current,
            stat->temperature, stat->fw_status);
        printf("details: ");
-       switch(stat->battery_type) {
+       switch (stat->battery_type) {
        case MFI_BBU_TYPE_IBBU:
                printf("guage %d relative charge %d charger state %d "
                    "charger ctrl %d\n", stat->detail.ibbu.gas_guage_status,
@@ -874,9 +875,9 @@
                printf("\n");
        }
 #endif
-       switch(stat->battery_type) {
+       switch (stat->battery_type) {
        case MFI_BBU_TYPE_BBU:
-               return (stat->detail.bbu.is_SOH_good ? 
+               return (stat->detail.bbu.is_SOH_good ?
                    MFI_BBU_GOOD : MFI_BBU_BAD);
        case MFI_BBU_TYPE_NONE:
                return MFI_BBU_UNKNOWN;
@@ -972,20 +973,22 @@
 mfi_shutdown(device_t dev, int how)
 {
        struct mfi_softc        *sc = device_private(dev);
-       uint8_t                 mbox[MFI_MBOX_SIZE];
+       union mfi_mbox          mbox;
        int s = splbio();
+
        DNPRINTF(MFI_D_MISC, "%s: mfi_shutdown\n", DEVNAME(sc));
        if (sc->sc_running) {
-               mbox[0] = MR_FLUSH_CTRL_CACHE | MR_FLUSH_DISK_CACHE;
+               memset(&mbox, 0, sizeof(mbox));
+               mbox.b[0] = MR_FLUSH_CTRL_CACHE | MR_FLUSH_DISK_CACHE;
                if (mfi_mgmt_internal(sc, MR_DCMD_CTRL_CACHE_FLUSH,
-                   MFI_DATA_NONE, 0, NULL, mbox, true)) {
+                   MFI_DATA_NONE, 0, NULL, &mbox, true)) {
                        aprint_error_dev(dev, "shutdown: cache flush failed\n");
                        goto fail;
                }
 
-               mbox[0] = 0;
+               mbox.b[0] = 0;
                if (mfi_mgmt_internal(sc, MR_DCMD_CTRL_SHUTDOWN,
-                   MFI_DATA_NONE, 0, NULL, mbox, true)) {
+                   MFI_DATA_NONE, 0, NULL, &mbox, true)) {
                        aprint_error_dev(dev, "shutdown: "
                            "firmware shutdown failed\n");
                        goto fail;
@@ -1042,7 +1045,7 @@
                sc->sc_iop = &mfi_iop_tbolt;
                break;
        default:
-                panic("%s: unknown iop %d", DEVNAME(sc), iop);
+               panic("%s: unknown iop %d", DEVNAME(sc), iop);
        }
 
        if (mfi_transition_firmware(sc))
@@ -1063,13 +1066,15 @@
                sc->sc_max_sgl = max_sgl;
                sc->sc_sgl_size = sizeof(struct mfi_sg32);
        }
+       if (sc->sc_ioptype == MFI_IOP_SKINNY)
+               sc->sc_sgl_size = sizeof(struct mfi_sg_ieee);
        DNPRINTF(MFI_D_MISC, "%s: max commands: %u, max sgl: %u\n",
            DEVNAME(sc), sc->sc_max_cmds, sc->sc_max_sgl);
 
        if (sc->sc_ioptype == MFI_IOP_TBOLT) {
                uint32_t tb_mem_size;
                /* for Alignment */
-               tb_mem_size = MEGASAS_THUNDERBOLT_MSG_ALLIGNMENT;
+               tb_mem_size = MEGASAS_THUNDERBOLT_MSG_ALIGNMENT;
 
                tb_mem_size +=
                    MEGASAS_THUNDERBOLT_NEW_MSG_SIZE * (sc->sc_max_cmds + 1);
@@ -1205,7 +1210,7 @@
                        aprint_normal("unknown type %d", bbu_stat.battery_type);
                }
                aprint_normal(", status ");
-               switch(mfi_bbu_status) {
+               switch (mfi_bbu_status) {
                case MFI_BBU_GOOD:
                        aprint_normal("good\n");
                        sc->sc_bbuok = true;
@@ -1372,8 +1377,7 @@
 
        pcq = MFIMEM_KVA(sc->sc_pcq);
 
-       DNPRINTF(MFI_D_INTR, "%s: mfi_intr %#lx %#lx\n", DEVNAME(sc),
-           (u_long)sc, (u_long)pcq);
+       DNPRINTF(MFI_D_INTR, "%s: mfi_intr %p %p\n", DEVNAME(sc), sc, pcq);
 
        bus_dmamap_sync(sc->sc_dmat, MFIMEM_MAP(sc->sc_pcq), 0,
            sizeof(uint32_t) * sc->sc_max_cmds + sizeof(struct mfi_prod_cons),
@@ -1477,8 +1481,8 @@
        struct scsipi_xfer      *xs = ccb->ccb_xs;
        struct mfi_softc        *sc = ccb->ccb_sc;
 
-       DNPRINTF(MFI_D_INTR, "%s: mfi_scsi_xs_done %#lx %#lx\n",
-           DEVNAME(sc), (u_long)ccb, (u_long)ccb->ccb_frame);
+       DNPRINTF(MFI_D_INTR, "%s: mfi_scsi_xs_done %p %p\n",
+           DEVNAME(sc), ccb, ccb->ccb_frame);
 
        if (xs->data != NULL) {
                DNPRINTF(MFI_D_INTR, "%s: mfi_scsi_xs_done sync\n",
@@ -1501,9 +1505,9 @@
                            ccb->ccb_psense - MFIMEM_DVA(sc->sc_sense),



Home | Main Index | Thread Index | Old Index