Received: by 2002:a25:d783:0:0:0:0:0 with SMTP id o125csp507282ybg; Thu, 19 Mar 2020 03:57:02 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsXH/3a/zDyeyfkKmWZhquNmBMyKlRh5KII1zwMrBEjizPGHMMicUauZDEb7cFFO9RcSV93 X-Received: by 2002:a9d:720a:: with SMTP id u10mr1668180otj.177.1584615421796; Thu, 19 Mar 2020 03:57:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584615421; cv=none; d=google.com; s=arc-20160816; b=YFhpJtIqX5hMAMl6wDm6oePJftABIG7thZHMFx312u97vEDllgwFI8wV8RmpO4txxn /jTErXDR606XyvhxCw9Eh8Rom3pnkBgqXRQqObWFnZaj3+BhMC8YumwufN0wflpAD1+c ifaVBZSBiINZ+b1oY+dx0ZXJSSwuKk77OLSzvxIkury6KmVZfdWv/WDLbwD3NnEM/NTq tGPIc85VAwaU00kv9w3YpTzlnY57Gjapk/f8AwcNJGlqOwYMVsQFg3Y1W9IfUdS0X9Kl mv44G6PPBkIs9kM6sbLlGP9KFhX7NV4E8AjGtSbfWmGGMtHXkxr7cNgrWO1fQYL5+N4p hLZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=2B71Ilx38FSmc8wtIe4i237uiN3P11n9fl8wswTG+HE=; b=MuzgoiJs2e9TwVLVpC5OKF2npnjWgc7ZgzfiU6MrKVOiOvIo68aU6BMJP/AWT79OVh +ohY4/9yjWunQzMZCkH6wFyhjLtCmReUbQRqRGZJGK7EHcN095HmEQT6AYM3LL4j3pKO sbZEGy7ELEAlDW8RaUq0SazRePzkX8KZLa6a6mPc8sU9RsItyM4/nzZFslx2XE+XiuqY 3AMh6yVhgxNto+r1liAeVc0vvL/eIFVYawG77k9KlYy/WjK6n+N8r5rZ5QEe1P0ypH17 ofbKUjEcD21EFstePWJo8sv71Ve/MBLq9tKo4vr0LVNxFPdPTqHkGZDG13grdJ7z9kKP +JIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uWRptmxy; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a128si930061oif.202.2020.03.19.03.56.49; Thu, 19 Mar 2020 03:57:01 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uWRptmxy; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727211AbgCSKzY (ORCPT + 99 others); Thu, 19 Mar 2020 06:55:24 -0400 Received: from mail-pj1-f68.google.com ([209.85.216.68]:36861 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727195AbgCSKzX (ORCPT ); Thu, 19 Mar 2020 06:55:23 -0400 Received: by mail-pj1-f68.google.com with SMTP id nu11so857249pjb.1; Thu, 19 Mar 2020 03:55:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=2B71Ilx38FSmc8wtIe4i237uiN3P11n9fl8wswTG+HE=; b=uWRptmxyg3U3LYbhlzQ1GX5LHM29toqGAeh/iTGNMSJMaU6hU4GxvfC2mGdIKL5XOR 8Ylc9TXDmov3+Eq2Z+zoh575WObZ6/cQ00Dh6MC6JwRRHUast/13omM0fYuSCvjQd4En vsg2mEIGf67A5JUZ1b3exnvLUIIQuJGI68cBW4gMmKGnhV7j07KX0EYKVDfJdIP/Es7T PlKra7VCaT+kpKUIO/PHVlaky0CQ5MBaOgoNeuTdcGLCn+Esnx11Jc0Ia+eYEHxcTDBh uIbPn2U8KEXVDMac/y2jJxF+TB5qOv9s3pLR9ruGqONw4QoclslkNZruKEwujOUHQOp9 F7nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=2B71Ilx38FSmc8wtIe4i237uiN3P11n9fl8wswTG+HE=; b=t3NptdDftdjBIYlLdS7gny0GV5FF/g94+CwmMxYm/jFETa4pZ+GZnySEXZ0uox1La6 wjwbLQTc2hYVrAARL/ap2Ye6+cIFnWp3MqXq9CM4j86kynjxpnsXSA6stHJxKn4WMv5C O6UkpiUfLxVZPucrGha67P2OQcD7Pt1kBCzV3OfGf7TyU66yhDCfR900ciM7V5I8y6rw e+kkJQu+tt4Mihnkk1nckMZZ+zKy0a+t1uUTlwJVmaEVsJL823ZQSTBvDa6yaTSmOS9d InoWIVhqHiRUpArt5kfRmueg1HJdhONUvG5U4Ou/dhxWt0aOxoyVIWEtcjK3CrlcNZea oxmw== X-Gm-Message-State: ANhLgQ2zYW0Czv3w8GKMx1LQp8VaCbs14sJ85Mw48hhPcOnUCUOwGx3/ VIEBZr3NEHFaHGXuodKdqq0= X-Received: by 2002:a17:90a:654a:: with SMTP id f10mr3233621pjs.50.1584615321880; Thu, 19 Mar 2020 03:55:21 -0700 (PDT) Received: from sh03840pcu.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id f6sm2209949pfk.99.2020.03.19.03.55.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Mar 2020 03:55:21 -0700 (PDT) From: Baolin Wang To: adrian.hunter@intel.com, ulf.hansson@linaro.org Cc: orsonzhai@gmail.com, zhang.lyra@gmail.com, baolin.wang7@gmail.com, arnd@arndb.de, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/4] mmc: host: hsq: Handle an unusual case of returing busy Date: Thu, 19 Mar 2020 18:54:21 +0800 Message-Id: X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Baolin Wang --- 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) { + 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); } 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; -- 1.9.1