From 3bc7f528ef6e8c0205b70d24d1fc7ad8efce6e23 Mon Sep 17 00:00:00 2001 From: mglocker Date: Thu, 9 May 2024 08:16:32 +0000 Subject: [PATCH] Perform bus DMA synchronization to update the command descriptors. --- sys/dev/ic/ufshci.c | 55 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/sys/dev/ic/ufshci.c b/sys/dev/ic/ufshci.c index a6363edae5c..c689cca7fbe 100644 --- a/sys/dev/ic/ufshci.c +++ b/sys/dev/ic/ufshci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ufshci.c,v 1.15 2024/05/09 08:13:57 mglocker Exp $ */ +/* $OpenBSD: ufshci.c,v 1.16 2024/05/09 08:16:32 mglocker Exp $ */ /* * Copyright (c) 2022 Marcus Glocker @@ -555,6 +555,11 @@ ufshci_utr_cmd_nop(struct ufshci_softc *sc, struct ufshci_ccb *ccb, return -1; } + bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_utrd), + sizeof(*utrd) * slot, sizeof(*utrd), BUS_DMASYNC_PREWRITE); + bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_ucd), + sizeof(*ucd) * slot, sizeof(*ucd), BUS_DMASYNC_PREWRITE); + /* 7.2.1 Basic Steps when Building a UTP Transfer Request: 14) */ ccb->ccb_status = CCB_STATUS_INPROGRESS; ufshci_doorbell_write(sc, slot); @@ -657,6 +662,11 @@ ufshci_utr_cmd_lun(struct ufshci_softc *sc, struct ufshci_ccb *ccb, return -1; } + bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_utrd), + sizeof(*utrd) * slot, sizeof(*utrd), BUS_DMASYNC_PREWRITE); + bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_ucd), + sizeof(*ucd) * slot, sizeof(*ucd), BUS_DMASYNC_PREWRITE); + /* 7.2.1 Basic Steps when Building a UTP Transfer Request: 14) */ ccb->ccb_status = CCB_STATUS_INPROGRESS; ufshci_doorbell_write(sc, slot); @@ -757,6 +767,11 @@ ufshci_utr_cmd_inquiry(struct ufshci_softc *sc, struct ufshci_ccb *ccb, return -1; } + bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_utrd), + sizeof(*utrd) * slot, sizeof(*utrd), BUS_DMASYNC_PREWRITE); + bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_ucd), + sizeof(*ucd) * slot, sizeof(*ucd), BUS_DMASYNC_PREWRITE); + /* 7.2.1 Basic Steps when Building a UTP Transfer Request: 14) */ ccb->ccb_status = CCB_STATUS_INPROGRESS; ufshci_doorbell_write(sc, slot); @@ -861,6 +876,11 @@ ufshci_utr_cmd_capacity16(struct ufshci_softc *sc, struct ufshci_ccb *ccb, return -1; } + bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_utrd), + sizeof(*utrd) * slot, sizeof(*utrd), BUS_DMASYNC_PREWRITE); + bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_ucd), + sizeof(*ucd) * slot, sizeof(*ucd), BUS_DMASYNC_PREWRITE); + /* 7.2.1 Basic Steps when Building a UTP Transfer Request: 14) */ ccb->ccb_status = CCB_STATUS_INPROGRESS; ufshci_doorbell_write(sc, slot); @@ -964,6 +984,11 @@ ufshci_utr_cmd_capacity(struct ufshci_softc *sc, struct ufshci_ccb *ccb, return -1; } + bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_utrd), + sizeof(*utrd) * slot, sizeof(*utrd), BUS_DMASYNC_PREWRITE); + bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_ucd), + sizeof(*ucd) * slot, sizeof(*ucd), BUS_DMASYNC_PREWRITE); + /* 7.2.1 Basic Steps when Building a UTP Transfer Request: 14) */ ccb->ccb_status = CCB_STATUS_INPROGRESS; ufshci_doorbell_write(sc, slot); @@ -1070,6 +1095,11 @@ ufshci_utr_cmd_io(struct ufshci_softc *sc, struct ufshci_ccb *ccb, return -1; } + bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_utrd), + sizeof(*utrd) * slot, sizeof(*utrd), BUS_DMASYNC_PREWRITE); + bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_ucd), + sizeof(*ucd) * slot, sizeof(*ucd), BUS_DMASYNC_PREWRITE); + /* 7.2.1 Basic Steps when Building a UTP Transfer Request: 14) */ ccb->ccb_status = CCB_STATUS_INPROGRESS; ufshci_doorbell_write(sc, slot); @@ -1164,6 +1194,11 @@ ufshci_utr_cmd_sync(struct ufshci_softc *sc, struct ufshci_ccb *ccb, return -1; } + bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_utrd), + sizeof(*utrd) * slot, sizeof(*utrd), BUS_DMASYNC_PREWRITE); + bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_ucd), + sizeof(*ucd) * slot, sizeof(*ucd), BUS_DMASYNC_PREWRITE); + /* 7.2.1 Basic Steps when Building a UTP Transfer Request: 14) */ ccb->ccb_status = CCB_STATUS_INPROGRESS; ufshci_doorbell_write(sc, slot); @@ -1665,6 +1700,8 @@ ufshci_scsi_io_done(struct ufshci_softc *sc, struct ufshci_ccb *ccb) { struct scsi_xfer *xs = ccb->ccb_cookie; bus_dmamap_t dmap = ccb->ccb_dmamap; + struct ufshci_ucd *ucd; + struct ufshci_utrd *utrd; bus_dmamap_sync(sc->sc_dmat, dmap, 0, dmap->dm_mapsize, ISSET(xs->flags, SCSI_DATA_IN) ? BUS_DMASYNC_POSTREAD : @@ -1672,6 +1709,13 @@ ufshci_scsi_io_done(struct ufshci_softc *sc, struct ufshci_ccb *ccb) bus_dmamap_unload(sc->sc_dmat, dmap); + bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_ucd), + sizeof(*ucd) * ccb->ccb_slot, sizeof(*ucd), + BUS_DMASYNC_POSTWRITE); + bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_utrd), + sizeof(*utrd) * ccb->ccb_slot, sizeof(*utrd), + BUS_DMASYNC_POSTWRITE); + ccb->ccb_cookie = NULL; ccb->ccb_status = CCB_STATUS_FREE; ccb->ccb_done = NULL; @@ -1686,6 +1730,15 @@ void ufshci_scsi_done(struct ufshci_softc *sc, struct ufshci_ccb *ccb) { struct scsi_xfer *xs = ccb->ccb_cookie; + struct ufshci_ucd *ucd; + struct ufshci_utrd *utrd; + + bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_ucd), + sizeof(*ucd) * ccb->ccb_slot, sizeof(*ucd), + BUS_DMASYNC_POSTWRITE); + bus_dmamap_sync(sc->sc_dmat, UFSHCI_DMA_MAP(sc->sc_dmamem_utrd), + sizeof(*utrd) * ccb->ccb_slot, sizeof(*utrd), + BUS_DMASYNC_POSTWRITE); ccb->ccb_cookie = NULL; ccb->ccb_status = CCB_STATUS_FREE; -- 2.20.1