aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-09-21 16:21:41 +0200
committerSimon Glass <sjg@chromium.org>2022-09-25 08:30:05 -0600
commitf75b6f76a484b24a346a1cd46a7e2553383a583d (patch)
treeb83647497009c46271099b75b13c671c018f2e35
parentf148ad1b5fb14a3295ced502647de5be69e46100 (diff)
downloadu-boot-f75b6f76a484b24a346a1cd46a7e2553383a583d.zip
u-boot-f75b6f76a484b24a346a1cd46a7e2553383a583d.tar.gz
u-boot-f75b6f76a484b24a346a1cd46a7e2553383a583d.tar.bz2
sandbox: scsi: Move reply setup out of helper
Move this code out of the helper function so we can (later) add it as part of the shared emulation code. Set a default value of 0 for buff_used since that is what we use when there is an error. Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r--drivers/usb/emul/sandbox_flash.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/drivers/usb/emul/sandbox_flash.c b/drivers/usb/emul/sandbox_flash.c
index 3c5bc67..e699f89 100644
--- a/drivers/usb/emul/sandbox_flash.c
+++ b/drivers/usb/emul/sandbox_flash.c
@@ -181,14 +181,12 @@ static int sandbox_flash_control(struct udevice *dev, struct usb_device *udev,
static void setup_fail_response(struct sandbox_flash_priv *priv)
{
- struct scsi_emul_info *info = &priv->eminfo;
struct umass_bbb_csw *csw = &priv->status;
csw->dCSWSignature = CSWSIGNATURE;
csw->dCSWTag = priv->tag;
csw->dCSWDataResidue = 0;
csw->bCSWStatus = CSWSTATUS_FAILED;
- info->buff_used = 0;
}
/**
@@ -198,19 +196,14 @@ static void setup_fail_response(struct sandbox_flash_priv *priv)
* @resp: Response to send, or NULL if none
* @size: Size of response
*/
-static void setup_response(struct sandbox_flash_priv *priv, void *resp,
- int size)
+static void setup_response(struct sandbox_flash_priv *priv)
{
- struct scsi_emul_info *info = &priv->eminfo;
struct umass_bbb_csw *csw = &priv->status;
csw->dCSWSignature = CSWSIGNATURE;
csw->dCSWTag = priv->tag;
csw->dCSWDataResidue = 0;
csw->bCSWStatus = CSWSTATUS_GOOD;
-
- assert(!resp || resp == info->buff);
- info->buff_used = size;
}
static void handle_read(struct sandbox_flash_priv *priv, ulong lba,
@@ -222,8 +215,8 @@ static void handle_read(struct sandbox_flash_priv *priv, ulong lba,
info->read_len = transfer_len;
if (priv->fd != -1) {
os_lseek(priv->fd, lba * info->block_size, OS_SEEK_SET);
- setup_response(priv, info->buff,
- transfer_len * info->block_size);
+ info->buff_used = transfer_len * info->block_size;
+ setup_response(priv);
} else {
setup_fail_response(priv);
}
@@ -236,6 +229,7 @@ static int handle_ufi_command(struct sandbox_flash_plat *plat,
struct scsi_emul_info *info = &priv->eminfo;
const struct scsi_cmd *req = buff;
+ info->buff_used = 0;
switch (*req->cmd) {
case SCSI_INQUIRY: {
struct scsi_inquiry_resp *resp = (void *)info->buff;
@@ -247,11 +241,12 @@ static int handle_ufi_command(struct sandbox_flash_plat *plat,
strncpy(resp->vendor, info->vendor, sizeof(resp->vendor));
strncpy(resp->product, info->product, sizeof(resp->product));
strncpy(resp->revision, "1.0", sizeof(resp->revision));
- setup_response(priv, resp, sizeof(*resp));
+ info->buff_used = sizeof(*resp);
+ setup_response(priv);
break;
}
case SCSI_TST_U_RDY:
- setup_response(priv, NULL, 0);
+ setup_response(priv);
break;
case SCSI_RD_CAPAC: {
struct scsi_read_capacity_resp *resp = (void *)info->buff;
@@ -263,7 +258,8 @@ static int handle_ufi_command(struct sandbox_flash_plat *plat,
blocks = 0;
resp->last_block_addr = cpu_to_be32(blocks);
resp->block_len = cpu_to_be32(info->block_size);
- setup_response(priv, resp, sizeof(*resp));
+ info->buff_used = sizeof(*resp);
+ setup_response(priv);
break;
}
case SCSI_READ10: {