Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4124050pxu; Mon, 30 Nov 2020 18:40:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJwK9wwL0+kNSYFV1CXV8PapiQhQ3/gvLfFx+01mwqW6NT4Sn/+dVrwliNs2yjhFCoQenMsp X-Received: by 2002:a17:906:2a09:: with SMTP id j9mr931975eje.355.1606790413853; Mon, 30 Nov 2020 18:40:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606790413; cv=none; d=google.com; s=arc-20160816; b=oLZZ/OSr+XHLED9bU02BjEN587e0M6Xc1oW9/1rHu14RFAoFPbvhYPJfxHRg5ncE3K 8F6sxt52xdTKpPNb9zKi92J81x6Xz/zs5iO1es73au9ZZmmpZILl7JOcCOZyFg7SZ2uN vqEXQkzpI755SDZgCef6s0kdqGqJbeDfwiEL0JXH0ORZluLlCJmYkwI1PWJIu9d4U1i7 H+1DCzNS9Aq70gVQalxM0N3M/p8eGlntSJB894TVSGzdjTAlsFlKUwfhVAN/JUm6/40A QgDEhrbJfWwlVC6TQGaRIX8xv6JiT9RznI0FxWPOPRPoi9pzrlcJZnDulHnSMwbr4ITs R67w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dmarc-filter:sender:dkim-signature; bh=syjTGio1OyJ5XZTcS06LweFoVuBQoMLa4k53wtt4Wi0=; b=gwmhO/zAxlRUumLJGjZGH6/hvvIUemY3Lwwjzsaw+o2Fc+D+QzfDM4EizpEeCmv4/l g6glSQS0yJ+laEJHPE0C5wfPl3H9/iCF6BT04FB5if5oYTuulagWVOXWR0VnfONG3mJX Th7qm9+QnkubSSLcOneTFK5P1uTl0i0Abk5trwLF/H9FYCwZi8AqMHudRVXaYChJY9wp Soc1v9OFbRoMf8AzG0ayHWnXF1ZKGff3YctwLIq+9P3urRym1oWBd0fPw9pB2IsPoAHg QHBBf8ZOpH9H4+rldn4y2fO8npyvMEFniqX6EtPBwFvqmtiz+xRIOseV0M9gB35ZeFrx ujdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=QBWh+lf6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id du15si105204ejc.471.2020.11.30.18.39.50; Mon, 30 Nov 2020 18:40:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=QBWh+lf6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730870AbgK3XTa (ORCPT + 99 others); Mon, 30 Nov 2020 18:19:30 -0500 Received: from z5.mailgun.us ([104.130.96.5]:35205 "EHLO z5.mailgun.us" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730721AbgK3XTa (ORCPT ); Mon, 30 Nov 2020 18:19:30 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1606778350; h=Content-Transfer-Encoding: Content-Type: In-Reply-To: MIME-Version: Date: Message-ID: From: References: Cc: To: Subject: Sender; bh=syjTGio1OyJ5XZTcS06LweFoVuBQoMLa4k53wtt4Wi0=; b=QBWh+lf68MFSR9nyZzgO5glcbEweUZeQQoxX7TpP/PRlxgsQAd+8+Qt3daJQtoOVDetBJ5CT Mfbzwvc7Sy2CbkMG54kw4d6O868H7NGASpjbFvuvLR8LY8J61u2c6rgiYSh6iXG3WDTLAQkL pqEYLw8HEsbFBpnbrCr3ffe3d24= X-Mailgun-Sending-Ip: 104.130.96.5 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n02.prod.us-west-2.postgun.com with SMTP id 5fc57ded07535c81bac92338 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Mon, 30 Nov 2020 23:19:09 GMT Sender: asutoshd=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 2CA22C43465; Mon, 30 Nov 2020 23:19:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00, NICE_REPLY_A,SPF_FAIL,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from [192.168.8.168] (cpe-70-95-149-85.san.res.rr.com [70.95.149.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: asutoshd) by smtp.codeaurora.org (Postfix) with ESMTPSA id B8D8CC43461; Mon, 30 Nov 2020 23:19:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org B8D8CC43461 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=asutoshd@codeaurora.org Subject: Re: [PATCH 1/3] scsi: ufs: Add "wb_on" sysfs node to control WB on/off To: Bean Huo , alim.akhtar@samsung.com, avri.altman@wdc.com, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com, cang@codeaurora.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org References: <20201130181143.5739-1-huobean@gmail.com> <20201130181143.5739-2-huobean@gmail.com> From: "Asutosh Das (asd)" Message-ID: <2a380908-3eb4-2cdc-4156-03e8946ffd88@codeaurora.org> Date: Mon, 30 Nov 2020 15:19:05 -0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.3 MIME-Version: 1.0 In-Reply-To: <20201130181143.5739-2-huobean@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/30/2020 10:11 AM, Bean Huo wrote: > From: Bean Huo > > Currently we let UFS WriteBooster driver use clock scaling > up/down to set WB on/off, for the platform which doesn't > support UFSHCD_CAP_CLK_SCALING, WB will be always on. Provide > a sysfs attribute to enable/disable WB during runtime. > > Signed-off-by: Bean Huo > --- > drivers/scsi/ufs/ufs-sysfs.c | 33 +++++++++++++++++++++++++++++++++ > drivers/scsi/ufs/ufshcd.c | 3 +-- > drivers/scsi/ufs/ufshcd.h | 2 ++ > 3 files changed, 36 insertions(+), 2 deletions(-) > > diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c > index 08e72b7eef6a..e41d8eb779ec 100644 > --- a/drivers/scsi/ufs/ufs-sysfs.c > +++ b/drivers/scsi/ufs/ufs-sysfs.c > @@ -189,6 +189,37 @@ static ssize_t auto_hibern8_store(struct device *dev, > return count; > } > > +static ssize_t wb_on_show(struct device *dev, struct device_attribute *attr, > + char *buf) > +{ > + struct ufs_hba *hba = dev_get_drvdata(dev); > + > + return scnprintf(buf, PAGE_SIZE, "%d\n", hba->wb_enabled); > +} > + > +static ssize_t wb_on_store(struct device *dev, struct device_attribute *attr, > + const char *buf, size_t count) > +{ > + struct ufs_hba *hba = dev_get_drvdata(dev); > + unsigned int wb_enable; > + ssize_t res; > + > + if (!ufshcd_is_wb_allowed(hba)) > + return -EOPNOTSUPP; > + > + if (kstrtouint(buf, 0, &wb_enable)) > + return -EINVAL; > + > + if (wb_enable != 0 && wb_enable != 1) > + return -EINVAL; > + > + pm_runtime_get_sync(hba->dev); > + res = ufshcd_wb_ctrl(hba, wb_enable); Say, a platform supports clock-scaling and this bit is toggled. The control goes into ufshcd_wb_ctrl for both this sysfs and clock-scaling contexts. The clock-scaling context passes all checks and blocks on waiting for this wb control to be disabled and then tries to enable wb when it's already disabled. Perhaps that's a race there? > + pm_runtime_put_sync(hba->dev); > + > + return res < 0 ? res : count; > +} > + > static DEVICE_ATTR_RW(rpm_lvl); > static DEVICE_ATTR_RO(rpm_target_dev_state); > static DEVICE_ATTR_RO(rpm_target_link_state); > @@ -196,6 +227,7 @@ static DEVICE_ATTR_RW(spm_lvl); > static DEVICE_ATTR_RO(spm_target_dev_state); > static DEVICE_ATTR_RO(spm_target_link_state); > static DEVICE_ATTR_RW(auto_hibern8); > +static DEVICE_ATTR_RW(wb_on); > > static struct attribute *ufs_sysfs_ufshcd_attrs[] = { > &dev_attr_rpm_lvl.attr, > @@ -205,6 +237,7 @@ static struct attribute *ufs_sysfs_ufshcd_attrs[] = { > &dev_attr_spm_target_dev_state.attr, > &dev_attr_spm_target_link_state.attr, > &dev_attr_auto_hibern8.attr, > + &dev_attr_wb_on.attr, > NULL > }; > > diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c > index d169db41ee16..639ba9d1ccbb 100644 > --- a/drivers/scsi/ufs/ufshcd.c > +++ b/drivers/scsi/ufs/ufshcd.c > @@ -247,7 +247,6 @@ static inline int ufshcd_config_vreg_hpm(struct ufs_hba *hba, > static int ufshcd_try_to_abort_task(struct ufs_hba *hba, int tag); > static int ufshcd_wb_buf_flush_enable(struct ufs_hba *hba); > static int ufshcd_wb_buf_flush_disable(struct ufs_hba *hba); > -static int ufshcd_wb_ctrl(struct ufs_hba *hba, bool enable); > static int ufshcd_wb_toggle_flush_during_h8(struct ufs_hba *hba, bool set); > static inline void ufshcd_wb_toggle_flush(struct ufs_hba *hba, bool enable); > static void ufshcd_hba_vreg_set_lpm(struct ufs_hba *hba); > @@ -5299,7 +5298,7 @@ static void ufshcd_bkops_exception_event_handler(struct ufs_hba *hba) > __func__, err); > } > > -static int ufshcd_wb_ctrl(struct ufs_hba *hba, bool enable) > +int ufshcd_wb_ctrl(struct ufs_hba *hba, bool enable) > { > int ret; > u8 index; > diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h > index d0b68df07eef..c7bb61a4e484 100644 > --- a/drivers/scsi/ufs/ufshcd.h > +++ b/drivers/scsi/ufs/ufshcd.h > @@ -1067,6 +1067,8 @@ int ufshcd_exec_raw_upiu_cmd(struct ufs_hba *hba, > u8 *desc_buff, int *buff_len, > enum query_opcode desc_op); > > +int ufshcd_wb_ctrl(struct ufs_hba *hba, bool enable); > + > /* Wrapper functions for safely calling variant operations */ > static inline const char *ufshcd_get_var_name(struct ufs_hba *hba) > { > -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, Linux Foundation Collaborative Project