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 DA7BEC0502A for ; Sat, 27 Aug 2022 15:18:18 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 546C384979; Sat, 27 Aug 2022 17:16:59 +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="HYNYOleP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 46A9584976; Sat, 27 Aug 2022 17:16:27 +0200 (CEST) Received: from mail-oa1-x2f.google.com (mail-oa1-x2f.google.com [IPv6:2001:4860:4864:20::2f]) (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 850FA84945 for ; Sat, 27 Aug 2022 17:16:18 +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-x2f.google.com with SMTP id 586e51a60fabf-11c896b879bso5646339fac.3 for ; Sat, 27 Aug 2022 08:16:18 -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=51aht+9cVrTAYlyp738T+Xz0f29RkPWM+8WcMOnReDQ=; b=HYNYOlePbjd+B7XaPWUauELeIdXjLAC0FdD71oZ3YVqnwPvfLuo9secJV9fRS0jPaN pVyDGLFil4cS/drn5kxyS3NthedQKi0woL4ZVwlVYYcka9fPbgW9Zk287O8FR/YSLdsM fQa15BcjcdrdOPD8iN+0r4rcOH+w21R4dzPPU= 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=51aht+9cVrTAYlyp738T+Xz0f29RkPWM+8WcMOnReDQ=; b=5w3vC1cjAid1qZ36DdPYHQQe7JeuF9js4b3z37DncziXXPYyAjuTiOEy/slIVbnAP3 XYpk7i6ny1KXjnFAgEfpe9dn5sGNKTwKKQDTSFPFeNaL/Yc8BSa3o8oeQP9PRjceEb4T 4Ee0ejQzLtcNyAerwbju61Q6kt7FsGzUFVfNNkxssheNJlqpK4Lt4zc7UiC5ga5aQ1br bdMRHwZi/2/tojmk4NP1BZHulmfLg7K7UVpXI3BTSjnaxhcSrjGboQMbi48bizLGv6LK 5HqCuQZmwLj9C+KQftnQrreX3TAf2mCzOzkd4yrnHJO375x77d6A5ZaVX3EZyl3Zu+5G lYWA== X-Gm-Message-State: ACgBeo2s8P56UxfXfG5i3B/4NRBb+0RjFgx/19RvO7g8b/2c2ogrQZ8U G9/t1ytO5xYl45augqcnEThvEnTxIzT7hw== X-Google-Smtp-Source: AA6agR4m9LTCs5TVMy6v28nbkJAIdUw9g/OfMphrqhfVelmM3tHqlWfr1dWT4pWColG7hTGUk+VK0w== X-Received: by 2002:a05:6870:f149:b0:dd:f3b0:986d with SMTP id l9-20020a056870f14900b000ddf3b0986dmr4042212oac.148.1661613354884; Sat, 27 Aug 2022 08:15:54 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Aug 2022 08:15:54 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Mario Six , Michal Simek , Rick Chen , Sean Anderson Subject: [PATCH 14/15] sandbox: Convert to use driver model for SCSI Date: Sat, 27 Aug 2022 09:15:12 -0600 Message-Id: <20220827151513.736395-15-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 At present sandbox is producing a warning about SCSI migration. Drop the legacy code and replace it with a new implementation. Also drop the SATA command, which does not work with driver model. Signed-off-by: Simon Glass --- arch/Kconfig | 1 - configs/sandbox64_defconfig | 1 + configs/sandbox_defconfig | 1 + configs/sandbox_flattree_defconfig | 1 + configs/sandbox_noinst_defconfig | 1 + configs/sandbox_spl_defconfig | 1 + configs/sandbox_vpl_defconfig | 1 + drivers/scsi/sandbox_scsi.c | 132 ++++++++++++++++++++++++++++- 8 files changed, 135 insertions(+), 4 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 994fd3b7f86..1ffd77c0f4f 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -166,7 +166,6 @@ config SANDBOX imply CMD_IO imply CMD_IOTRACE imply CMD_LZMADEC - imply CMD_SATA imply CMD_SF imply CMD_SF_TEST imply CRC32_VERIFY diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index fdbb6eb4b85..deefc99d8d1 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -205,6 +205,7 @@ CONFIG_SANDBOX_RESET=y CONFIG_DM_RTC=y CONFIG_RTC_RV8803=y CONFIG_SCSI=y +CONFIG_DM_SCSI=y CONFIG_SCSI_AHCI_PLAT=y CONFIG_SYS_SCSI_MAX_SCSI_ID=8 CONFIG_SYS_SCSI_MAX_LUN=4 diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 3e9bb9e628d..c7026da1bbf 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -263,6 +263,7 @@ CONFIG_RESET_SCMI=y CONFIG_DM_RTC=y CONFIG_RTC_RV8803=y CONFIG_SCSI=y +CONFIG_DM_SCSI=y CONFIG_SCSI_AHCI_PLAT=y CONFIG_SYS_SCSI_MAX_SCSI_ID=8 CONFIG_SYS_SCSI_MAX_LUN=4 diff --git a/configs/sandbox_flattree_defconfig b/configs/sandbox_flattree_defconfig index 95ff77d8824..226a36f0fe9 100644 --- a/configs/sandbox_flattree_defconfig +++ b/configs/sandbox_flattree_defconfig @@ -176,6 +176,7 @@ CONFIG_DM_RESET=y CONFIG_SANDBOX_RESET=y CONFIG_DM_RTC=y CONFIG_SCSI=y +CONFIG_DM_SCSI=y CONFIG_SCSI_AHCI_PLAT=y CONFIG_SYS_SCSI_MAX_SCSI_ID=8 CONFIG_SYS_SCSI_MAX_LUN=4 diff --git a/configs/sandbox_noinst_defconfig b/configs/sandbox_noinst_defconfig index dcae8fa2582..e4bf05df1d8 100644 --- a/configs/sandbox_noinst_defconfig +++ b/configs/sandbox_noinst_defconfig @@ -202,6 +202,7 @@ CONFIG_SANDBOX_RESET=y CONFIG_DM_RTC=y CONFIG_SPL_DM_RTC=y CONFIG_SCSI=y +CONFIG_DM_SCSI=y CONFIG_SCSI_AHCI_PLAT=y CONFIG_SYS_SCSI_MAX_SCSI_ID=8 CONFIG_SYS_SCSI_MAX_LUN=4 diff --git a/configs/sandbox_spl_defconfig b/configs/sandbox_spl_defconfig index 9454e942315..fcaee771055 100644 --- a/configs/sandbox_spl_defconfig +++ b/configs/sandbox_spl_defconfig @@ -205,6 +205,7 @@ CONFIG_SANDBOX_RESET=y CONFIG_DM_RTC=y CONFIG_SPL_DM_RTC=y CONFIG_SCSI=y +CONFIG_DM_SCSI=y CONFIG_SCSI_AHCI_PLAT=y CONFIG_SYS_SCSI_MAX_SCSI_ID=8 CONFIG_SYS_SCSI_MAX_LUN=4 diff --git a/configs/sandbox_vpl_defconfig b/configs/sandbox_vpl_defconfig index f5ef760b5d5..593e72aa6a7 100644 --- a/configs/sandbox_vpl_defconfig +++ b/configs/sandbox_vpl_defconfig @@ -211,6 +211,7 @@ CONFIG_DM_RTC=y CONFIG_SPL_DM_RTC=y CONFIG_TPL_DM_RTC=y CONFIG_SCSI=y +CONFIG_DM_SCSI=y CONFIG_SCSI_AHCI_PLAT=y CONFIG_SYS_SCSI_MAX_SCSI_ID=8 CONFIG_SYS_SCSI_MAX_LUN=4 diff --git a/drivers/scsi/sandbox_scsi.c b/drivers/scsi/sandbox_scsi.c index 39b969a4b2f..a7ac33cb1c4 100644 --- a/drivers/scsi/sandbox_scsi.c +++ b/drivers/scsi/sandbox_scsi.c @@ -7,19 +7,145 @@ * that CONFIG_SCSI can be enabled for sandbox. */ +#define LOG_CATEGORY UCLASS_SCSI + #include +#include +#include +#include #include +#include + +enum { + SANDBOX_SCSI_BLOCK_LEN = 512, + SANDBOX_SCSI_BUF_SIZE = 512, +}; + +/** + * struct sandbox_scsi_priv + * + * @eminfo: emulator state + * @pathanme: Path to the backing file, e.g. 'scsi.img' + * @fd: File descriptor of backing file + */ +struct sandbox_scsi_priv { + struct scsi_emul_info eminfo; + const char *pathname; + int fd; +}; -int scsi_bus_reset(struct udevice *dev) +static int sandbox_scsi_exec(struct udevice *dev, struct scsi_cmd *req) { + struct sandbox_scsi_priv *priv = dev_get_priv(dev); + struct scsi_emul_info *info = &priv->eminfo; + int ret; + + if (req->lun || req->target) + return -EIO; + ret = sb_scsi_emul_command(info, req, req->cmdlen); + if (ret < 0) { + log_debug("SCSI command 0x%02x ret errno %d\n", req->cmd[0], + ret); + return ret; + } else if (ret == SCSI_EMUL_DO_READ && priv->fd != -1) { + long bytes_read; + + log_debug("read %x %x\n", info->seek_block, info->read_len); + os_lseek(priv->fd, info->seek_block * info->block_size, + OS_SEEK_SET); + bytes_read = os_read(priv->fd, req->pdata, info->buff_used); + if (bytes_read < 0) + return bytes_read; + if (bytes_read != info->buff_used) + return -EIO; + } else if (!ret) { + req->pdata = info->buff; + info->phase = SCSIPH_STATUS; + log_debug("sending buf\n"); + } else { + log_debug("error\n"); + return -EIO; + } + return 0; } -void scsi_init(void) +static int sandbox_scsi_bus_reset(struct udevice *dev) { + /* Not implemented */ + + return 0; } -int scsi_exec(struct udevice *dev, struct scsi_cmd *pccb) +static int sandbox_scsi_of_to_plat(struct udevice *dev) { + struct sandbox_scsi_priv *priv = dev_get_priv(dev); + + priv->pathname = dev_read_string(dev, "sandbox,filepath"); + return 0; } + +static int sandbox_scsi_probe(struct udevice *dev) +{ + struct scsi_plat *scsi_plat = dev_get_uclass_plat(dev); + struct sandbox_scsi_priv *priv = dev_get_priv(dev); + struct scsi_emul_info *info = &priv->eminfo; + int ret; + + scsi_plat->max_id = 2; + scsi_plat->max_lun = 3; + scsi_plat->max_bytes_per_req = 1 << 20; + + info->vendor = "SANDBOX"; + info->product = "FAKE DISK"; + info->buff = malloc(SANDBOX_SCSI_BUF_SIZE); + if (!info->buff) + return log_ret(-ENOMEM); + info->block_size = SANDBOX_SCSI_BLOCK_LEN; + + if (priv->pathname) { + priv->fd = os_open(priv->pathname, OS_O_RDONLY); + if (priv->fd != -1) { + ret = os_get_filesize(priv->pathname, &info->file_size); + if (ret) + return log_msg_ret("sz", ret); + } + } else { + priv->fd = -1; + } + log_debug("filename: %s, fd %d\n", priv->pathname, priv->fd); + + return 0; +} + +static int sandbox_scsi_remove(struct udevice *dev) +{ + struct sandbox_scsi_priv *priv = dev_get_priv(dev); + struct scsi_emul_info *info = &priv->eminfo; + + free(info->buff); + + return 0; +} + +struct scsi_ops sandbox_scsi_ops = { + .exec = sandbox_scsi_exec, + .bus_reset = sandbox_scsi_bus_reset, +}; + +static const struct udevice_id sanbox_scsi_ids[] = { + { .compatible = "sandbox,scsi" }, + { } +}; + +U_BOOT_DRIVER(sandbox_scsi) = { + .name = "sandbox_scsi", + .id = UCLASS_SCSI, + .ops = &sandbox_scsi_ops, + .of_match = sanbox_scsi_ids, + .of_to_plat = sandbox_scsi_of_to_plat, + .probe = sandbox_scsi_probe, + .remove = sandbox_scsi_remove, + .priv_auto = sizeof(struct sandbox_scsi_priv), +}; -- 2.37.2.672.g94769d06f0-goog