From a9129097cc3b6649752d0704da42f01d119b2881 Mon Sep 17 00:00:00 2001 From: mglocker Date: Thu, 16 May 2024 10:52:11 +0000 Subject: [PATCH] As of the documentation, the value of the Command UPIU expected_xfer_len field shall be the product of the Logical Block Size and the transfer length field of the CDB. --- sys/dev/ic/ufshci.c | 15 +++++++++++++-- sys/dev/ic/ufshcireg.h | 5 ++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sys/dev/ic/ufshci.c b/sys/dev/ic/ufshci.c index ae69dfa55f8..6cdb154064f 100644 --- a/sys/dev/ic/ufshci.c +++ b/sys/dev/ic/ufshci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ufshci.c,v 1.23 2024/05/15 20:10:27 mglocker Exp $ */ +/* $OpenBSD: ufshci.c,v 1.24 2024/05/16 10:52:11 mglocker Exp $ */ /* * Copyright (c) 2022 Marcus Glocker @@ -1000,6 +1000,8 @@ ufshci_utr_cmd_io(struct ufshci_softc *sc, struct ufshci_ccb *ccb, struct ufshci_utrd *utrd; struct ufshci_ucd *ucd; bus_dmamap_t dmap = ccb->ccb_dmamap; + uint32_t blocks; + uint64_t lba; /* 7.2.1 Basic Steps when Building a UTP Transfer Request: 1) */ slot = ccb->ccb_slot; @@ -1044,7 +1046,16 @@ ufshci_utr_cmd_io(struct ufshci_softc *sc, struct ufshci_ccb *ccb, ucd->cmd.hdr.device_info = 0; ucd->cmd.hdr.ds_len = 0; - ucd->cmd.expected_xfer_len = htobe32(xs->datalen); + /* + * JESD220C-2_1.pdf, page 88, d) Expected Data Transfer Length: + * "When the COMMAND UPIU encodes a SCSI WRITE or SCSI READ command + * (specifically WRITE (6), READ (6), WRITE (10), READ (10), + * WRITE (16), or READ (16)), the value of this field shall be the + * product of the Logical Block Size (bLogicalBlockSize) and the + * TRANSFER LENGTH field of the CDB." + */ + scsi_cmd_rw_decode(&xs->cmd, &lba, &blocks); + ucd->cmd.expected_xfer_len = htobe32(UFSHCI_LBS * blocks); memcpy(ucd->cmd.cdb, &xs->cmd, sizeof(ucd->cmd.cdb)); diff --git a/sys/dev/ic/ufshcireg.h b/sys/dev/ic/ufshcireg.h index 682a855c578..741ecd1fe12 100644 --- a/sys/dev/ic/ufshcireg.h +++ b/sys/dev/ic/ufshcireg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ufshcireg.h,v 1.8 2024/05/15 20:10:27 mglocker Exp $ */ +/* $OpenBSD: ufshcireg.h,v 1.9 2024/05/16 10:52:11 mglocker Exp $ */ /* * Copyright (c) 2022 Marcus Glocker @@ -23,6 +23,9 @@ #define UFSHCI_UCD_PRDT_MAX_XFER (UFSHCI_UCD_PRDT_MAX_SEGS * PAGE_SIZE) #define UFSHCI_INTR_AGGR_TIMEOUT 0x08 /* 320us (1 unit = 40us) */ #define UFSHCI_MAX_UNITS 32 +#define UFSHCI_LBS 4096 /* UFS Logical Block Size: + For UFS minimum size shall be + 4096 bytes */ /* * Controller Capabilities Registers -- 2.20.1