Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2023703pxu; Sun, 13 Dec 2020 10:56:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJx+U+l124MniV6h/b3hQNwrPJzvd8BAAIpn+6G0cjzEz7Nyz9K9uXzV/FSu3zEdC/455zOi X-Received: by 2002:a17:906:1cd4:: with SMTP id i20mr20077945ejh.415.1607885783747; Sun, 13 Dec 2020 10:56:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607885783; cv=none; d=google.com; s=arc-20160816; b=Yex1DNRYKpJ5T09iRtUaLrEWQeHrTmxzn0UCJ1O+pEiQ3+9LSDPRL+ajmQDUEaI0q2 sREmn60GMlOjABMCTk8mx95ObfQCvnsr4lg0P3EvJuPkkrxZ6L5Q4kVimEjfS6L60LcO MwLbXXjbNinqYHxHfu8ZUacjVs3jfNoGWWPOZsYYYQxTDTOZnkL96OKhJx9Ac8HOjPn1 51S4pSGIF0KJOzjmX0f0Px8VP7R7m8kxnT1BNfhO5FXfBMLG4aUCfHiECvbppZhAfiJU PhsMuDeiI/z6wFKHPDTqGp9ynO9+Qs0Dil8rAv1zY1aoDQMNs3oED1nBlMczbpBzZoIW YNeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr; bh=KndobHIZafppp7CMsBlWbaGxrXUeCfPyXkGw4Eh46Ts=; b=l49RsXVKj6mEVLgfrM/iYCMctJKu3fU5wrYPxFKZBcZWeLC+PvBdiJfHQmLdefa0O4 +sUJgZ5doBInrT40ZlO7lQJiLl6OOcLqV+XHw7P5gADdquTjdbtvgj5WfcWvy2piArHd mFSqE3VIYbN8U5Mvd7K5qQ76Nt4CJnt9LajqIgBbj2eaTtsFQB1FV23wPksn5GfsRM6J z1wCJj+EkZKoeP4QhFxQxruaaZl59sgeUjzes4NoZc9VUMmqIcn1QMWLlfFPBTSNmQ9X 9IFJo5QRRhLuycehR1cCagb2FdGAXw/PS1/GFC3plbzz+VZVzxxyWhHj44L0K3BAsxlG q/Jg== ARC-Authentication-Results: i=1; mx.google.com; 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 am1si8201963ejc.463.2020.12.13.10.56.00; Sun, 13 Dec 2020 10:56:23 -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; 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 S2393522AbgLMQO7 (ORCPT + 99 others); Sun, 13 Dec 2020 11:14:59 -0500 Received: from labrats.qualcomm.com ([199.106.110.90]:3052 "EHLO labrats.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730046AbgLMQOm (ORCPT ); Sun, 13 Dec 2020 11:14:42 -0500 IronPort-SDR: HywL4VtA8vGB1q9gv1AzcmYRbyt5xzjYk9zTfTxCHN2kpdJ+zC14/V+jPJUSAnBcfI+rb278WI WY4DjYZC9QVWCtJoDXnUvPRMliUi1jSVzgJHk8+7qUrYxyoSypcvH2my60or8o0TTC62RR86ok RKzHJBwgoop82jFQ3SSwBA310tx8uU+0LnvcS0zUUIg3TLnb7SFkB7BZZRUN+NMuGgK1l4JihD Bs/UoH4bVFC0p23R3mKVpZq9PnA0R/3RGBv9WkoRBhmXlco/kP8UTPhAeyGtTqoiJZbtaEn7JY nXs= X-IronPort-AV: E=Sophos;i="5.78,416,1599548400"; d="scan'208";a="29356136" Received: from unknown (HELO ironmsg01-sd.qualcomm.com) ([10.53.140.141]) by labrats.qualcomm.com with ESMTP; 13 Dec 2020 08:13:35 -0800 X-QCInternal: smtphost Received: from stor-presley.qualcomm.com ([192.168.140.85]) by ironmsg01-sd.qualcomm.com with ESMTP; 13 Dec 2020 08:13:34 -0800 Received: by stor-presley.qualcomm.com (Postfix, from userid 359480) id C607521616; Sun, 13 Dec 2020 08:13:33 -0800 (PST) From: Can Guo To: asutoshd@codeaurora.org, nguyenb@codeaurora.org, hongwus@codeaurora.org, rnayak@codeaurora.org, linux-scsi@vger.kernel.org, kernel-team@android.com, saravanak@google.com, salyzyn@google.com, cang@codeaurora.org Cc: Alim Akhtar , Avri Altman , "James E.J. Bottomley" , "Martin K. Petersen" , Stanley Chu , Bean Huo , Bart Van Assche , Satya Tangirala , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 2/3] scsi: ufs: Clean up ufshcd_exit_clk_scaling/gating() Date: Sun, 13 Dec 2020 08:13:18 -0800 Message-Id: <1607876000-3293-3-git-send-email-cang@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1607876000-3293-1-git-send-email-cang@codeaurora.org> References: <1607876000-3293-1-git-send-email-cang@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ufshcd_hba_exit() is always called after ufshcd_exit_clk_scaling() and ufshcd_exit_clk_gating(), so move ufshcd_exit_clk_scaling/gating() to ufshcd_hba_exit(). Signed-off-by: Can Guo --- drivers/scsi/ufs/ufshcd.c | 32 +++++++++++++++----------------- drivers/scsi/ufs/ufshcd.h | 4 ++++ 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 59dac09..f2ca087 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1858,11 +1858,14 @@ static void ufshcd_init_clk_scaling(struct ufs_hba *hba) snprintf(wq_name, sizeof(wq_name), "ufs_clkscaling_%d", hba->host->host_no); hba->clk_scaling.workq = create_singlethread_workqueue(wq_name); + + hba->clk_scaling.is_initialized = true; } static void ufshcd_exit_clk_scaling(struct ufs_hba *hba) { - if (!ufshcd_is_clkscaling_supported(hba)) + if (!ufshcd_is_clkscaling_supported(hba) || + !hba->clk_scaling.is_initialized) return; if (hba->devfreq) @@ -1906,12 +1909,16 @@ static void ufshcd_init_clk_gating(struct ufs_hba *hba) hba->clk_gating.enable_attr.attr.mode = 0644; if (device_create_file(hba->dev, &hba->clk_gating.enable_attr)) dev_err(hba->dev, "Failed to create sysfs for clkgate_enable\n"); + + hba->clk_gating.is_initialized = true; } static void ufshcd_exit_clk_gating(struct ufs_hba *hba) { - if (!ufshcd_is_clkgating_allowed(hba)) + if (!ufshcd_is_clkgating_allowed(hba) || + !hba->clk_gating.is_initialized) return; + device_remove_file(hba->dev, &hba->clk_gating.delay_attr); device_remove_file(hba->dev, &hba->clk_gating.enable_attr); cancel_work_sync(&hba->clk_gating.ungate_work); @@ -7776,7 +7783,6 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie) */ if (ret) { pm_runtime_put_sync(hba->dev); - ufshcd_exit_clk_scaling(hba); ufshcd_hba_exit(hba); } } @@ -8213,12 +8219,12 @@ static int ufshcd_hba_init(struct ufs_hba *hba) static void ufshcd_hba_exit(struct ufs_hba *hba) { if (hba->is_powered) { + ufshcd_exit_clk_scaling(hba); + ufshcd_exit_clk_gating(hba); + if (hba->eh_wq) + destroy_workqueue(hba->eh_wq); ufshcd_variant_hba_exit(hba); ufshcd_setup_vreg(hba, false); - ufshcd_suspend_clkscaling(hba); - if (ufshcd_is_clkscaling_supported(hba)) - if (hba->devfreq) - ufshcd_suspend_clkscaling(hba); ufshcd_setup_clocks(hba, false); ufshcd_setup_hba_vreg(hba, false); hba->is_powered = false; @@ -8967,13 +8973,9 @@ void ufshcd_remove(struct ufs_hba *hba) blk_mq_free_tag_set(&hba->tmf_tag_set); blk_cleanup_queue(hba->cmd_queue); scsi_remove_host(hba->host); - destroy_workqueue(hba->eh_wq); /* disable interrupts */ ufshcd_disable_intr(hba, hba->intr_mask); ufshcd_hba_stop(hba); - - ufshcd_exit_clk_scaling(hba); - ufshcd_exit_clk_gating(hba); ufshcd_hba_exit(hba); } EXPORT_SYMBOL_GPL(ufshcd_remove); @@ -9172,7 +9174,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) err = devm_request_irq(dev, irq, ufshcd_intr, IRQF_SHARED, UFSHCD, hba); if (err) { dev_err(hba->dev, "request irq failed\n"); - goto exit_gating; + goto out_disable; } else { hba->is_irq_enabled = true; } @@ -9180,7 +9182,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) err = scsi_add_host(host, hba->dev); if (err) { dev_err(hba->dev, "scsi_add_host failed\n"); - goto exit_gating; + goto out_disable; } hba->cmd_queue = blk_mq_init_queue(&hba->host->tag_set); @@ -9263,10 +9265,6 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq) blk_cleanup_queue(hba->cmd_queue); out_remove_scsi_host: scsi_remove_host(hba->host); -exit_gating: - ufshcd_exit_clk_scaling(hba); - ufshcd_exit_clk_gating(hba); - destroy_workqueue(hba->eh_wq); out_disable: hba->is_irq_enabled = false; ufshcd_hba_exit(hba); diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 9fcecba..3c57847 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -347,6 +347,7 @@ enum clk_gating_state { * @delay_attr: sysfs attribute to control delay_attr * @enable_attr: sysfs attribute to enable/disable clock gating * @is_enabled: Indicates the current status of clock gating + * @is_initialized: Indicates whether clock gating is initialized or not * @active_reqs: number of requests that are pending and should be waited for * completion before gating clocks. */ @@ -359,6 +360,7 @@ struct ufs_clk_gating { struct device_attribute delay_attr; struct device_attribute enable_attr; bool is_enabled; + bool is_initialized; int active_reqs; struct workqueue_struct *clk_gating_workq; }; @@ -384,6 +386,7 @@ struct ufs_saved_pwr_info { * @resume_work: worker to resume devfreq * @is_enabled: tracks if scaling is currently enabled or not * @is_allowed: tracks if scaling is currently allowed or not + * @is_initialized: Indicates whether clock scaling is initialized or not * @is_busy_started: tracks if busy period has started or not * @is_suspended: tracks if devfreq is suspended or not */ @@ -399,6 +402,7 @@ struct ufs_clk_scaling { struct work_struct resume_work; bool is_enabled; bool is_allowed; + bool is_initialized; bool is_busy_started; bool is_suspended; }; -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.