From patchwork Tue Nov 22 22:26:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 627853 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC6E6C4332F for ; Tue, 22 Nov 2022 22:26:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235025AbiKVW0j (ORCPT ); Tue, 22 Nov 2022 17:26:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234549AbiKVW0h (ORCPT ); Tue, 22 Nov 2022 17:26:37 -0500 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E6457A376 for ; Tue, 22 Nov 2022 14:26:37 -0800 (PST) Received: by mail-pl1-f182.google.com with SMTP id d20so14978858plr.10 for ; Tue, 22 Nov 2022 14:26:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=704PJWnopOqaVGnhssGOT3S0dUQA0qS4/DU7F8KMwtM=; b=e5GWyi8DW+mWFPib1LEAUcwHjFM9Xp4MDW8J4W+jrfxUjviUBXrjDuWN5dNrre3fEs JYqrePfbilkIpmTllC+wboCCsu9l0v4/9AhqricdgWejXW5CN+/FCADS6U3xFdShCKbM A9+tzJBRXdAJEUug6iUJyU2drPIMu0Zb8Vb8AGQ187Iau6KVbatPfvkxvtGF62K8t572 QhY4k10dTb3485ONA30xwcwLFVQ/TgZFDZCjcb4oAoCX3By8iy+/SnwtChF726seL8en dXTRKpIDwxM0W9acxojZrIFR52AZS2BwdPicxz7NgoeFWQ03rNf8wNUhdYIF/y18xB2C kTAA== X-Gm-Message-State: ANoB5pkOU9GcYdS8tgo5BdFJmHF/fADvVaFNLcZYLL0Bu2GeiiiMIHk1 bbwaybWxd+mwM2mRojn3d4A= X-Google-Smtp-Source: AA0mqf4M3LyUUnLqK18S/GnkZ8ORHGVy8HYeOlwOMGWpKWt5ZoGBkRJ2yQdRidnn18z66fnyBKpeGA== X-Received: by 2002:a17:902:9a03:b0:186:9f20:e7e2 with SMTP id v3-20020a1709029a0300b001869f20e7e2mr5973594plp.174.1669155996431; Tue, 22 Nov 2022 14:26:36 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:3c88:9479:e09c:9acb]) by smtp.gmail.com with ESMTPSA id cp5-20020a170902e78500b00172973d3cd9sm12539551plb.55.2022.11.22.14.26.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 14:26:35 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Adrian Hunter , Bart Van Assche , Avri Altman , Stanley Chu , "James E.J. Bottomley" , Matthias Brugger , Bean Huo , Jinyoung Choi Subject: [PATCH v4 1/5] scsi: ufs: Reduce the clock scaling latency Date: Tue, 22 Nov 2022 14:26:13 -0800 Message-Id: <20221122222617.3449081-2-bvanassche@acm.org> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog In-Reply-To: <20221122222617.3449081-1-bvanassche@acm.org> References: <20221122222617.3449081-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Wait at most 20 ms before rechecking the doorbells instead of waiting for a potentially long time between doorbell checks. Reviewed-by: Avri Altman Reviewed-by: Stanley Chu Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 768cb49d269c..81c20e315dba 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -1154,7 +1154,7 @@ static int ufshcd_wait_for_doorbell_clr(struct ufs_hba *hba, } spin_unlock_irqrestore(hba->host->host_lock, flags); - schedule(); + io_schedule_timeout(msecs_to_jiffies(20)); if (ktime_to_us(ktime_sub(ktime_get(), start)) > wait_timeout_us) { timeout = true; From patchwork Tue Nov 22 22:26:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 628189 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF121C4332F for ; Tue, 22 Nov 2022 22:26:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235102AbiKVW0s (ORCPT ); Tue, 22 Nov 2022 17:26:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234549AbiKVW0q (ORCPT ); Tue, 22 Nov 2022 17:26:46 -0500 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5076579E2B for ; Tue, 22 Nov 2022 14:26:46 -0800 (PST) Received: by mail-pf1-f169.google.com with SMTP id b185so15663345pfb.9 for ; Tue, 22 Nov 2022 14:26:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oRrbQSGdvYUcE4BuW28QJ3skyWFt/5TBa/Fr/nBLjMg=; b=wyaV3uxI6VusQzNSnfhkaJ0nnN5G8vYYylbMXJ2W0+SE7I/zB42lQqPcppvKHfH565 krM1VAq2ChykOJLWPEzI0jWAOyb1sKpF5drCp7NyCxVdhOBuHiiodaoexVKE7SjfFQjI OLvIb+1OIRaiUYB4VXQyx2PxabQFSIzgyC3SY0BuZpgSjJ7N5xfJuVRCkJsAN4/6l+Ja jQWDiTQxvpWyxzh5c5cKw7d/u/V/6XufebR+jW10SOMfR5TzaRy4jOb2rocKaY70rfXW 3pmHlJO0CWi+tba4zrVgUUd0e7UlvnFAe+mM/m3FbRrenNnPNh0k4YwAPwMfZnhZq5Hj eFBQ== X-Gm-Message-State: ANoB5pkEPxUULwWrL4Vc1kkxyWL4tiBTOqo1lhYUNkksi4LVH7mYyH3W nendPU38frDt2gl51/hT89Y= X-Google-Smtp-Source: AA0mqf5SXA0lr6A2wxDZaVJfn/xMb1cC3ao2aSJI8QK4BS47Rt2NslIKfXnDacTGg4sO06BK3GqNzw== X-Received: by 2002:a62:1a8b:0:b0:572:7c58:540 with SMTP id a133-20020a621a8b000000b005727c580540mr7246726pfa.69.1669156005725; Tue, 22 Nov 2022 14:26:45 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:3c88:9479:e09c:9acb]) by smtp.gmail.com with ESMTPSA id cp5-20020a170902e78500b00172973d3cd9sm12539551plb.55.2022.11.22.14.26.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 14:26:44 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Adrian Hunter , Bart Van Assche , "James E.J. Bottomley" , Bean Huo , Avri Altman , Jinyoung Choi Subject: [PATCH v4 2/5] scsi: ufs: Move a clock scaling check Date: Tue, 22 Nov 2022 14:26:14 -0800 Message-Id: <20221122222617.3449081-3-bvanassche@acm.org> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog In-Reply-To: <20221122222617.3449081-1-bvanassche@acm.org> References: <20221122222617.3449081-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Move a check related to clock scaling into ufshcd_devfreq_scale(). This patch prepares for adding a second ufshcd_clock_scaling_prepare() caller in a function not related to clock scaling. Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 81c20e315dba..195261e3521c 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -1236,8 +1236,7 @@ static int ufshcd_clock_scaling_prepare(struct ufs_hba *hba) ufshcd_scsi_block_requests(hba); down_write(&hba->clk_scaling_lock); - if (!hba->clk_scaling.is_allowed || - ufshcd_wait_for_doorbell_clr(hba, DOORBELL_CLR_TOUT_US)) { + if (ufshcd_wait_for_doorbell_clr(hba, DOORBELL_CLR_TOUT_US)) { ret = -EBUSY; up_write(&hba->clk_scaling_lock); ufshcd_scsi_unblock_requests(hba); @@ -1275,10 +1274,18 @@ static int ufshcd_devfreq_scale(struct ufs_hba *hba, bool scale_up) int ret = 0; bool is_writelock = true; + if (!hba->clk_scaling.is_allowed) + return -EBUSY; + ret = ufshcd_clock_scaling_prepare(hba); if (ret) return ret; + if (!hba->clk_scaling.is_allowed) { + ret = -EBUSY; + goto out_unprepare; + } + /* scale down the gear before scaling down clocks */ if (!scale_up) { ret = ufshcd_scale_gear(hba, false); From patchwork Tue Nov 22 22:26:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 627852 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 170A2C4332F for ; Tue, 22 Nov 2022 22:27:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234858AbiKVW07 (ORCPT ); Tue, 22 Nov 2022 17:26:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235202AbiKVW0z (ORCPT ); Tue, 22 Nov 2022 17:26:55 -0500 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33C387818D for ; Tue, 22 Nov 2022 14:26:55 -0800 (PST) Received: by mail-pg1-f169.google.com with SMTP id r18so15204172pgr.12 for ; Tue, 22 Nov 2022 14:26:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CHCnAXPPmp2IpgajiXHrcVTx/+rpqECCL4FFj/zhSbc=; b=cGZ8D+5HPftkgB01Hnu6ltfW9DdUDmIkmANIqp6uQa+dTR/WmjBgUYdgyhEWd/4bXV F7iLFes+8DDrP1d9kAOuF9Bfjcjja63H/5mcXzmJeetT3OzHhQYFqb0Em97N5VPCzP5H o+OIcJ0E8dv6Pb3aYweyHvJCrKru0I2Omh6SwHxyMz70zkTcdmOBvuNlVhyUK26PIqWj 4TVgMCuIbxNMRJLrlZVhfff/teFVVn3/qPCPChcWQQRoxBg+c+GgATFyrWxjsQIIDp6x CqJlThCuVfhIKpMJWAkAlWD/ZMpVtPWTXfZAan6MtYpLLDq4f0XeYw8PJXgiEbhzht6Z N2yw== X-Gm-Message-State: ANoB5plhH6OpVT/fxYKNZLrCJCXwuIFV5nSwHanvbGe0YNaQngecJbkZ yiY0XH5wx2g7UodEJ6tpCyA= X-Google-Smtp-Source: AA0mqf6vSiSKRQ6m//wYelIy/B7XGxEWt5PIhGPl26OV8pKPFCfk2VP0PW5KUy1aaU7J1jbBdIZOoQ== X-Received: by 2002:a63:580a:0:b0:477:12e3:6e1c with SMTP id m10-20020a63580a000000b0047712e36e1cmr8235362pgb.126.1669156014600; Tue, 22 Nov 2022 14:26:54 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:3c88:9479:e09c:9acb]) by smtp.gmail.com with ESMTPSA id cp5-20020a170902e78500b00172973d3cd9sm12539551plb.55.2022.11.22.14.26.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 14:26:53 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Adrian Hunter , Bart Van Assche , Avri Altman , "James E.J. Bottomley" , Bean Huo , Jinyoung Choi Subject: [PATCH v4 3/5] scsi: ufs: Pass the clock scaling timeout as an argument Date: Tue, 22 Nov 2022 14:26:15 -0800 Message-Id: <20221122222617.3449081-4-bvanassche@acm.org> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog In-Reply-To: <20221122222617.3449081-1-bvanassche@acm.org> References: <20221122222617.3449081-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Prepare for adding an additional ufshcd_clock_scaling_prepare() call with a different timeout. Reviewed-by: Avri Altman Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 195261e3521c..7b2948592c4a 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -1121,6 +1121,12 @@ static u32 ufshcd_pending_cmds(struct ufs_hba *hba) return pending; } +/* + * Wait until all pending SCSI commands and TMFs have finished or the timeout + * has expired. + * + * Return: 0 upon success; -EBUSY upon timeout. + */ static int ufshcd_wait_for_doorbell_clr(struct ufs_hba *hba, u64 wait_timeout_us) { @@ -1225,9 +1231,14 @@ static int ufshcd_scale_gear(struct ufs_hba *hba, bool scale_up) return ret; } -static int ufshcd_clock_scaling_prepare(struct ufs_hba *hba) +/* + * Wait until all pending SCSI commands and TMFs have finished or the timeout + * has expired. + * + * Return: 0 upon success; -EBUSY upon timeout. + */ +static int ufshcd_clock_scaling_prepare(struct ufs_hba *hba, u64 timeout_us) { - #define DOORBELL_CLR_TOUT_US (1000 * 1000) /* 1 sec */ int ret = 0; /* * make sure that there are no outstanding requests when @@ -1236,7 +1247,7 @@ static int ufshcd_clock_scaling_prepare(struct ufs_hba *hba) ufshcd_scsi_block_requests(hba); down_write(&hba->clk_scaling_lock); - if (ufshcd_wait_for_doorbell_clr(hba, DOORBELL_CLR_TOUT_US)) { + if (ufshcd_wait_for_doorbell_clr(hba, timeout_us)) { ret = -EBUSY; up_write(&hba->clk_scaling_lock); ufshcd_scsi_unblock_requests(hba); @@ -1277,7 +1288,7 @@ static int ufshcd_devfreq_scale(struct ufs_hba *hba, bool scale_up) if (!hba->clk_scaling.is_allowed) return -EBUSY; - ret = ufshcd_clock_scaling_prepare(hba); + ret = ufshcd_clock_scaling_prepare(hba, 1 * USEC_PER_SEC); if (ret) return ret; From patchwork Tue Nov 22 22:26:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 628188 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61E11C4332F for ; Tue, 22 Nov 2022 22:27:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234320AbiKVW1P (ORCPT ); Tue, 22 Nov 2022 17:27:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234264AbiKVW1O (ORCPT ); Tue, 22 Nov 2022 17:27:14 -0500 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F73879E2B for ; Tue, 22 Nov 2022 14:27:14 -0800 (PST) Received: by mail-pj1-f46.google.com with SMTP id t17so13716347pjo.3 for ; Tue, 22 Nov 2022 14:27:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C0LhfTi/S7dYsdQK1Ey0lYG6TJ57E7plztRQPKjBZ08=; b=qTAKJ82DMHQHDzWIyp+u5nV2jp8ubyTnIM7Ev7+xu0Aa1nithktQVgwoahIiLlar5L zLxukr2UKCI52eb/bq9eCYE0Bx224IWMUiVNmotAtcwGDiVt3I7ijJSO8H6J0K/EMLJI /+/1zJsffVN8lsU82SuSxg3BKcPkS/u5kHe5jo/Eu+WXfGWvc0OqFevyU+2aXi/Y625L LUpvsyEzrK7ffaMKm1l+BWe8ba4QB4XbxKdH/w+1zGKPzw7Md2sFrHDXU7oH/wbaZZcg mGCVAYznhEeQazMN9LGoiJ+qaX6kC+E4ICihLuJ6LtAMItuxg6+om9QwbmqfHFai/6KJ 3Viw== X-Gm-Message-State: ANoB5pm/ttC2cwYoFPQiwcOawoShL3yYjdaX3v1+GKsTqU42anL1Rz8N uLNPtmRsb1TLv1Lj5GNhHyg= X-Google-Smtp-Source: AA0mqf6Z1d75wA2FQ4+prEJ+YTk7/7ZHhT5QZDRV8Wzvqhpy55JCKv0sVEUAyPn69qI3eZvNw5eHKw== X-Received: by 2002:a17:902:f813:b0:17f:8011:dd03 with SMTP id ix19-20020a170902f81300b0017f8011dd03mr6003707plb.59.1669156033356; Tue, 22 Nov 2022 14:27:13 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:3c88:9479:e09c:9acb]) by smtp.gmail.com with ESMTPSA id cp5-20020a170902e78500b00172973d3cd9sm12539551plb.55.2022.11.22.14.27.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 14:27:12 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Adrian Hunter , Bart Van Assche , Avri Altman , "James E.J. Bottomley" , Bean Huo , Jinyoung Choi , Yoshihiro Shimoda , Keoseong Park , Stanley Chu Subject: [PATCH v4 4/5] scsi: ufs: Add suspend/resume SCSI command processing support Date: Tue, 22 Nov 2022 14:26:16 -0800 Message-Id: <20221122222617.3449081-5-bvanassche@acm.org> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog In-Reply-To: <20221122222617.3449081-1-bvanassche@acm.org> References: <20221122222617.3449081-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This functionality is needed by UFS drivers to e.g. suspend SCSI command processing while reprogramming encryption keys if the hardware does not support concurrent I/O and key reprogramming. This patch prepares for adding support in the upstream kernel for the Pixel 6 and 7 UFS controllers. Reviewed-by: Avri Altman Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 20 ++++++++++++++++++++ include/ufs/ufshcd.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 7b2948592c4a..fa1c84731b8e 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -1707,6 +1707,26 @@ static void ufshcd_ungate_work(struct work_struct *work) ufshcd_scsi_unblock_requests(hba); } +/* + * Block processing of new SCSI commands and wait until pending SCSI + * commands and TMFs have finished. ufshcd_exec_dev_cmd() and + * ufshcd_issue_devman_upiu_cmd() are not affected by this function. + * + * Return: 0 upon success; -EBUSY upon timeout. + */ +int ufshcd_freeze_scsi_devs(struct ufs_hba *hba, u64 timeout_us) +{ + return ufshcd_clock_scaling_prepare(hba, timeout_us); +} +EXPORT_SYMBOL_GPL(ufshcd_freeze_scsi_devs); + +/* Resume processing of SCSI commands. */ +void ufshcd_unfreeze_scsi_devs(struct ufs_hba *hba) +{ + ufshcd_clock_scaling_unprepare(hba, true); +} +EXPORT_SYMBOL_GPL(ufshcd_unfreeze_scsi_devs); + /** * ufshcd_hold - Enable clocks that were gated earlier due to ufshcd_release. * Also, exit from hibern8 mode and set the link as active. diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index 5cf81dff60aa..bd45818bf0e8 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -1186,6 +1186,9 @@ void ufshcd_release(struct ufs_hba *hba); void ufshcd_clkgate_delay_set(struct device *dev, unsigned long value); +int ufshcd_freeze_scsi_devs(struct ufs_hba *hba, u64 timeout_us); +void ufshcd_unfreeze_scsi_devs(struct ufs_hba *hba); + void ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id, int *desc_length); From patchwork Tue Nov 22 22:26:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 627851 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 654FCC433FE for ; Tue, 22 Nov 2022 22:28:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235164AbiKVW2E (ORCPT ); Tue, 22 Nov 2022 17:28:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235230AbiKVW1t (ORCPT ); Tue, 22 Nov 2022 17:27:49 -0500 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 772CF248D2 for ; Tue, 22 Nov 2022 14:27:45 -0800 (PST) Received: by mail-pf1-f176.google.com with SMTP id c203so15655328pfc.11 for ; Tue, 22 Nov 2022 14:27:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KCVRjCGW7kZ/dU6rMA345/UpZtvUvRhhs7itHKqRU2I=; b=dQf/RLjfmlYXa19rim/e6uR6eB56TQOR2KRWKAO2rWPf3QsnoztGYatc2db3TZhBxY GCS53vuZ9x5uhePSHsch/6T+siaElQNlzsaTXOmac6CcGrqThXUlTZs8R5BiPVaL/Bq7 QvpRk8fX1/Mo3FJdAz2CfwW/nxhMWiqKSOPoE5ClWJNkcogmBPnpDV7jJ7rBjL7WZiJ7 VNjBdAIaV5GVNH3WQgws0Q1v6DYIuE0tzkd4R3OYbD0gszQmaFA1VCe1ynbS2uY+eG1A +Co0AQMl/Fp5kja/J6PhARyrkc119ftj/s1QsTxL6vl3ZzE/JLpeiAAKMknlspx/OcVU xk7g== X-Gm-Message-State: ANoB5pkOUEyGdXuMdBJy1lPoRDEac7PlcZfAdIb78E47gToKWluati9s qwkYIYjrWTAy3TKCwlmSU70= X-Google-Smtp-Source: AA0mqf4CamGmS+6ELrGJf5AvHnexF5XiKgsubWcYLHgidPR1rygwZLX0jF6GQ4VlUUrsh9EZNfJrYg== X-Received: by 2002:a63:d407:0:b0:476:e0fc:8d8a with SMTP id a7-20020a63d407000000b00476e0fc8d8amr12294294pgh.145.1669156064582; Tue, 22 Nov 2022 14:27:44 -0800 (PST) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:3c88:9479:e09c:9acb]) by smtp.gmail.com with ESMTPSA id cp5-20020a170902e78500b00172973d3cd9sm12539551plb.55.2022.11.22.14.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 14:27:43 -0800 (PST) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Adrian Hunter , Bart Van Assche , Eric Biggers , Avri Altman , "James E.J. Bottomley" , Bean Huo , Jinyoung Choi , Yoshihiro Shimoda , Stanley Chu , Keoseong Park , Kiwoong Kim Subject: [PATCH v4 5/5] scsi: ufs: Allow UFS host drivers to override the sg entry size Date: Tue, 22 Nov 2022 14:26:17 -0800 Message-Id: <20221122222617.3449081-6-bvanassche@acm.org> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog In-Reply-To: <20221122222617.3449081-1-bvanassche@acm.org> References: <20221122222617.3449081-1-bvanassche@acm.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Eric Biggers Modify the UFSHCD core to allow 'struct ufshcd_sg_entry' to be variable-length. The default is the standard length, but variants can override ufs_hba::sg_entry_size with a larger value if there are vendor-specific fields following the standard ones. This is needed to support inline encryption with ufs-exynos (FMP). Cc: Eric Biggers Reviewed-by: Avri Altman Signed-off-by: Eric Biggers [ bvanassche: edited commit message and introduced CONFIG_SCSI_UFS_VARIABLE_SG_ENTRY_SIZE ] Signed-off-by: Bart Van Assche --- drivers/ufs/core/ufshcd.c | 39 ++++++++++++++++++--------------------- drivers/ufs/host/Kconfig | 4 ++++ include/ufs/ufshcd.h | 30 ++++++++++++++++++++++++++++++ include/ufs/ufshci.h | 9 +++++++-- 4 files changed, 59 insertions(+), 23 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index fa1c84731b8e..6df24aed970f 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -528,7 +528,7 @@ void ufshcd_print_trs(struct ufs_hba *hba, unsigned long bitmap, bool pr_prdt) prdt_length = le16_to_cpu( lrbp->utr_descriptor_ptr->prd_table_length); if (hba->quirks & UFSHCD_QUIRK_PRDT_BYTE_GRAN) - prdt_length /= sizeof(struct ufshcd_sg_entry); + prdt_length /= ufshcd_sg_entry_size(hba); dev_err(hba->dev, "UPIU[%d] - PRDT - %d entries phys@0x%llx\n", @@ -537,7 +537,7 @@ void ufshcd_print_trs(struct ufs_hba *hba, unsigned long bitmap, bool pr_prdt) if (pr_prdt) ufshcd_hex_dump("UPIU PRDT: ", lrbp->ucd_prdt_ptr, - sizeof(struct ufshcd_sg_entry) * prdt_length); + ufshcd_sg_entry_size(hba) * prdt_length); } } @@ -2445,7 +2445,7 @@ int ufshcd_send_uic_cmd(struct ufs_hba *hba, struct uic_command *uic_cmd) */ static int ufshcd_map_sg(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) { - struct ufshcd_sg_entry *prd_table; + struct ufshcd_sg_entry *prd; struct scatterlist *sg; struct scsi_cmnd *cmd; int sg_segments; @@ -2460,13 +2460,12 @@ static int ufshcd_map_sg(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) if (hba->quirks & UFSHCD_QUIRK_PRDT_BYTE_GRAN) lrbp->utr_descriptor_ptr->prd_table_length = - cpu_to_le16((sg_segments * - sizeof(struct ufshcd_sg_entry))); + cpu_to_le16(sg_segments * ufshcd_sg_entry_size(hba)); else lrbp->utr_descriptor_ptr->prd_table_length = cpu_to_le16(sg_segments); - prd_table = lrbp->ucd_prdt_ptr; + prd = lrbp->ucd_prdt_ptr; scsi_for_each_sg(cmd, sg, sg_segments, i) { const unsigned int len = sg_dma_len(sg); @@ -2480,9 +2479,10 @@ static int ufshcd_map_sg(struct ufs_hba *hba, struct ufshcd_lrb *lrbp) * indicates 4 bytes, '7' indicates 8 bytes, etc." */ WARN_ONCE(len > 256 * 1024, "len = %#x\n", len); - prd_table[i].size = cpu_to_le32(len - 1); - prd_table[i].addr = cpu_to_le64(sg->dma_address); - prd_table[i].reserved = 0; + prd->size = cpu_to_le32(len - 1); + prd->addr = cpu_to_le64(sg->dma_address); + prd->reserved = 0; + prd = (void *)prd + ufshcd_sg_entry_size(hba); } } else { lrbp->utr_descriptor_ptr->prd_table_length = 0; @@ -2772,10 +2772,11 @@ static void ufshcd_map_queues(struct Scsi_Host *shost) static void ufshcd_init_lrb(struct ufs_hba *hba, struct ufshcd_lrb *lrb, int i) { - struct utp_transfer_cmd_desc *cmd_descp = hba->ucdl_base_addr; + struct utp_transfer_cmd_desc *cmd_descp = (void *)hba->ucdl_base_addr + + i * sizeof_utp_transfer_cmd_desc(hba); struct utp_transfer_req_desc *utrdlp = hba->utrdl_base_addr; dma_addr_t cmd_desc_element_addr = hba->ucdl_dma_addr + - i * sizeof(struct utp_transfer_cmd_desc); + i * sizeof_utp_transfer_cmd_desc(hba); u16 response_offset = offsetof(struct utp_transfer_cmd_desc, response_upiu); u16 prdt_offset = offsetof(struct utp_transfer_cmd_desc, prd_table); @@ -2783,11 +2784,11 @@ static void ufshcd_init_lrb(struct ufs_hba *hba, struct ufshcd_lrb *lrb, int i) lrb->utr_descriptor_ptr = utrdlp + i; lrb->utrd_dma_addr = hba->utrdl_dma_addr + i * sizeof(struct utp_transfer_req_desc); - lrb->ucd_req_ptr = (struct utp_upiu_req *)(cmd_descp + i); + lrb->ucd_req_ptr = (struct utp_upiu_req *)cmd_descp->command_upiu; lrb->ucd_req_dma_addr = cmd_desc_element_addr; - lrb->ucd_rsp_ptr = (struct utp_upiu_rsp *)cmd_descp[i].response_upiu; + lrb->ucd_rsp_ptr = (struct utp_upiu_rsp *)cmd_descp->response_upiu; lrb->ucd_rsp_dma_addr = cmd_desc_element_addr + response_offset; - lrb->ucd_prdt_ptr = cmd_descp[i].prd_table; + lrb->ucd_prdt_ptr = (struct ufshcd_sg_entry *)cmd_descp->prd_table; lrb->ucd_prdt_dma_addr = cmd_desc_element_addr + prdt_offset; } @@ -3696,7 +3697,7 @@ static int ufshcd_memory_alloc(struct ufs_hba *hba) size_t utmrdl_size, utrdl_size, ucdl_size; /* Allocate memory for UTP command descriptors */ - ucdl_size = (sizeof(struct utp_transfer_cmd_desc) * hba->nutrs); + ucdl_size = sizeof_utp_transfer_cmd_desc(hba) * hba->nutrs; hba->ucdl_base_addr = dmam_alloc_coherent(hba->dev, ucdl_size, &hba->ucdl_dma_addr, @@ -3790,7 +3791,7 @@ static void ufshcd_host_memory_configure(struct ufs_hba *hba) prdt_offset = offsetof(struct utp_transfer_cmd_desc, prd_table); - cmd_desc_size = sizeof(struct utp_transfer_cmd_desc); + cmd_desc_size = sizeof_utp_transfer_cmd_desc(hba); cmd_desc_dma_addr = hba->ucdl_dma_addr; for (i = 0; i < hba->nutrs; i++) { @@ -9661,6 +9662,7 @@ int ufshcd_alloc_host(struct device *dev, struct ufs_hba **hba_handle) hba->dev = dev; hba->dev_ref_clk_freq = REF_CLK_FREQ_INVAL; hba->nop_out_timeout = NOP_OUT_TIMEOUT; + ufshcd_set_sg_entry_size(hba, sizeof(struct ufshcd_sg_entry)); INIT_LIST_HEAD(&hba->clk_list_head); spin_lock_init(&hba->outstanding_lock); @@ -10039,11 +10041,6 @@ static int __init ufshcd_core_init(void) { int ret; - /* Verify that there are no gaps in struct utp_transfer_cmd_desc. */ - static_assert(sizeof(struct utp_transfer_cmd_desc) == - 2 * ALIGNED_UPIU_SIZE + - SG_ALL * sizeof(struct ufshcd_sg_entry)); - ufs_debugfs_init(); ret = scsi_register_driver(&ufs_dev_wlun_template.gendrv); diff --git a/drivers/ufs/host/Kconfig b/drivers/ufs/host/Kconfig index 4cc2dbd79ed0..7f01f453e792 100644 --- a/drivers/ufs/host/Kconfig +++ b/drivers/ufs/host/Kconfig @@ -124,3 +124,7 @@ config SCSI_UFS_EXYNOS Select this if you have UFS host controller on Samsung Exynos SoC. If unsure, say N. + +config SCSI_UFS_VARIABLE_SG_ENTRY_SIZE + bool + default y if SCSI_UFS_EXYNOS && SCSI_UFS_CRYPTO diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index bd45818bf0e8..12982e764730 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -754,6 +754,7 @@ struct ufs_hba_monitor { * @vops: pointer to variant specific operations * @vps: pointer to variant specific parameters * @priv: pointer to variant specific private data + * @sg_entry_size: size of struct ufshcd_sg_entry (may include variant fields) * @irq: Irq number of the controller * @is_irq_enabled: whether or not the UFS controller interrupt is enabled. * @dev_ref_clk_freq: reference clock frequency @@ -877,6 +878,9 @@ struct ufs_hba { const struct ufs_hba_variant_ops *vops; struct ufs_hba_variant_params *vps; void *priv; +#ifdef CONFIG_SCSI_UFS_VARIABLE_SG_ENTRY_SIZE + size_t sg_entry_size; +#endif unsigned int irq; bool is_irq_enabled; enum ufs_ref_clk_freq dev_ref_clk_freq; @@ -980,6 +984,32 @@ struct ufs_hba { bool complete_put; }; +#ifdef CONFIG_SCSI_UFS_VARIABLE_SG_ENTRY_SIZE +static inline size_t ufshcd_sg_entry_size(const struct ufs_hba *hba) +{ + return hba->sg_entry_size; +} + +static inline void ufshcd_set_sg_entry_size(struct ufs_hba *hba, size_t sg_entry_size) +{ + WARN_ON_ONCE(sg_entry_size < sizeof(struct ufshcd_sg_entry)); + hba->sg_entry_size = sg_entry_size; +} +#else +static inline size_t ufshcd_sg_entry_size(const struct ufs_hba *hba) +{ + return sizeof(struct ufshcd_sg_entry); +} + +#define ufshcd_set_sg_entry_size(hba, sg_entry_size) \ + ({ (void)(hba); BUILD_BUG_ON(sg_entry_size != sizeof(struct ufshcd_sg_entry)); }) +#endif + +static inline size_t sizeof_utp_transfer_cmd_desc(const struct ufs_hba *hba) +{ + return sizeof(struct utp_transfer_cmd_desc) + SG_ALL * ufshcd_sg_entry_size(hba); +} + /* Returns true if clocks can be gated. Otherwise false */ static inline bool ufshcd_is_clkgating_allowed(struct ufs_hba *hba) { diff --git a/include/ufs/ufshci.h b/include/ufs/ufshci.h index f525566a0864..e145a478afa2 100644 --- a/include/ufs/ufshci.h +++ b/include/ufs/ufshci.h @@ -422,18 +422,23 @@ struct ufshcd_sg_entry { __le64 addr; __le32 reserved; __le32 size; + /* + * followed by variant-specific fields if + * CONFIG_SCSI_UFS_VARIABLE_SG_ENTRY_SIZE has been defined. + */ }; /** * struct utp_transfer_cmd_desc - UTP Command Descriptor (UCD) * @command_upiu: Command UPIU Frame address * @response_upiu: Response UPIU Frame address - * @prd_table: Physical Region Descriptor + * @prd_table: Physical Region Descriptor: an array of SG_ALL struct + * ufshcd_sg_entry's. Variant-specific fields may be present after each. */ struct utp_transfer_cmd_desc { u8 command_upiu[ALIGNED_UPIU_SIZE]; u8 response_upiu[ALIGNED_UPIU_SIZE]; - struct ufshcd_sg_entry prd_table[SG_ALL]; + u8 prd_table[]; }; /**