Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1586779ybb; Thu, 2 Apr 2020 03:46:44 -0700 (PDT) X-Google-Smtp-Source: APiQypIGXrRn8e2B2ens2ASUaMnNl3fCI0Fd0NPi6kJXjpq8U1vPyJvjSdtsiyL4AODWBeMHbqmw X-Received: by 2002:a9d:1a3:: with SMTP id e32mr1901947ote.206.1585824404555; Thu, 02 Apr 2020 03:46:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585824404; cv=none; d=google.com; s=arc-20160816; b=IXgSpJtzm0dM7hT3/2YJ9z357vKevGl+4s0cwLnHbQFOmwHGC27uM03omMgB2wSpkA lA4dwVnwVwiTQ2dUrt6yRPBYxiAoHAw3hD/Oi1vqx+yQ6Y5YO58faPjsprz5CqBkBqQR m9dvIUIS02l6Ykyt6zyfPsMhYbldeR+V9q2S9C8seYhqeL+KsFBgmhFEGcWmU9UQo77N w6xLlet+/3+VmYBKDn9hp2BpoEz3zmbCqPgocDw1AC+nZqNNbOucRIARbpAQHHpuwlmG f/b8pm2C6kPXPdeNuZewY0JRMIeLFtVelBAWYa6KW7JWIKt+CYxlGIyaAWK5Per0Ow9t 5hfA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject:ironport-sdr :ironport-sdr; bh=JFiEPbNoaCMDPLhIZbCTwYHK6sSvEj0h0Cq3paz6ukc=; b=ygVFNvgpXUsTTp+1qkRF5y0tLeJ6XAqH5cw3zYOQ6FCtAOMQE8DDVxRGTWEMV+S0VH bheEAt6sbinM06nHdYKX8qN30Ac0p+YsTGUCUtpQLnMydWKRr6IGx1EUaWCp8o1MGcoi 5ZOaoFGqrerlQ2GgfEilFRdKsi3Wr9twmncbvQvvAN4lDSEaNNkgJb7rD6H0Dw5LQZCH Kk29y548kRR92d+AF4zGKBBF/YnIiR4DBtjBJ1DxxZp20vIZR+4kWVNaBHJ+S1tWH24M I8al87ge3/UYXGtPr3PkNPJnFfkl7BDan8j2yhzZ3QQDoDAV/TYTg8WqZUOizvwRH1j0 PTzA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v20si2201818oif.63.2020.04.02.03.46.31; Thu, 02 Apr 2020 03:46:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387990AbgDBKpu (ORCPT + 99 others); Thu, 2 Apr 2020 06:45:50 -0400 Received: from mga05.intel.com ([192.55.52.43]:53826 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387963AbgDBKpt (ORCPT ); Thu, 2 Apr 2020 06:45:49 -0400 IronPort-SDR: H3xSB95jWYTXkx+j4NETqPnqRaC/e7CIqeI7xTeuZzr8sUO+SjbH1Kz2zdbvqpLYYZy3168mKn T16j6F/QdsTw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2020 03:45:49 -0700 IronPort-SDR: KxM0FCr0vwUYqKDLXgHweWoLlVQUzA+Hvv0ii4BEJ/fusUQk21Fa8+Ik97Ub+LCeV6vca6mC3w CRvk5bWouKhQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,335,1580803200"; d="scan'208";a="240788144" Received: from ahunter-desktop.fi.intel.com (HELO [10.237.72.87]) ([10.237.72.87]) by fmsmga007.fm.intel.com with ESMTP; 02 Apr 2020 03:45:47 -0700 Subject: Re: [PATCH v3 3/4] mmc: host: hsq: Handle an unusual case of returing busy To: Baolin Wang , ulf.hansson@linaro.org Cc: orsonzhai@gmail.com, zhang.lyra@gmail.com, arnd@arndb.de, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org References: From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Message-ID: <3e048723-2edb-cc5b-a8f1-8ab8554e077f@intel.com> Date: Thu, 2 Apr 2020 13:45:03 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 19/03/20 12:54 pm, Baolin Wang wrote: > There is an unusual case that the card is busy when trying to send a > command, and we can not polling the card status in interrupt context > by using request_atomic() to dispatch requests. > > Thus we should queue a work to try again in the non-atomic context > in case the host releases the busy signal later. I think this should be part of patch 1 > > Signed-off-by: Baolin Wang Sorry for the slow reply. > --- > drivers/mmc/host/mmc_hsq.c | 37 ++++++++++++++++++++++++++++++++++++- > drivers/mmc/host/mmc_hsq.h | 1 + > 2 files changed, 37 insertions(+), 1 deletion(-) > > diff --git a/drivers/mmc/host/mmc_hsq.c b/drivers/mmc/host/mmc_hsq.c > index fdbaa98..3edad11 100644 > --- a/drivers/mmc/host/mmc_hsq.c > +++ b/drivers/mmc/host/mmc_hsq.c > @@ -15,11 +15,33 @@ > #define HSQ_NUM_SLOTS 64 > #define HSQ_INVALID_TAG HSQ_NUM_SLOTS > > +static void mmc_hsq_retry_handler(struct work_struct *work) > +{ > + struct mmc_hsq *hsq = container_of(work, struct mmc_hsq, retry_work); > + struct mmc_host *mmc = hsq->mmc; > + struct mmc_request *mrq = hsq->mrq; > + struct mmc_data *data = mrq->data; > + > + if (mmc->ops->request) { ->request() is not an optional mmc operation so checking it is not necessary. > + mmc->ops->request(mmc, mrq); > + return; > + } > + > + /* > + * If host does not supply the callback in normal context to > + * handle request, just finish this request. > + */ > + data->error = -EBUSY; > + data->bytes_xfered = 0; > + mmc_hsq_finalize_request(mmc, mrq); > +} > + > static void mmc_hsq_pump_requests(struct mmc_hsq *hsq) > { > struct mmc_host *mmc = hsq->mmc; > struct hsq_slot *slot; > unsigned long flags; > + int ret = 0; > > spin_lock_irqsave(&hsq->lock, flags); > > @@ -42,9 +64,21 @@ static void mmc_hsq_pump_requests(struct mmc_hsq *hsq) > spin_unlock_irqrestore(&hsq->lock, flags); > > if (mmc->ops->request_atomic) > - mmc->ops->request_atomic(mmc, hsq->mrq); > + ret = mmc->ops->request_atomic(mmc, hsq->mrq); > else > mmc->ops->request(mmc, hsq->mrq); > + > + /* > + * If returning BUSY from request_atomic(), which means the card > + * may be busy now, and we should change to non-atomic context to > + * try again for this unusual case, to avoid time-consuming operations > + * in the atomic context. > + * > + * Note: we can ignore other error cases, since the host driver > + * will handle them. > + */ > + if (ret == -EBUSY) > + schedule_work(&hsq->retry_work); Let's add a warning for unexpected return values i.e. WARN_ON_ONCE(ret && ret != -EBUSY); > } > > static void mmc_hsq_update_next_tag(struct mmc_hsq *hsq, int remains) > @@ -327,6 +361,7 @@ int mmc_hsq_init(struct mmc_hsq *hsq, struct mmc_host *mmc) > hsq->mmc->cqe_private = hsq; > mmc->cqe_ops = &mmc_hsq_ops; > > + INIT_WORK(&hsq->retry_work, mmc_hsq_retry_handler); > spin_lock_init(&hsq->lock); > init_waitqueue_head(&hsq->wait_queue); > > diff --git a/drivers/mmc/host/mmc_hsq.h b/drivers/mmc/host/mmc_hsq.h > index d51beb7..81f6c4f 100644 > --- a/drivers/mmc/host/mmc_hsq.h > +++ b/drivers/mmc/host/mmc_hsq.h > @@ -12,6 +12,7 @@ struct mmc_hsq { > wait_queue_head_t wait_queue; > struct hsq_slot *slot; > spinlock_t lock; > + struct work_struct retry_work; > > int next_tag; > int num_slots; >