From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 36F51ECAAD2 for ; Sat, 27 Aug 2022 15:16:33 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 41F0684220; Sat, 27 Aug 2022 17:16:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="HyW3jOsl"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 50CCB8491E; Sat, 27 Aug 2022 17:15:54 +0200 (CEST) Received: from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com [IPv6:2001:4860:4864:20::2e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2A1AD848E7 for ; Sat, 27 Aug 2022 17:15:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-11ba6e79dd1so5620854fac.12 for ; Sat, 27 Aug 2022 08:15:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=7MEN9EJOCjGuReK9TcCHszF1L6CuGxFJMmuC3bmfbKU=; b=HyW3jOsl66RlNIHiwIB7KzX1LZO9AoJ+BdNWdmKOsAB57iCQgh1bspVYYO/j5tC7V4 SUzb40l7mvlDul8G2XilPDX3yfdpjxNnXloMRsvjIGU8sQwg5TIpVbWYLjHxd+NiXF29 c6ciZiHDQJhGi70iyWs6DqVW8uWKddygY479c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=7MEN9EJOCjGuReK9TcCHszF1L6CuGxFJMmuC3bmfbKU=; b=bPwSLdKKYbc0wn6o0AZN4Onuro0OFeey9ByiCTUCU5We5HGiZ75GzNCW42WuzuhI/o nE/RTDTkwQpsbp/fVbuMI56wB+yNDENDFc2d+jYGH3xuEKk30j64gWjUb+fyOkXPFETx 9VFXVZyke8KCUXS5AIQaCIQnR4acRAsXlB2VYtRpJNmrAQxlZTOyrQmc/e3GxFGMQ7gW lLvJ+OI/LQtJkA/xGJpRXuoMSPWii6ScK2jDZkpgPEUzB0cvV6yrDVycl/ZQ+sg+JZh8 AaRDM1gUXIOXMxI4U359QelJP06df9Sf49soHNkdQ9/vg0xLyGUrc662WikulN6RZ+3/ ii2g== X-Gm-Message-State: ACgBeo2zCb3LD0YiuVUARgBbzuRstVUlz0mabAi80GIc2U69zy5ub+OE A1Y9FgYMLQsBKPA7FTJ1+IeuSY2J0d2EbA== X-Google-Smtp-Source: AA6agR5R6ZzZmxfpOL2UiTQAF79JncJ3p2k71UZVS57sVHxuFFnnkWOp2iq5jGczT6gT9OM90m+9zA== X-Received: by 2002:a05:6870:4729:b0:11d:6e9a:9e15 with SMTP id b41-20020a056870472900b0011d6e9a9e15mr4111426oaq.183.1661613346503; Sat, 27 Aug 2022 08:15:46 -0700 (PDT) Received: from sjg1.lan (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id e9-20020acab509000000b00344a22e71a9sm2466876oif.9.2022.08.27.08.15.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Aug 2022 08:15:46 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Andrew Scull , Marek Vasut , Sean Anderson Subject: [PATCH 05/15] sandbox: Move buffer to scsi_emul_info Date: Sat, 27 Aug 2022 09:15:03 -0600 Message-Id: <20220827151513.736395-6-sjg@chromium.org> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog In-Reply-To: <20220827151513.736395-1-sjg@chromium.org> References: <20220827151513.736395-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Move the buffer into this struct so it can be shared between different implementations. Signed-off-by: Simon Glass --- drivers/usb/emul/sandbox_flash.c | 41 +++++++++++++++++++++++--------- include/scsi_emul.h | 5 ++++ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/drivers/usb/emul/sandbox_flash.c b/drivers/usb/emul/sandbox_flash.c index e7abc0d5c9f..3a9db835eed 100644 --- a/drivers/usb/emul/sandbox_flash.c +++ b/drivers/usb/emul/sandbox_flash.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -22,6 +23,7 @@ enum { SANDBOX_FLASH_EP_OUT = 1, /* endpoints */ SANDBOX_FLASH_EP_IN = 2, SANDBOX_FLASH_BLOCK_LEN = 512, + SANDBOX_FLASH_BUF_SIZE = 512, }; enum { @@ -41,7 +43,6 @@ enum { * @fd: File descriptor of backing file * @file_size: Size of file in bytes * @status_buff: Data buffer for outgoing status - * @buff: Data buffer for outgoing data */ struct sandbox_flash_priv { struct scsi_emul_info eminfo; @@ -50,7 +51,6 @@ struct sandbox_flash_priv { int fd; loff_t file_size; struct umass_bbb_csw status; - u8 buff[512]; }; struct sandbox_flash_plat { @@ -210,7 +210,7 @@ static void setup_response(struct sandbox_flash_priv *priv, void *resp, csw->dCSWDataResidue = 0; csw->bCSWStatus = CSWSTATUS_GOOD; - assert(!resp || resp == priv->buff); + assert(!resp || resp == info->buff); info->buff_used = size; } @@ -223,7 +223,7 @@ 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 * SANDBOX_FLASH_BLOCK_LEN, OS_SEEK_SET); - setup_response(priv, priv->buff, + setup_response(priv, info->buff, transfer_len * SANDBOX_FLASH_BLOCK_LEN); } else { setup_fail_response(priv); @@ -239,7 +239,7 @@ static int handle_ufi_command(struct sandbox_flash_plat *plat, switch (*req->cmd) { case SCSI_INQUIRY: { - struct scsi_inquiry_resp *resp = (void *)priv->buff; + struct scsi_inquiry_resp *resp = (void *)info->buff; info->alloc_len = req->cmd[4]; memset(resp, '\0', sizeof(*resp)); @@ -259,7 +259,7 @@ static int handle_ufi_command(struct sandbox_flash_plat *plat, setup_response(priv, NULL, 0); break; case SCSI_RD_CAPAC: { - struct scsi_read_capacity_resp *resp = (void *)priv->buff; + struct scsi_read_capacity_resp *resp = (void *)info->buff; uint blocks; if (priv->file_size) @@ -342,9 +342,9 @@ static int sandbox_flash_bulk(struct udevice *dev, struct usb_device *udev, } else { if (info->alloc_len && len > info->alloc_len) len = info->alloc_len; - if (len > sizeof(priv->buff)) - len = sizeof(priv->buff); - memcpy(buff, priv->buff, len); + if (len > SANDBOX_FLASH_BUF_SIZE) + len = SANDBOX_FLASH_BUF_SIZE; + memcpy(buff, info->buff, len); info->phase = SCSIPH_STATUS; } return len; @@ -394,10 +394,28 @@ static int sandbox_flash_probe(struct udevice *dev) { struct sandbox_flash_plat *plat = dev_get_plat(dev); struct sandbox_flash_priv *priv = dev_get_priv(dev); + struct scsi_emul_info *info = &priv->eminfo; + int ret; priv->fd = os_open(plat->pathname, OS_O_RDONLY); - if (priv->fd != -1) - return os_get_filesize(plat->pathname, &priv->file_size); + if (priv->fd != -1) { + ret = os_get_filesize(plat->pathname, &priv->file_size); + if (ret) + return log_msg_ret("sz", ret); + } + info->buff = malloc(SANDBOX_FLASH_BUF_SIZE); + if (!info->buff) + return log_ret(-ENOMEM); + + return 0; +} + +static int sandbox_flash_remove(struct udevice *dev) +{ + struct sandbox_flash_priv *priv = dev_get_priv(dev); + struct scsi_emul_info *info = &priv->eminfo; + + free(info->buff); return 0; } @@ -418,6 +436,7 @@ U_BOOT_DRIVER(usb_sandbox_flash) = { .of_match = sandbox_usb_flash_ids, .bind = sandbox_flash_bind, .probe = sandbox_flash_probe, + .remove = sandbox_flash_remove, .of_to_plat = sandbox_flash_of_to_plat, .ops = &sandbox_usb_flash_ops, .priv_auto = sizeof(struct sandbox_flash_priv), diff --git a/include/scsi_emul.h b/include/scsi_emul.h index dec78d239c7..f27c19750b0 100644 --- a/include/scsi_emul.h +++ b/include/scsi_emul.h @@ -20,8 +20,13 @@ * @read_len: Number of bytes of data left in the current read command * @alloc_len: Allocation length from the last incoming command * @transfer_len: Transfer length from CBW header + * @buff: Data buffer for outgoing data */ struct scsi_emul_info { + /* provided by the caller: */ + void *buff; + + /* state maintained by the emulator: */ enum scsi_cmd_phase phase; int buff_used; int read_len; -- 2.37.2.672.g94769d06f0-goog