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 D867EC636CC for ; Tue, 31 Jan 2023 12:59:31 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E235C85A70; Tue, 31 Jan 2023 13:59:28 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="LiZu5Uba"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E741385A78; Tue, 31 Jan 2023 13:59:26 +0100 (CET) Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) (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 B847F8599E for ; Tue, 31 Jan 2023 13:59:22 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jh80.chung@gmail.com Received: by mail-pl1-x631.google.com with SMTP id be8so14956101plb.7 for ; Tue, 31 Jan 2023 04:59:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=SQx+6ITJinee4n9KVlRWgaXD97Qt0pK1bCLoTBMI+9I=; b=LiZu5UbaZ1SgEtlb0tJgKf9NL4/flFmiCdyy8Ni9h6sQvOfN60oCalNqUpAr/QfL+L LJxbcvWbmcxwRRGyjzCF+YM4RE4D6afy1i+rPwyOdrOJf/7WZbOK3eP5Xu5TvC+OATHD bqL3sAZKdiw+HpIRCvRXIpBiFobRQX/hJ+vEu+Txknv4cPtqecrhO/CY2hcolkwNRZCq M7jAuntOtR9PHvtzUqbtKIZ6SsfW6JGmSOJiObAAQwNX71sdnMjfVxYVDvnerRcwATzS NUmSQD6lAzS+rMNdCW04pYWoxLAfCAVpJYLnXpfh1viwBQkGEqXR0OeAQDwK91vqpL9j kFZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SQx+6ITJinee4n9KVlRWgaXD97Qt0pK1bCLoTBMI+9I=; b=Gpyv2xrySvYHPqjP8ehgyMsYjb9FusgtgNThmxq5hgSz6DJf5CoNENMT2Ds/yUp0a1 EzBbVreVBgJlbQj+mhQsOLQYDJdMRw7V8GwRP/nuSB+pnQEsLK5SA5gNrqx7S7cWIWGR 3AY223eHYbXi0BJRKWU/zJrnvtBYfmqxtSyKIF0dPEilZJorjhFPJAS4iMWNcPb+RN39 oPMuq3wOYKIk+hMaC/8yj2tXCt3PmTv4zeSer+WAT8AIYWDqWhVXZxdC91onAN7WDEWa 9Bgljkcb167bBEXEOF/uQSq5sU57y65dDMl/jliMpP4WmT9meLtyf/PzQzED8onhK/8A LgVg== X-Gm-Message-State: AO0yUKU/SAyqnTXN5HFBBRosqteEiJ3i/3L0k5cXsT5X+oXqQarViZKt rJB+Sa1TTWEvvB2bKEnwfjw= X-Google-Smtp-Source: AK7set99JWEdtI6IbMZuzEN+CMnS/P+T/mfUq+a0iciiiKZISAt4eCf9Eo8FG1zsLhny+Mk/I9S9QQ== X-Received: by 2002:a17:903:18c:b0:196:4624:1691 with SMTP id z12-20020a170903018c00b0019646241691mr22424139plg.54.1675169960929; Tue, 31 Jan 2023 04:59:20 -0800 (PST) Received: from [192.168.0.18] ([183.99.112.216]) by smtp.gmail.com with ESMTPSA id o9-20020a1709026b0900b00180033438a0sm9671288plk.106.2023.01.31.04.59.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 31 Jan 2023 04:59:20 -0800 (PST) Message-ID: <7017743b-298d-2cce-d55f-bfc9263dfc70@gmail.com> Date: Tue, 31 Jan 2023 21:59:17 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v2] cmd: mmc: Expand bkops handling Content-Language: en-US To: Marek Vasut , u-boot@lists.denx.de Cc: Jaehoon Chung , Peng Fan References: <20230105141908.160343-1-marex@denx.de> From: Jaehoon Chung In-Reply-To: <20230105141908.160343-1-marex@denx.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 On 1/5/23 23:19, Marek Vasut wrote: > Add more capable "bkops" command which allows enabling and disabling both > manual and automatic bkops. The existing 'mmc bkops-enable' subcommand is > poorly named to cover all the possibilities, hence the new-ish subcommand. > Note that both commands are wrappers around the same common code. > > Signed-off-by: Marek Vasut Reviewed-by: Jaehoon Chung Best Regards, Jaehoon Chung > --- > Cc: Jaehoon Chung > Cc: Peng Fan > --- > V2: - Add kerneldoc comment to mmc_set_bkops_enable > - Drop ifdef around mmc_set_bkops_enable in mmc.h > --- > cmd/mmc.c | 49 +++++++++++++++++++++++++++++++++++++++-------- > drivers/mmc/mmc.c | 14 +++++++++----- > include/mmc.h | 14 +++++++++++--- > 3 files changed, 61 insertions(+), 16 deletions(-) > > diff --git a/cmd/mmc.c b/cmd/mmc.c > index c79d9407986..94deb9a1686 100644 > --- a/cmd/mmc.c > +++ b/cmd/mmc.c > @@ -1020,16 +1020,12 @@ static int do_mmc_setdsr(struct cmd_tbl *cmdtp, int flag, > } > > #ifdef CONFIG_CMD_BKOPS_ENABLE > -static int do_mmc_bkops_enable(struct cmd_tbl *cmdtp, int flag, > - int argc, char *const argv[]) > +static int mmc_bkops_common(char *device, bool autobkops, bool enable) > { > - int dev; > struct mmc *mmc; > + int dev; > > - if (argc != 2) > - return CMD_RET_USAGE; > - > - dev = dectoul(argv[1], NULL); > + dev = dectoul(device, NULL); > > mmc = init_mmc_device(dev, false); > if (!mmc) > @@ -1040,7 +1036,41 @@ static int do_mmc_bkops_enable(struct cmd_tbl *cmdtp, int flag, > return CMD_RET_FAILURE; > } > > - return mmc_set_bkops_enable(mmc); > + return mmc_set_bkops_enable(mmc, autobkops, enable); > +} > + > +static int do_mmc_bkops(struct cmd_tbl *cmdtp, int flag, > + int argc, char * const argv[]) > +{ > + bool autobkops, enable; > + > + if (argc != 4) > + return CMD_RET_USAGE; > + > + if (!strcmp(argv[2], "manual")) > + autobkops = false; > + else if (!strcmp(argv[2], "auto")) > + autobkops = true; > + else > + return CMD_RET_FAILURE; > + > + if (!strcmp(argv[3], "disable")) > + enable = false; > + else if (!strcmp(argv[3], "enable")) > + enable = true; > + else > + return CMD_RET_FAILURE; > + > + return mmc_bkops_common(argv[1], autobkops, enable); > +} > + > +static int do_mmc_bkops_enable(struct cmd_tbl *cmdtp, int flag, > + int argc, char * const argv[]) > +{ > + if (argc != 2) > + return CMD_RET_USAGE; > + > + return mmc_bkops_common(argv[1], false, true); > } > #endif > > @@ -1102,6 +1132,7 @@ static struct cmd_tbl cmd_mmc[] = { > U_BOOT_CMD_MKENT(setdsr, 2, 0, do_mmc_setdsr, "", ""), > #ifdef CONFIG_CMD_BKOPS_ENABLE > U_BOOT_CMD_MKENT(bkops-enable, 2, 0, do_mmc_bkops_enable, "", ""), > + U_BOOT_CMD_MKENT(bkops, 4, 0, do_mmc_bkops, "", ""), > #endif > }; > > @@ -1188,6 +1219,8 @@ U_BOOT_CMD( > #ifdef CONFIG_CMD_BKOPS_ENABLE > "mmc bkops-enable - enable background operations handshake on device\n" > " WARNING: This is a write-once setting.\n" > + "mmc bkops [auto|manual] [enable|disable]\n" > + " - configure background operations handshake on device\n" > #endif > ); > > diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c > index 210703ea46b..afbc497b12c 100644 > --- a/drivers/mmc/mmc.c > +++ b/drivers/mmc/mmc.c > @@ -3127,9 +3127,10 @@ int mmc_init_device(int num) > #endif > > #ifdef CONFIG_CMD_BKOPS_ENABLE > -int mmc_set_bkops_enable(struct mmc *mmc) > +int mmc_set_bkops_enable(struct mmc *mmc, bool autobkops, bool enable) > { > int err; > + u32 bit = autobkops ? BIT(1) : BIT(0); > ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN); > > err = mmc_send_ext_csd(mmc, ext_csd); > @@ -3143,18 +3144,21 @@ int mmc_set_bkops_enable(struct mmc *mmc) > return -EMEDIUMTYPE; > } > > - if (ext_csd[EXT_CSD_BKOPS_EN] & 0x1) { > + if (enable && (ext_csd[EXT_CSD_BKOPS_EN] & bit)) { > puts("Background operations already enabled\n"); > return 0; > } > > - err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BKOPS_EN, 1); > + err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BKOPS_EN, > + enable ? bit : 0); > if (err) { > - puts("Failed to enable manual background operations\n"); > + printf("Failed to %sable manual background operations\n", > + enable ? "en" : "dis"); > return err; > } > > - puts("Enabled manual background operations\n"); > + printf("%sabled %s background operations\n", > + enable ? "En" : "Dis", autobkops ? "auto" : "manual"); > > return 0; > } > diff --git a/include/mmc.h b/include/mmc.h > index 571fa625d02..36dd841d5d1 100644 > --- a/include/mmc.h > +++ b/include/mmc.h > @@ -892,9 +892,17 @@ int mmc_rpmb_write(struct mmc *mmc, void *addr, unsigned short blk, > int mmc_rpmb_route_frames(struct mmc *mmc, void *req, unsigned long reqlen, > void *rsp, unsigned long rsplen); > > -#ifdef CONFIG_CMD_BKOPS_ENABLE > -int mmc_set_bkops_enable(struct mmc *mmc); > -#endif > +/** > + * mmc_set_bkops_enable() - enable background operations > + * @param mmc Pointer to a MMC device struct > + * @param autobkops Enable automatic bkops, not manual bkops > + * @param enable Enable bkops, not disable > + * > + * Enable or disable automatic or manual background operation of the eMMC. > + * > + * Return: 0 on success, <0 on error. > + */ > +int mmc_set_bkops_enable(struct mmc *mmc, bool autobkops, bool enable); > > /** > * Start device initialization and return immediately; it does not block on