-/* $OpenBSD: ufshci.c,v 1.7 2024/01/06 13:04:03 mglocker Exp $ */
+/* $OpenBSD: ufshci.c,v 1.8 2024/01/06 13:23:47 mglocker Exp $ */
/*
* Copyright (c) 2022 Marcus Glocker <mglocker@openbsd.org>
uint8_t ufshci_get_taskid(struct ufshci_softc *);
int ufshci_utr_cmd_nop(struct ufshci_softc *);
int ufshci_utr_cmd_lun(struct ufshci_softc *,
- struct ufshci_ccb *, int);
+ struct ufshci_ccb *, struct scsi_xfer *);
int ufshci_utr_cmd_inquiry(struct ufshci_softc *,
- struct ufshci_ccb *, int, int);
+ struct ufshci_ccb *, struct scsi_xfer *);
int ufshci_utr_cmd_capacity16(struct ufshci_softc *,
- struct ufshci_ccb *, int, int);
+ struct ufshci_ccb *, struct scsi_xfer *);
int ufshci_utr_cmd_capacity(struct ufshci_softc *,
- struct ufshci_ccb *, int, int);
+ struct ufshci_ccb *, struct scsi_xfer *);
int ufshci_utr_cmd_io(struct ufshci_softc *,
struct ufshci_ccb *, struct scsi_xfer *, int);
int ufshci_utr_cmd_sync(struct ufshci_softc *,
- struct ufshci_ccb *, int, uint32_t, uint16_t);
+ struct ufshci_ccb *, struct scsi_xfer *,
+ uint32_t, uint16_t);
int ufshci_xfer_complete(struct ufshci_softc *);
/* SCSI */
int
ufshci_utr_cmd_lun(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
- int rsp_size)
+ struct scsi_xfer *xs)
{
int slot, off, len, i;
uint64_t dva;
ucd->cmd.hdr.device_info = 0;
ucd->cmd.hdr.ds_len = 0;
- ucd->cmd.expected_xfer_len = htobe32(rsp_size);
+ ucd->cmd.expected_xfer_len = htobe32(xs->datalen);
ucd->cmd.cdb[0] = REPORT_LUNS;
ucd->cmd.cdb[6] = 0;
ucd->cmd.cdb[7] = 0;
ucd->cmd.cdb[8] = 0;
- ucd->cmd.cdb[9] = rsp_size;
+ ucd->cmd.cdb[9] = xs->datalen;
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 2g) */
/* Already done with above memset */
int
ufshci_utr_cmd_inquiry(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
- int rsp_size, int flags)
+ struct scsi_xfer *xs)
{
int slot, off, len, i;
uint64_t dva;
ucd->cmd.hdr.device_info = 0;
ucd->cmd.hdr.ds_len = 0;
- ucd->cmd.expected_xfer_len = htobe32(rsp_size);
+ ucd->cmd.expected_xfer_len = htobe32(xs->datalen);
ucd->cmd.cdb[0] = INQUIRY; /* 0x12 */
ucd->cmd.cdb[3] = 0;
- ucd->cmd.cdb[4] = rsp_size;
+ ucd->cmd.cdb[4] = xs->datalen;
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 2g) */
/* Already done with above memset */
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 11) */
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 12) */
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 13) */
- if (!ISSET(flags, SCSI_POLL)) {
+ if (!ISSET(xs->flags, SCSI_POLL)) {
UFSHCI_WRITE_4(sc, UFSHCI_REG_UTRIACR,
UFSHCI_REG_UTRIACR_IAEN |
UFSHCI_REG_UTRIACR_IAPWEN |
int
ufshci_utr_cmd_capacity16(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
- int rsp_size, int flags)
+ struct scsi_xfer *xs)
{
int slot, off, len, i;
uint64_t dva;
ucd->cmd.hdr.device_info = 0;
ucd->cmd.hdr.ds_len = 0;
- ucd->cmd.expected_xfer_len = htobe32(rsp_size);
+ ucd->cmd.expected_xfer_len = htobe32(xs->datalen);
ucd->cmd.cdb[0] = READ_CAPACITY_16; /* 0x9e */
ucd->cmd.cdb[1] = 0x10; /* Service Action */
ucd->cmd.cdb[10] = 0;
ucd->cmd.cdb[11] = 0;
ucd->cmd.cdb[12] = 0;
- ucd->cmd.cdb[13] = rsp_size;
+ ucd->cmd.cdb[13] = xs->datalen;
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 2g) */
/* Already done with above memset */
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 11) */
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 12) */
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 13) */
- if (!ISSET(flags, SCSI_POLL)) {
+ if (!ISSET(xs->flags, SCSI_POLL)) {
UFSHCI_WRITE_4(sc, UFSHCI_REG_UTRIACR,
UFSHCI_REG_UTRIACR_IAEN |
UFSHCI_REG_UTRIACR_IAPWEN |
int
ufshci_utr_cmd_capacity(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
- int rsp_size, int flags)
+ struct scsi_xfer *xs)
{
int slot, off, len, i;
uint64_t dva;
ucd->cmd.hdr.device_info = 0;
ucd->cmd.hdr.ds_len = 0;
- ucd->cmd.expected_xfer_len = htobe32(rsp_size);
+ ucd->cmd.expected_xfer_len = htobe32(xs->datalen);
ucd->cmd.cdb[0] = READ_CAPACITY; /* 0x25 */
/* Logical Block Address = 0 for UFS */
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 11) */
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 12) */
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 13) */
- if (!ISSET(flags, SCSI_POLL)) {
+ if (!ISSET(xs->flags, SCSI_POLL)) {
UFSHCI_WRITE_4(sc, UFSHCI_REG_UTRIACR,
UFSHCI_REG_UTRIACR_IAEN |
UFSHCI_REG_UTRIACR_IAPWEN |
int
ufshci_utr_cmd_sync(struct ufshci_softc *sc, struct ufshci_ccb *ccb,
- int flags, uint32_t lba, uint16_t blocks)
+ struct scsi_xfer *xs, uint32_t lba, uint16_t blocks)
{
int slot, off, len;
uint64_t dva;
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 11) */
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 12) */
/* 7.2.1 Basic Steps when Building a UTP Transfer Request: 13) */
- if (!ISSET(flags, SCSI_POLL)) {
+ if (!ISSET(xs->flags, SCSI_POLL)) {
UFSHCI_WRITE_4(sc, UFSHCI_REG_UTRIACR,
UFSHCI_REG_UTRIACR_IAEN |
UFSHCI_REG_UTRIACR_IAPWEN |
ccb->ccb_done = ufshci_scsi_io_done;
/* Response length should be UPIU_SCSI_RSP_INQUIRY_SIZE. */
- ccb->ccb_slot = ufshci_utr_cmd_inquiry(sc, ccb, xs->datalen, xs->flags);
+ ccb->ccb_slot = ufshci_utr_cmd_inquiry(sc, ccb, xs);
if (ccb->ccb_slot == -1)
goto error2;
ccb->ccb_done = ufshci_scsi_io_done;
/* Response length should be UPIU_SCSI_RSP_CAPACITY16_SIZE. */
- ccb->ccb_slot = ufshci_utr_cmd_capacity16(sc, ccb, xs->datalen,
- xs->flags);
+ ccb->ccb_slot = ufshci_utr_cmd_capacity16(sc, ccb, xs);
if (ccb->ccb_slot == -1)
goto error2;
ccb->ccb_done = ufshci_scsi_io_done;
/* Response length should be UPIU_SCSI_RSP_CAPACITY_SIZE */
- ccb->ccb_slot = ufshci_utr_cmd_capacity(sc, ccb, xs->datalen,
- xs->flags);
+ ccb->ccb_slot = ufshci_utr_cmd_capacity(sc, ccb, xs);
if (ccb->ccb_slot == -1)
goto error2;
ccb->ccb_cookie = xs;
ccb->ccb_done = ufshci_scsi_done;
- ccb->ccb_slot = ufshci_utr_cmd_sync(sc, ccb, xs->flags, (uint32_t)lba,
+ ccb->ccb_slot = ufshci_utr_cmd_sync(sc, ccb, xs, (uint32_t)lba,
(uint16_t)blocks);
if (ccb->ccb_slot == -1)
goto error;