From patchwork Fri Jul 15 21:25:11 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: 591600 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 DCC2CC43334 for ; Fri, 15 Jul 2022 21:25:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230513AbiGOVZo (ORCPT ); Fri, 15 Jul 2022 17:25:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231262AbiGOVZn (ORCPT ); Fri, 15 Jul 2022 17:25:43 -0400 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9540A72EF1 for ; Fri, 15 Jul 2022 14:25:42 -0700 (PDT) Received: by mail-pf1-f174.google.com with SMTP id 70so5695059pfx.1 for ; Fri, 15 Jul 2022 14:25:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VRLjBHheSx3+WidXlAJ16yE6sr2l4d/LEP3cuBG5S/s=; b=vnknvFZbrAkyy3XRzkwS3k+xGSMh4R1BDfW+1dU53acZeyYoA1seGdoFdCvldgFdDD qFxpV7x1k/TMRsQV6+bgRGGth+UFSmN2fBzUh1VLzo6pODCeKk6c6GAv9PxGxxef6YT1 mE9SmXJFlSRkYfHarOkxVybsEqRACJYj5S9Z6l2hCQXTNCCRUibZHSO0ahWZklh0DrMh rnowzuOYyM1dK7e06I2A4Pe+guPhryhAHqhPSLJ+8e1jDFdPPKZCYbTKEcIJxwKUCZbO 9PmtivpnFRWbQhTd5v7BrCftzUICWUXKxVgPYUoj71KoUFKTRoWgova7XSqLof/eONS9 bHKg== X-Gm-Message-State: AJIora9El5Q2wcboZJVNJ2tuuiHnBKuJUGxp7L1Rzy26l/o6uIdpjyh/ m4Uq9/7pKFi/TUhkAo+oW6k= X-Google-Smtp-Source: AGRyM1vXpYj3O1UgfbgRiWxcBwsegr3XQQp9+itqCz6lsO6AUOF6YNxlJch1QvAG4d7o9euO/Hnu7A== X-Received: by 2002:a63:8649:0:b0:415:c328:4dff with SMTP id x70-20020a638649000000b00415c3284dffmr13960297pgd.430.1657920342057; Fri, 15 Jul 2022 14:25:42 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:276e:f777:f438:e01d]) by smtp.gmail.com with ESMTPSA id e35-20020a630f23000000b0040c40b022fbsm3535944pgl.94.2022.07.15.14.25.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 14:25:41 -0700 (PDT) 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 Subject: [PATCH v2 1/5] scsi: ufs: Reduce the clock scaling latency Date: Fri, 15 Jul 2022 14:25:11 -0700 Message-Id: <20220715212515.347664-2-bvanassche@acm.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220715212515.347664-1-bvanassche@acm.org> References: <20220715212515.347664-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 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 b92d4fb82bca..a51644bcfbb7 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -1149,7 +1149,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 Fri Jul 15 21:25:12 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: 591133 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 68EA9C43334 for ; Fri, 15 Jul 2022 21:25:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231287AbiGOVZw (ORCPT ); Fri, 15 Jul 2022 17:25:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229839AbiGOVZt (ORCPT ); Fri, 15 Jul 2022 17:25:49 -0400 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB1D243E69 for ; Fri, 15 Jul 2022 14:25:48 -0700 (PDT) Received: by mail-pg1-f174.google.com with SMTP id f65so5452150pgc.12 for ; Fri, 15 Jul 2022 14:25:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lxWAv2EChn51hExylSSAviLP25c6GTSyIQ0V215GCTI=; b=t0dqb2oCgp3oALk7jGNbk5pM1TzUmqvSnWrW0ie+Sc0dQ6qp6wObtXUnzg0oBZvWys /wYfg+KdRgI0IoODAPZjn4BrrXope5S55jdyHLp79qFJqP4EAY+A1UQu8tlDffuQRPh7 u/RHDxMq7LoVCBxhm/NpWAtvKc8IR+OL7I60ddXI8bFvXm/6H38dwtqsO4PSsaVRLyLJ rt3sukmuWypxR3kj+t02mVGPAAb9OdnxC2nupfJORcgYh18fNMZDw+7Qo5Yn0hsTUqMN 25HSai8pfxyvvjGOihX5MPANLGz1+3R9Z7ey9IipaklV4bFmVyqQkRhu2Ypgp40PC32L 5+DA== X-Gm-Message-State: AJIora/Q+5Dd/DLX8WpAbCuvAKq8muOt++Y8gP+sa1Ebh2+O5L0Zni46 vvw/SYRYlN89eSMf986wnAw= X-Google-Smtp-Source: AGRyM1veT+Xq6KZ4nF4u25m6a9wyM0p7KPf3jSd3k+MtpO0wjiJ34pDBr0QxSLcwZ7xlGw4A9t2U7A== X-Received: by 2002:a63:4e09:0:b0:412:1ba3:672a with SMTP id c9-20020a634e09000000b004121ba3672amr14188930pgb.597.1657920348359; Fri, 15 Jul 2022 14:25:48 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:276e:f777:f438:e01d]) by smtp.gmail.com with ESMTPSA id e35-20020a630f23000000b0040c40b022fbsm3535944pgl.94.2022.07.15.14.25.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 14:25:47 -0700 (PDT) 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 Subject: [PATCH v2 2/5] scsi: ufs: Move a clock scaling check Date: Fri, 15 Jul 2022 14:25:12 -0700 Message-Id: <20220715212515.347664-3-bvanassche@acm.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220715212515.347664-1-bvanassche@acm.org> References: <20220715212515.347664-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 a51644bcfbb7..f7af5cd3124e 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -1231,8 +1231,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); @@ -1270,10 +1269,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 Fri Jul 15 21:25: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: 591599 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 6BFDAC43334 for ; Fri, 15 Jul 2022 21:26:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231452AbiGOV0F (ORCPT ); Fri, 15 Jul 2022 17:26:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231411AbiGOVZ7 (ORCPT ); Fri, 15 Jul 2022 17:25:59 -0400 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D50F79EFA for ; Fri, 15 Jul 2022 14:25:55 -0700 (PDT) Received: by mail-pg1-f181.google.com with SMTP id q16so2373740pgq.6 for ; Fri, 15 Jul 2022 14:25:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Vf3d4T6ckpl5sc6NUdI7j1z51d7qLNRgPs7pebeIVtY=; b=LB2w/OiEmV/OOIEptmaFa/U+Sib93z+rLkR1XuEa+2XCtc59F4EZb4FKWq2l2D1Wy6 Rn7i0sgJKh6wRRPcoNmyLNhdNHSJAAK2C+iF5x0pI6Qh+IHtVEr2ZdnhnsK9b77vFzj0 TwFgJgHzYe0h7drTVh5NcsiBReNVExcBIdbdQbAtOFi0doVWs1mkGYhLCdTjYaTNcCL3 gxiPVhisyl/ekfz9hJ+NMHSJ8Ip0m1871ZsogNxwgn0AjGuTiAY6bcgws7m3DpKAILrQ 0pQPGb9AThcKOLoxL3Z1xKS0OrIQ07FQykC9h6zabShI+HNaig2IQFLhH23N4Tvk0Y9E 3cqw== X-Gm-Message-State: AJIora8QfxN3CunlVDpwUPOXa9OsEOZcLi6oES5j81n7YQUIQE383YSs TLmCvBhhKsuwNT1w3DBC8us= X-Google-Smtp-Source: AGRyM1sFhRVTd2u5AxNSzbW10XIccN6T4PjMIvE8QrjdA31KvFr0aoeMaArlgYySOvIqP2c42imKJA== X-Received: by 2002:a05:6a00:1a8c:b0:52b:3eed:13d8 with SMTP id e12-20020a056a001a8c00b0052b3eed13d8mr4843943pfv.74.1657920354656; Fri, 15 Jul 2022 14:25:54 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:276e:f777:f438:e01d]) by smtp.gmail.com with ESMTPSA id e35-20020a630f23000000b0040c40b022fbsm3535944pgl.94.2022.07.15.14.25.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 14:25:54 -0700 (PDT) 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 Subject: [PATCH v2 3/5] scsi: ufs: Pass the clock scaling timeout as an argument Date: Fri, 15 Jul 2022 14:25:13 -0700 Message-Id: <20220715212515.347664-4-bvanassche@acm.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220715212515.347664-1-bvanassche@acm.org> References: <20220715212515.347664-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 f7af5cd3124e..5739e9d1b970 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -1116,6 +1116,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) { @@ -1220,9 +1226,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 @@ -1231,7 +1242,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); @@ -1272,7 +1283,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 Fri Jul 15 21:25: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: 591132 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 DD245C433EF for ; Fri, 15 Jul 2022 21:26:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231467AbiGOV0Z (ORCPT ); Fri, 15 Jul 2022 17:26:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231481AbiGOV0O (ORCPT ); Fri, 15 Jul 2022 17:26:14 -0400 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19D6974786 for ; Fri, 15 Jul 2022 14:26:12 -0700 (PDT) Received: by mail-pg1-f174.google.com with SMTP id 72so5510374pge.0 for ; Fri, 15 Jul 2022 14:26:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g0+xzAPEBgCb77lBIYpZ0BmG2rO6rleJg1wB3i4XeQA=; b=FaAEmWRJq0qwB1GhIAWSs4HiZS8U7xdXmVMkMNSEe+NgL+9cDEOJ88M5Sok8CAWu4l YHfP8l41ULdpcP9brsnLWe8aDA/oisov861AnZsQuC+XgdiGYAJiCQguTrhtaoNBVM1k 2NPSsvlwyIhJOaCwLH4FCOo/dUySgoJfN4hV8hkFbD/KOqZCE9ihF14Rk/sTFl2ZCVKo +ER89rNxO2Z/nqda21LFks0gGV+1zYQXz3+cxm/zNCH3kgLTjvs/fT+wGHCywWLRy+01 QVzyL8dBRSXviKdsxwX1fBZrcGkxeUna6eCNUKhfd1JwkyFG4fk95hyoVOb3u5M4gfxg iZ6w== X-Gm-Message-State: AJIora9HstEpiJQFt4JFt59cpFWouWjfoCopEr/bL4B3vXwMy+m3IuDG Dbp7G8m2vBY6N76rGsN3IG0= X-Google-Smtp-Source: AGRyM1sbSB/OH7gCNAUPaZbvhj05svElMKXnIy1u0wIsehy43/ghksiz78LwyCCsfUuskKlzTG28zg== X-Received: by 2002:a62:d103:0:b0:528:c6c7:bd74 with SMTP id z3-20020a62d103000000b00528c6c7bd74mr15868128pfg.68.1657920371441; Fri, 15 Jul 2022 14:26:11 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:276e:f777:f438:e01d]) by smtp.gmail.com with ESMTPSA id e35-20020a630f23000000b0040c40b022fbsm3535944pgl.94.2022.07.15.14.26.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 14:26:10 -0700 (PDT) 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 , Daejun Park , Eric Biggers Subject: [PATCH v2 4/5] scsi: ufs: Add suspend/resume SCSI command processing support Date: Fri, 15 Jul 2022 14:25:14 -0700 Message-Id: <20220715212515.347664-5-bvanassche@acm.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220715212515.347664-1-bvanassche@acm.org> References: <20220715212515.347664-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. Signed-off-by: Bart Van Assche Reviewed-by: Avri Altman --- 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 5739e9d1b970..8363d2ff622c 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -1700,6 +1700,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 7fe1a926cd99..6d78bcbedb9e 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -1194,6 +1194,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 Fri Jul 15 21:25: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: 591598 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 48206C433EF for ; Fri, 15 Jul 2022 21:26:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231422AbiGOV0i (ORCPT ); Fri, 15 Jul 2022 17:26:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231425AbiGOV0h (ORCPT ); Fri, 15 Jul 2022 17:26:37 -0400 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6783A73907 for ; Fri, 15 Jul 2022 14:26:36 -0700 (PDT) Received: by mail-pl1-f172.google.com with SMTP id f11so4209004plr.4 for ; Fri, 15 Jul 2022 14:26:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hnEAIOfNMe9QKXEO8DOyKlMaoYb/EBm2NNxA3j6CL1M=; b=BBb2zLR5SPbkw/e6GlMnZ9Ee6jUTEJA7skJfKddGP7PkY5Zyn0jXqre/EgCfLzyKST 8fZUxSFa/4y/NbK2j8IuU+F6Ida/8g2O3oqPSzgzFXVqX3WAeEOhInRvQ6G/0RxbNnhz mA2CmRJe8qaKU3k0QVEi7RADv+bI3jZiAcJbhafZaJAG/GVkwciCnnWmiopmGWpBRjym ENZg1CSJGOKmnuBUT1Pkoy2WX201fhpS9wT/xrbyplJqWGJm99633Lnm2/NLkvniFHNU HfRr0YOLQrNTGBxk5GIE5x4IPhCJKMFghz8PJ6mC8KtHfkPmaulG0rNaWEzy5quBN4sr 6g9w== X-Gm-Message-State: AJIora/IFUU+4zF5fRl4D0lILuiOiNlFt+1LYV/N4rWm91XMpSUP4HW5 ZhS9NoFOmTF9ne5+qYKgF6U= X-Google-Smtp-Source: AGRyM1u7GcwmrcUdDLhsoorYU2O1nOrX1nh8yOcfXOXBUNW6bW5UgeoYJSyBjQMhP+Ctp2ATSWrZgQ== X-Received: by 2002:a17:90b:88d:b0:1ef:9182:104a with SMTP id bj13-20020a17090b088d00b001ef9182104amr25154834pjb.74.1657920395745; Fri, 15 Jul 2022 14:26:35 -0700 (PDT) Received: from bvanassche-linux.mtv.corp.google.com ([2620:15c:211:201:276e:f777:f438:e01d]) by smtp.gmail.com with ESMTPSA id e35-20020a630f23000000b0040c40b022fbsm3535944pgl.94.2022.07.15.14.26.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 14:26:35 -0700 (PDT) From: Bart Van Assche To: "Martin K . Petersen" Cc: Jaegeuk Kim , linux-scsi@vger.kernel.org, Adrian Hunter , Bart Van Assche , Eric Biggers , "James E.J. Bottomley" , Bean Huo , Avri Altman , Geert Uytterhoeven , Krzysztof Kozlowski , Anders Roxell , Daejun Park , Kiwoong Kim Subject: [PATCH v2 5/5] scsi: ufs: Allow UFS host drivers to override the sg entry size Date: Fri, 15 Jul 2022 14:25:15 -0700 Message-Id: <20220715212515.347664-6-bvanassche@acm.org> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog In-Reply-To: <20220715212515.347664-1-bvanassche@acm.org> References: <20220715212515.347664-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 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 | 10 ++++++++++ include/ufs/ufshcd.h | 32 ++++++++++++++++++++++++++++++++ include/ufs/ufshci.h | 9 +++++++-- 4 files changed, 67 insertions(+), 23 deletions(-) diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index 8363d2ff622c..8894d66413e1 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -523,7 +523,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", @@ -532,7 +532,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); } } @@ -2437,7 +2437,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; @@ -2452,13 +2452,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); @@ -2472,9 +2471,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; @@ -2767,10 +2767,11 @@ static int 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); @@ -2778,11 +2779,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; 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; } @@ -3669,7 +3670,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, @@ -3763,7 +3764,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++) { @@ -9601,6 +9602,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); @@ -9979,11 +9981,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..49017abdac92 100644 --- a/drivers/ufs/host/Kconfig +++ b/drivers/ufs/host/Kconfig @@ -124,3 +124,13 @@ 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 "Variable size UTP physical region descriptor" + help + In the UFSHCI 3.0 standard the Physical Region Descriptor (PRD) is a + data structure used for transferring data between host and UFS + device. This data structure describes a single region in physical + memory. Although the standard requires that this data structure has a + size of 16 bytes, for some controllers this data structure has a + different size. Enable this option for UFS controllers that need it. diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h index 6d78bcbedb9e..a1d0dab9a01e 100644 --- a/include/ufs/ufshcd.h +++ b/include/ufs/ufshcd.h @@ -744,6 +744,9 @@ struct ufs_hba_monitor { * @vops: pointer to variant specific operations * @vps: pointer to variant specific parameters * @priv: pointer to variant specific private data +#ifdef CONFIG_SCSI_UFS_VARIABLE_SG_ENTRY_SIZE + * @sg_entry_size: size of struct ufshcd_sg_entry (may include variant fields) +#endif * @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 @@ -865,6 +868,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; @@ -967,6 +973,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 f81aa95ffbc4..4e764016895d 100644 --- a/include/ufs/ufshci.h +++ b/include/ufs/ufshci.h @@ -426,18 +426,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[]; }; /**