Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp3128825lkv; Mon, 10 May 2021 08:18:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzj8mwRKjkfA4bpNAbkxQ14ESvbuLJJxOB8TF1SlNto318BanqeHMdBpbVx2JZxZSSPLA9W X-Received: by 2002:a17:906:e118:: with SMTP id gj24mr26806121ejb.205.1620659897373; Mon, 10 May 2021 08:18:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620659897; cv=none; d=google.com; s=arc-20160816; b=b+YyNICMQIXkDUtL1sm0IL2tsRy67+T2TkMyM6IBco1tan9wWrgPuVJQkyg11h65Eh 3RI9aJyxthAArA2g1Ecqr6diKOV7KqxkRReFa2dDpnvsFxjMc6OXHBbm9oixmfWmNaz7 /r9Tv9FU41ZL446ZetZkDv0wjyjeD4iWHlPhV87lM8R3JYTM9sl0VdaWqyHw+IupzzOs bdkOUA5/4/1ky64zpZ6S1s32LZMa2h21BUIl03iC7XMyt8UcAZhVO2gGYhjNw34261Ew 9jsuc2TlWpFAWKCT3VLGrAZMbUVQZjgJBr0I+vMUxyf2Ld5PttMwyBQOCDrDppRHWyXZ yUjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=nGZx3IHlZolc8cpiUp7UZIMaVX9aP3c8CsMB4Q5ljJQ=; b=Uf15D3WPmTs8ehknfhUnXvzjevafJSOdECDDCTvMl2HieVFT/QFlAZtF0KeTAMCsbq H1R6T3ZofMcga+/H/sNYBfJRhPboR7I4jeGVrVJi3vzqVBZGleFYNzxFJxE0JcnwYf5V hwMYEjCeSm0rqmXq1drVcN+EolFZN44zJ211RaeOcSNjQ5dSCG3LPRhLqhsAzJ4Ez18q TXycXOya9mnnI3MO0waa78wBNhf5jUB4sWNPdd0hRW7qm6Er5oDQ8SIYG0VbTQ3xk0+L qpyDnsrJSMKw1RRkVCigKIEok3HNel0qOP4q26+E96sETF3+ceKV35TovCiCGtqEWsEF DeDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QQ51fpoX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kg22si14289349ejc.723.2021.05.10.08.17.53; Mon, 10 May 2021 08:18:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QQ51fpoX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241323AbhEJPQv (ORCPT + 99 others); Mon, 10 May 2021 11:16:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241605AbhEJPQA (ORCPT ); Mon, 10 May 2021 11:16:00 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C2F3C0611C5 for ; Mon, 10 May 2021 07:42:21 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id c3so23706993lfs.7 for ; Mon, 10 May 2021 07:42:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nGZx3IHlZolc8cpiUp7UZIMaVX9aP3c8CsMB4Q5ljJQ=; b=QQ51fpoXpyNz4qMgniyay13YXJ5B8HSlgu7JIjxKmsIZ+udNaVEPDeEocaZNmn+d9m OdNcQWPnKD+TFmlwf+gA2nmWPYTnm32vb/fSV8YGs8EFYv9VrVQ4FaDm8pGRydg/22fd Imn0FMzKzzfwxv+UHRncvPvwAdUWxgGkzScrQrbMq8zaGdfIqCcg4VHpMqvnIO3I0nAa Tb6eJP8DPzFkIRBYglU7NjATrZtQ4YYG2wNFMnH2d5CzHWSLwlWMjzg5/YF0C2gCe3H2 raUHkfi/Z0VuD3JldFYqp9BSWbtqyZ9HBNLYWZ02P2acCIyLcPO/OyPp6HIqgs5Uzy7C BDdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nGZx3IHlZolc8cpiUp7UZIMaVX9aP3c8CsMB4Q5ljJQ=; b=Y+wCttGSLDSCHJeyHgsk8dtXR6rQixAt3YsiR2WR01ZTo4YGsCbN3Hh3A7qrYhgD2o 9ZjbaLsv+sIAjmMlEN7V5PzkeUwobzcT4lAj1+C7j2NSqOpnwelvQvUcxtT/iCs9iVry JTCjvgOxkwqya/WNsWjJ+Q3YwIBHqEx7ziT/4W2WcrNJmSv1XzgCNlSsl15zyD9cnv3f DZR4tVJtdDzNjcLL4QkegwlacIEgK69LOYeF9KOPilEiirHUOmWNikywO9c+HMhNGzaX xbbSiyyiOsccNCC9Z9+kZV2rFRngFqLfLKv1LfPLqR90KljAXRFr3m/WRZqNR+8dXNmL b0Cw== X-Gm-Message-State: AOAM532HuqMurDOcCSVVi/w9EJ8IKe+Nmi2s3snBf9x3OWo2AK5bbeo5 Fdmp619QU6eBjlKwUCw8UlBfVW4DG/UVC+Do7kTNFg== X-Received: by 2002:a05:6512:3e14:: with SMTP id i20mr16631717lfv.142.1620657739885; Mon, 10 May 2021 07:42:19 -0700 (PDT) MIME-Version: 1.0 References: <20210506145829.198823-1-ulf.hansson@linaro.org> <20210506145829.198823-3-ulf.hansson@linaro.org> In-Reply-To: From: Ulf Hansson Date: Mon, 10 May 2021 16:41:43 +0200 Message-ID: Subject: Re: [PATCH 2/2] mmc: core: Add support for cache ctrl for SD cards To: Avri Altman Cc: "linux-mmc@vger.kernel.org" , Adrian Hunter , Linus Walleij , Wolfram Sang , Shawn Lin , Masami Hiramatsu , "linux-block@vger.kernel.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 10 May 2021 at 11:10, Avri Altman wrote: > > > +static int sd_enable_cache(struct mmc_card *card) > > +{ > > + u8 *reg_buf; > > + int err; > > + > > + reg_buf = kzalloc(512, GFP_KERNEL); > > + if (!reg_buf) > > + return -ENOMEM; > > + > > + /* > > + * Set the Cache Enable bit in the performance enhancement register at > > + * 260 bytes offset. > > + */ > > + err = sd_write_ext_reg(card, card->ext_perf.fno, card->ext_perf.page, > > + card->ext_perf.offset + 260, 0x1); > > + if (err) { > > + pr_warn("%s: error %d writing Cache Enable bit\n", > > + mmc_hostname(card->host), err); > > + goto out; > > + } > > + > > + err = mmc_poll_for_busy(card, > > SD_WRITE_EXTR_SINGLE_TIMEOUT_MS, false, > > + MMC_BUSY_EXTR_SINGLE); > I think 1sec is for flush cache, but I guess it makes sense to use it here as well. The spec talks about generic busy signaling time for CMD49 of one second. That's why I added this here. > > > + if (!err) > > + card->ext_perf.feature_enabled |= SD_EXT_PERF_CACHE; > Maybe > If (err) > card->ext_perf.feature_enabled &= ~SD_EXT_PERF_CACHE; > > and move to out: to catch the sd_write_ext_reg err ? > > > + > > +out: > > + kfree(reg_buf); > > + return err; > > +} > > + > > /* > > * Handle the detection and initialisation of a card. > > * > > @@ -1442,6 +1531,13 @@ static int mmc_sd_init_card(struct mmc_host > > *host, u32 ocr, > > goto free_card; > > } > > > > + /* Enable internal SD cache if supported. */ > > + if (card->ext_perf.feature_support & SD_EXT_PERF_CACHE) { > > + err = sd_enable_cache(card); > > + if (err) > > + goto free_card; > If cache enablement failed, is it worthwhile to bail out? > Maybe disabling the cache with the appropriate message is enough? Right, good point. Let me also think about how we best reset the .feature_enabled field after a power cycle. Theoretically we could fail to enable a feature after the system has resumed, but then we would still have the correspond bits set. > > > + } > > + > > if (host->cqe_ops && !host->cqe_enabled) { > > err = host->cqe_ops->cqe_enable(host, card); > > if (!err) { > > @@ -1694,6 +1790,8 @@ static const struct mmc_bus_ops mmc_sd_ops = { > > .alive = mmc_sd_alive, > > .shutdown = mmc_sd_suspend, > > .hw_reset = mmc_sd_hw_reset, > > + .cache_enabled = sd_cache_enabled, > > + .flush_cache = sd_flush_cache, > > }; > > I would expect 2 more patches in this series: > - flush cache on power down According to the spec that should not be needed, because that should be managed internally in the SD card when we send a poweroff notification. Did I get that wrong? Do you prefer to send a flush cache as well before the poweroff notification? > - cache disablement events? This I don't know about. Can you elaborate? > > Thanks, > Avri Kind regards Uffe