From patchwork Wed Nov 9 19:41:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asutosh Das X-Patchwork-Id: 17791 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp528782wru; Wed, 9 Nov 2022 11:48:33 -0800 (PST) X-Google-Smtp-Source: AMsMyM5stie+Kiyhq8YEeP1j5aCRufwCKgsySodmwLxdntWWHuOHq2zOuyAL3JzDhtxvXo/HapDu X-Received: by 2002:a05:6402:366:b0:463:11e8:13cb with SMTP id s6-20020a056402036600b0046311e813cbmr59972149edw.367.1668023313505; Wed, 09 Nov 2022 11:48:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668023313; cv=none; d=google.com; s=arc-20160816; b=dGCXreflfqJ8BuIawBWer4VdIUZxR2XNqDryORYqu4B73aEbo0fW7cJyciXIkL8HtE KBvzXvekO0yRyz5CT2MXgwd7iuz7lpINRAOAWu6GUTRjf5pU4gSaJKd7SWCjbNmIoMiq tyROEZws93ad7snjw/fs3Qytme2WfVn2U1CDiWzT1Vod8vtz5MgXKV/FJJU5WxUspGTz iFHL42I+OTVaZOzfzaYkA8qh47GwlVO61DwsxociT5FZ8cDLH7TlbY0lRFz9VtB2UtdW zOi89sfIY1KBQiPwdgxYmfn0QMrI/llncj8K50ce47InbjlhEb32XfQwfNx2hq3zTBdi YMbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=QXoFrC0i5LjPHLxerGYLqbCcvl3lVxK/VsvrGlwRW0s=; b=tI+MXc3GoTSY3WwU30gjbfs3ENrf3RRjK2UR02bp1yodaFywJll1Q5ra1DpNiAB+B7 Rqi5fAbB/g13c0N3b76I7/EhiYwTd73NcjhCp/oY6FtGU3TyhcWTWDHMO2SCXToQLF21 XWLSHv/T85rmdlpb0xoUhqJf17ARI+KYSldw0Tiufp031uYh2mEaVzz33aksEGijbK8Q WJqn+9MDHBhP7vFZXHYdc8yQ9sz0mDfKf105xAITtnB29Mn1fNdYTZqtbE9cHeS2tl64 qFaqwEvNvPEYreVZypglqL4YEub8z/MopGF6KvMipBM2gugtKc0Yx+xA8x0S2f9UksHV vbsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=Kbu3+Evn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw13-20020a056402228d00b004615c5728e8si13926728edb.494.2022.11.09.11.48.08; Wed, 09 Nov 2022 11:48:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b=Kbu3+Evn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232103AbiKITqo (ORCPT + 99 others); Wed, 9 Nov 2022 14:46:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231947AbiKITqa (ORCPT ); Wed, 9 Nov 2022 14:46:30 -0500 Received: from alexa-out-sd-01.qualcomm.com (alexa-out-sd-01.qualcomm.com [199.106.114.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A2C72181E; Wed, 9 Nov 2022 11:45:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1668023153; x=1699559153; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=QXoFrC0i5LjPHLxerGYLqbCcvl3lVxK/VsvrGlwRW0s=; b=Kbu3+EvnxUaduB6fHA+em6HPlqKMyDssGPKGDjRzFgEBTJSgnZB/SRDB EbvWgKlnL4ZtLMqwP/eRZt+x4LTGCeukjxeQBq+uCW5Zd/VKBUFCRPoO/ nrVbj4WHVT4EZBoxmxBcmT/osXc+jRhYcz8xPelzMc6NKLTUlGFJrMrrQ k=; Received: from unknown (HELO ironmsg-SD-alpha.qualcomm.com) ([10.53.140.30]) by alexa-out-sd-01.qualcomm.com with ESMTP; 09 Nov 2022 11:45:52 -0800 X-QCInternal: smtphost Received: from unknown (HELO nasanex01a.na.qualcomm.com) ([10.52.223.231]) by ironmsg-SD-alpha.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 11:45:52 -0800 Received: from asutoshd-linux1.qualcomm.com (10.80.80.8) by nasanex01a.na.qualcomm.com (10.52.223.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Wed, 9 Nov 2022 11:45:52 -0800 From: Asutosh Das To: , , CC: , , , , , , , , , Asutosh Das , , Alim Akhtar , "James E.J. Bottomley" , Arthur Simchaev , Jinyoung Choi , Krzysztof Kozlowski , open list Subject: [PATCH v4 15/16] ufs: core: mcq: Add completion support in poll Date: Wed, 9 Nov 2022 11:41:40 -0800 Message-ID: <3d589d7836bbe8a3994c1be9abf36134b711a632.1668022680.git.quic_asutoshd@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nasanex01a.na.qualcomm.com (10.52.223.231) X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749049214021642069?= X-GMAIL-MSGID: =?utf-8?q?1749049214021642069?= Complete cqe requests in poll. Assumption is that several poll completion may happen in different CPUs for the same completion queue. Hence a spin lock protection is added. Co-developed-by: Can Guo Signed-off-by: Can Guo Signed-off-by: Asutosh Das Reviewed-by: Bart Van Assche --- drivers/ufs/core/ufs-mcq.c | 13 +++++++++++++ drivers/ufs/core/ufshcd-priv.h | 2 ++ drivers/ufs/core/ufshcd.c | 7 +++++++ include/ufs/ufshcd.h | 2 ++ 4 files changed, 24 insertions(+) diff --git a/drivers/ufs/core/ufs-mcq.c b/drivers/ufs/core/ufs-mcq.c index 448c0fa..f64286d 100644 --- a/drivers/ufs/core/ufs-mcq.c +++ b/drivers/ufs/core/ufs-mcq.c @@ -375,6 +375,18 @@ unsigned long ufshcd_mcq_poll_cqe_nolock(struct ufs_hba *hba, return completed_reqs; } +unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba, + struct ufs_hw_queue *hwq) +{ + unsigned long completed_reqs; + + spin_lock(&hwq->cq_lock); + completed_reqs = ufshcd_mcq_poll_cqe_nolock(hba, hwq); + spin_unlock(&hwq->cq_lock); + + return completed_reqs; +} + void ufshcd_mcq_make_queues_operational(struct ufs_hba *hba) { struct ufs_hw_queue *hwq; @@ -468,6 +480,7 @@ int ufshcd_mcq_init(struct ufs_hba *hba) hwq = &hba->uhq[i]; hwq->max_entries = hba->nutrs; spin_lock_init(&hwq->sq_lock); + spin_lock_init(&hwq->cq_lock); } /* The very first HW queue serves device commands */ diff --git a/drivers/ufs/core/ufshcd-priv.h b/drivers/ufs/core/ufshcd-priv.h index c5b5bf3..73ce8a2 100644 --- a/drivers/ufs/core/ufshcd-priv.h +++ b/drivers/ufs/core/ufshcd-priv.h @@ -75,6 +75,8 @@ unsigned long ufshcd_mcq_poll_cqe_nolock(struct ufs_hba *hba, struct ufs_hw_queue *hwq); struct ufs_hw_queue *ufshcd_mcq_req_to_hwq(struct ufs_hba *hba, struct request *req); +unsigned long ufshcd_mcq_poll_cqe_lock(struct ufs_hba *hba, + struct ufs_hw_queue *hwq); #define UFSHCD_MCQ_IO_QUEUE_OFFSET 1 #define SD_ASCII_STD true diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index cda78bd..9dcbbb5 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -5453,6 +5453,13 @@ static int ufshcd_poll(struct Scsi_Host *shost, unsigned int queue_num) struct ufs_hba *hba = shost_priv(shost); unsigned long completed_reqs, flags; u32 tr_doorbell; + struct ufs_hw_queue *hwq; + + if (is_mcq_enabled(hba)) { + hwq = &hba->uhq[queue_num + UFSHCD_MCQ_IO_QUEUE_OFFSET]; + + return ufshcd_mcq_poll_cqe_lock(hba, hwq); + } spin_lock_irqsave(&hba->outstanding_lock, flags); tr_doorbell = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL); diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index d5fde64..a709391 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -1069,6 +1069,7 @@ struct ufs_hba { * @sq_lock: serialize submission queue access * @cq_tail_slot: current slot to which CQ tail pointer is pointing * @cq_head_slot: current slot to which CQ head pointer is pointing + * @cq_lock: Synchronize between multiple polling instances */ struct ufs_hw_queue { void __iomem *mcq_sq_head; @@ -1086,6 +1087,7 @@ struct ufs_hw_queue { spinlock_t sq_lock; u32 cq_tail_slot; u32 cq_head_slot; + spinlock_t cq_lock; }; static inline bool is_mcq_enabled(struct ufs_hba *hba)