Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1941166pxa; Sun, 23 Aug 2020 23:37:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8LsFBGEoWDdxqYCjUeR+x028iFzwTjqg4ZbW6A9ljga17schZx2BwlCGNf/gyx0c1g6qO X-Received: by 2002:a17:906:b34c:: with SMTP id cd12mr3900207ejb.504.1598251046299; Sun, 23 Aug 2020 23:37:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598251046; cv=none; d=google.com; s=arc-20160816; b=gdt5RB5O7mDI2iUmQKhnNpA+w9NvMB/Qsktq9vLJdhtR0gr16faaqYXyiy5WM1OPXT hMWNC8D0mkqJ3LplDhNiZIrJ0n7kRBaXioTeXEFX4a38Pnr7ECTuua1cgqlXJpKOH+mx hEG6feqgwz4izaDeuhsjjDQZDV/+e6+LZyZDO0LXkStO2mkGpViOZW0cUiHRIy1REEZx zt0Al0I04a1nsHvt5vVaRgUCjmyn9AqzLRRc71/ABQELrxs9+0P/nANo55LmmtH2beNa RQJwGyJVS3S08HMNaQ+Rj/PL1g5bmk1HU+1SSvVLt0pC0/yWt6AKr4bJPK/1qOeRZUji s/hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=g0O7JTTEG8zhra8Bmg9qzPY8D1AcZ5n76o6w8ixndyc=; b=FQku3nX+WUxnlRIyrp+GNxKvQZnLzdswkF6iyp4YDkrkkp7pVfX6CDdBVQluZjZDS9 YheZfDolTnNpoNc5bdLwm6doLl+59HhAM1tx4RhS7QTG6FIjFuY5BVJQfoYsrpWgEE4p DLKyzX96mIhFu446FJwt+cZsRAKLzhQGYq12ZivcM6VNXI0D4h+Rh/9Et9YbX1PJawUb rbYgPAcDThPrzFUomQ6pF3GT6p7U3oeaglEfOmwtlKGYL7oSg8U52+JeJ/4wceAvatwF AJZZX7iysJeh0eLuUfXSOIFdVrVoxLh5Xsik3LTnYX5+nks+vNHVLwpp3V96tAcsDumx vCpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Nc6vsHNo; 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 f12si2973153edv.593.2020.08.23.23.36.58; Sun, 23 Aug 2020 23:37:26 -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=Nc6vsHNo; 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 S1725926AbgHXGeg (ORCPT + 99 others); Mon, 24 Aug 2020 02:34:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725730AbgHXGee (ORCPT ); Mon, 24 Aug 2020 02:34:34 -0400 Received: from mail-ua1-x943.google.com (mail-ua1-x943.google.com [IPv6:2607:f8b0:4864:20::943]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48338C061573 for ; Sun, 23 Aug 2020 23:34:34 -0700 (PDT) Received: by mail-ua1-x943.google.com with SMTP id k3so1227341uae.6 for ; Sun, 23 Aug 2020 23:34:34 -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:content-transfer-encoding; bh=g0O7JTTEG8zhra8Bmg9qzPY8D1AcZ5n76o6w8ixndyc=; b=Nc6vsHNoA7tyvTeoyEk/516QqWonlIVTa5PIghtJCkIBB60ctW7pnM6s1MxqOYQRzj 9flK76JLPqsVr6jgcvEENxKMZhBMdpyVoz46hcu7lELf8vbsU+U0P8W6krU52IU0IE7c y8Aizy9JTOnPM7Qf7hTY1hltjtojdKO7qWriIEWDJS5MI2/L0tkV0tBHLQn6IWc+DJzs xESjMdyDNixzBEK8TXDNbQB0+SsO9CSRn4g2tGoDi4VKi138BqetjefnMfS1HwlFE78X XLE4wmIEHeBSmK99rJxKE4oxirb97De0wSCI9XTBfzsXh1KACd+3xTrGw6evmXQdyN0G czAA== 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:content-transfer-encoding; bh=g0O7JTTEG8zhra8Bmg9qzPY8D1AcZ5n76o6w8ixndyc=; b=FoMpVcrSgXTebaD0aBEa7bh9iPGPopCnJZRVGiMjnQCZIMtXwqWBCw5lYr+s/pINrk RZ2WQ88+gGFJxXhTWH/s2mMOQnC2aVRF7MkojkAfpqGtqU0UDwuWFIxcGy7y8BKYOigY blopZQDR288XA2WyKmsIFDsjS71QFOiXaZ6EJeuVKyfZnNDAU4EjG29zrhIodLFhEGSF 5CXJOf9J7WGkzA4DgmO9POiCIWSkfHZzPdpkPzxA37r/doojyRN1UpxLyxNEqag3WfGH 9DVymHxfBJyb+I4xefJJ9zsUkQdLF9hQe1nyD+542kkYMOs7vlBBzwQBt2r49LSEGLZh BSpg== X-Gm-Message-State: AOAM533sr9pXdTo3UiK3s7r8HUdoV/ZT+O/F0L9V7TC854Dx6fK2ktLu NwFXGpxNOogcv3n/QUJoPUhn18mMxQCOPLoj2cHCaw== X-Received: by 2002:ab0:3a85:: with SMTP id r5mr1733713uaw.100.1598250873271; Sun, 23 Aug 2020 23:34:33 -0700 (PDT) MIME-Version: 1.0 References: <20200716141534.30241-1-ulf.hansson@linaro.org> In-Reply-To: From: Ulf Hansson Date: Mon, 24 Aug 2020 08:33:57 +0200 Message-ID: Subject: Re: [PATCH] mmc: core: Initial support for SD express card/host To: =?UTF-8?B?5Yav6ZSQ?= Cc: Christoph Hellwig , Arnd Bergmann , "linux-nvme@lists.infradead.org" , "linux-mmc@vger.kernel.org" , Linux PCI , Linux Kernel Mailing List , Adrian Hunter , Greg Kroah-Hartman Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 24 Aug 2020 at 03:04, =E5=86=AF=E9=94=90 = wrote: > > Hi Hansson: > > If this patch will not be changed, I will post a patch for rtsx driver ac= cording your patch. I don't think there is any change needed, unless you think so. Kind regards Uffe > > > > > Rui, > > > > On Thu, 16 Jul 2020 at 16:16, Ulf Hansson wrot= e: > > > > > > In the SD specification v7.10 the SD express card has been added. Thi= s > > > new type of removable SD card, can be managed via a PCIe/NVMe based > > > interface, while also allowing backwards compatibility towards the > > > legacy SD interface. > > > > > > To keep the backwards compatibility, it's required to start the > > > initialization through the legacy SD interface. If it turns out that > > > the mmc host and the SD card, both supports the PCIe/NVMe interface, > > > then a switch should be allowed. > > > > > > Therefore, let's introduce some basic support for this type of SD > > > cards to the mmc core. The mmc host, should set MMC_CAP2_SD_EXP if it > > > supports this interface and MMC_CAP2_SD_EXP_1_2V, if also 1.2V is > > > supported, as to inform the core about it. > > > > > > To deal with the switch to the PCIe/NVMe interface, the mmc host is > > > required to implement a new host ops, ->init_sd_express(). Based on > > > the initial communication between the host and the card, > > > host->ios.timing is set to either MMC_TIMING_SD_EXP or > > > MMC_TIMING_SD_EXP_1_2V, depending on if 1.2V is supported or not. In > > > this way, the mmc host can check these values in its ->init_sd_expres= s() ops, > > to know how to proceed with the handover. > > > > > > Note that, to manage card insert/removal, the mmc core sticks with > > > using the ->get_cd() callback, which means it's the host's > > > responsibility to make sure it provides valid data, even if the card > > > may be managed by PCIe/NVMe at the moment. As long as the card seems > > > to be present, the mmc core keeps the card powered on. > > > > > > Cc: Greg Kroah-Hartman > > > Cc: Arnd Bergmann > > > Cc: Christoph Hellwig > > > Cc: Rui Feng > > > Signed-off-by: Ulf Hansson > > > > Rui, did you manage to get some time to look at $subject patch? > > > > If you need some help to understand what's needed to implement the > > corresponding support in drivers/mmc/host/rtsx_pci_sdmmc.c, then please > > just ask. > > > > I think it would make sense to queue changes for rtsx_pci at the same p= oint as > > the mmc core changes. That's because I don't want to maintain code in t= he > > mmc core that's left unused. > > > > Kind regards > > Uffe > > > > > --- > > > drivers/mmc/core/core.c | 15 ++++++++++-- > > > drivers/mmc/core/host.h | 6 +++++ > > > drivers/mmc/core/sd_ops.c | 49 > > > +++++++++++++++++++++++++++++++++++++-- > > > drivers/mmc/core/sd_ops.h | 1 + > > > include/linux/mmc/host.h | 7 ++++++ > > > 5 files changed, 74 insertions(+), 4 deletions(-) > > > > > > diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index > > > 8ccae6452b9c..6673c0f33cc7 100644 > > > --- a/drivers/mmc/core/core.c > > > +++ b/drivers/mmc/core/core.c > > > @@ -2137,8 +2137,12 @@ static int mmc_rescan_try_freq(struct > > mmc_host > > > *host, unsigned freq) > > > > > > mmc_go_idle(host); > > > > > > - if (!(host->caps2 & MMC_CAP2_NO_SD)) > > > - mmc_send_if_cond(host, host->ocr_avail); > > > + if (!(host->caps2 & MMC_CAP2_NO_SD)) { > > > + if (mmc_send_if_cond_pcie(host, host->ocr_avail)) > > > + goto out; > > > + if (mmc_card_sd_express(host)) > > > + return 0; > > > + } > > > > > > /* Order's important: probe SDIO, then SD, then MMC */ > > > if (!(host->caps2 & MMC_CAP2_NO_SDIO)) @@ -2153,6 +2157,7 > > @@ > > > static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq) > > > if (!mmc_attach_mmc(host)) > > > return 0; > > > > > > +out: > > > mmc_power_off(host); > > > return -EIO; > > > } > > > @@ -2280,6 +2285,12 @@ void mmc_rescan(struct work_struct *work) > > > goto out; > > > } > > > > > > + /* If an SD express card is present, then leave it as is. */ > > > + if (mmc_card_sd_express(host)) { > > > + mmc_release_host(host); > > > + goto out; > > > + } > > > + > > > for (i =3D 0; i < ARRAY_SIZE(freqs); i++) { > > > unsigned int freq =3D freqs[i]; > > > if (freq > host->f_max) { diff --git > > > a/drivers/mmc/core/host.h b/drivers/mmc/core/host.h index > > > 5e3b9534ffb2..ba407617ed23 100644 > > > --- a/drivers/mmc/core/host.h > > > +++ b/drivers/mmc/core/host.h > > > @@ -77,5 +77,11 @@ static inline bool mmc_card_hs400es(struct > > mmc_card *card) > > > return card->host->ios.enhanced_strobe; } > > > > > > +static inline bool mmc_card_sd_express(struct mmc_host *host) { > > > + return host->ios.timing =3D=3D MMC_TIMING_SD_EXP || > > > + host->ios.timing =3D=3D MMC_TIMING_SD_EXP_1_2V; } > > > + > > > #endif > > > > > > diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c > > > index 22bf528294b9..d61ff811218c 100644 > > > --- a/drivers/mmc/core/sd_ops.c > > > +++ b/drivers/mmc/core/sd_ops.c > > > @@ -158,7 +158,8 @@ int mmc_send_app_op_cond(struct mmc_host *host, > > u32 ocr, u32 *rocr) > > > return err; > > > } > > > > > > -int mmc_send_if_cond(struct mmc_host *host, u32 ocr) > > > +static int __mmc_send_if_cond(struct mmc_host *host, u32 ocr, u8 > > pcie_bits, > > > + u32 *resp) > > > { > > > struct mmc_command cmd =3D {}; > > > int err; > > > @@ -171,7 +172,7 @@ int mmc_send_if_cond(struct mmc_host *host, u32 > > ocr) > > > * SD 1.0 cards. > > > */ > > > cmd.opcode =3D SD_SEND_IF_COND; > > > - cmd.arg =3D ((ocr & 0xFF8000) !=3D 0) << 8 | test_pattern; > > > + cmd.arg =3D ((ocr & 0xFF8000) !=3D 0) << 8 | pcie_bits << 8 | > > > + test_pattern; > > > cmd.flags =3D MMC_RSP_SPI_R7 | MMC_RSP_R7 | > > MMC_CMD_BCR; > > > > > > err =3D mmc_wait_for_cmd(host, &cmd, 0); @@ -186,6 +187,50 > > @@ > > > int mmc_send_if_cond(struct mmc_host *host, u32 ocr) > > > if (result_pattern !=3D test_pattern) > > > return -EIO; > > > > > > + if (resp) > > > + *resp =3D cmd.resp[0]; > > > + > > > + return 0; > > > +} > > > + > > > +int mmc_send_if_cond(struct mmc_host *host, u32 ocr) { > > > + return __mmc_send_if_cond(host, ocr, 0, NULL); } > > > + > > > +int mmc_send_if_cond_pcie(struct mmc_host *host, u32 ocr) { > > > + u32 resp =3D 0; > > > + u8 pcie_bits =3D 0; > > > + int ret; > > > + > > > + if (host->caps2 & MMC_CAP2_SD_EXP) { > > > + /* Probe card for SD express support via PCIe. */ > > > + pcie_bits =3D 0x10; > > > + if (host->caps2 & MMC_CAP2_SD_EXP_1_2V) > > > + /* Probe also for 1.2V support. */ > > > + pcie_bits =3D 0x30; > > > + } > > > + > > > + ret =3D __mmc_send_if_cond(host, ocr, pcie_bits, &resp); > > > + if (ret) > > > + return 0; > > > + > > > + /* Continue with the SD express init, if the card supports it= . */ > > > + resp &=3D 0x3000; > > > + if (pcie_bits && resp) { > > > + if (resp =3D=3D 0x3000) > > > + host->ios.timing =3D > > MMC_TIMING_SD_EXP_1_2V; > > > + else > > > + host->ios.timing =3D MMC_TIMING_SD_EXP; > > > + > > > + /* > > > + * According to the spec the clock shall also be gate= d, but > > > + * let's leave this to the host driver for more flexi= bility. > > > + */ > > > + return host->ops->init_sd_express(host, &host->ios); > > > + } > > > + > > > return 0; > > > } > > > > > > diff --git a/drivers/mmc/core/sd_ops.h b/drivers/mmc/core/sd_ops.h > > > index 2194cabfcfc5..3ba7b3cf4652 100644 > > > --- a/drivers/mmc/core/sd_ops.h > > > +++ b/drivers/mmc/core/sd_ops.h > > > @@ -16,6 +16,7 @@ struct mmc_host; > > > int mmc_app_set_bus_width(struct mmc_card *card, int width); int > > > mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr); int > > > mmc_send_if_cond(struct mmc_host *host, u32 ocr); > > > +int mmc_send_if_cond_pcie(struct mmc_host *host, u32 ocr); > > > int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca)= ; > > > int mmc_app_send_scr(struct mmc_card *card); int mmc_sd_switch(struc= t > > > mmc_card *card, int mode, int group, diff --git > > > a/include/linux/mmc/host.h b/include/linux/mmc/host.h index > > > c5b6e97cb21a..905cddc5e6f3 100644 > > > --- a/include/linux/mmc/host.h > > > +++ b/include/linux/mmc/host.h > > > @@ -60,6 +60,8 @@ struct mmc_ios { > > > #define MMC_TIMING_MMC_DDR52 8 > > > #define MMC_TIMING_MMC_HS200 9 > > > #define MMC_TIMING_MMC_HS400 10 > > > +#define MMC_TIMING_SD_EXP 11 > > > +#define MMC_TIMING_SD_EXP_1_2V 12 > > > > > > unsigned char signal_voltage; /* signalling voltage > > (1.8V or 3.3V) */ > > > > > > @@ -172,6 +174,9 @@ struct mmc_host_ops { > > > */ > > > int (*multi_io_quirk)(struct mmc_card *card, > > > unsigned int direction, int > > > blk_size); > > > + > > > + /* Initialize an SD express card, mandatory for MMC_CAP2_SD_E= XP. > > */ > > > + int (*init_sd_express)(struct mmc_host *host, struct > > mmc_ios *ios); > > > }; > > > > > > struct mmc_cqe_ops { > > > @@ -357,6 +362,8 @@ struct mmc_host { > > > #define MMC_CAP2_HS200_1_2V_SDR (1 << 6) /* can > > support */ > > > #define MMC_CAP2_HS200 (MMC_CAP2_HS200_1_8V_SDR | \ > > > MMC_CAP2_HS200_1_2V_SDR) > > > +#define MMC_CAP2_SD_EXP (1 << 7) /* SD > > express via PCIe */ > > > +#define MMC_CAP2_SD_EXP_1_2V (1 << 8) /* SD express 1.2V > > */ > > > #define MMC_CAP2_CD_ACTIVE_HIGH (1 << 10) /* > > Card-detect signal active high */ > > > #define MMC_CAP2_RO_ACTIVE_HIGH (1 << 11) /* > > Write-protect signal active high */ > > > #define MMC_CAP2_NO_PRESCAN_POWERUP (1 << 14) /* Don't power > > up > > > before scan */ > > > -- > > > 2.20.1 > > > > > > > ------Please consider the environment before printing this e-mail.