Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4354772pxu; Wed, 9 Dec 2020 15:11:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJxwl4PwC7Q5aCd60okubFRT4ygxZ365l2HUDYIP6AKkRt5q53GDkMg9h48DwokeOFfnNopQ X-Received: by 2002:a17:906:cd14:: with SMTP id oz20mr3753013ejb.99.1607555490265; Wed, 09 Dec 2020 15:11:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607555490; cv=none; d=google.com; s=arc-20160816; b=Zg0+Spsdw8k7QMOj8SlgP1fuL5x0xWNbRMIKJR88YGAoI6VDLuNdNhAxB8SLuB8E2j pCOIaiSulWz5Vpv+Sij7wr4SvXPlICwYFjhZpQmPuRQDWkjcD6ZAInsLP4SghugIzPeP n+dM9HJdu51Sk2sRaZ+0H6ftqndTjK/kJYCae+EgizdW2aKlbrihYTQIn0UQxvrBEtVU WCn64kwNtJEu0ZlDj41ah5toJDOCo/ucUHWPUKFDxNEPzUXWEAXoggMNeoctHqNL8HO3 FF8MuqLuA1Eq+sYhcCiZAcfErLYbSoRzk6dOwPcZ32U4L1Pd3n5bkrEP2O9MQCcmTCWK D/MA== 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=98F5DO05EhIysV6+JdM1/2tGSfAYYjCiWpAARnStf1E=; b=b7SHJlrD42eS62Qyrjf+i7F2YLLiVPo0+CTdL/zGN9C18RYUHt41gQrBCWX13WzFY3 hDegRMENw7k9otDCdRB04pJunj8sfwz6IfUJPa8VZCPKYGQN4BXKlf9430FGqGBt5Q9k 2vZkreQMMmixmLPE1nGfPNC3XPCsxAmq2DW14i4FE6v9mGo+Qnl5y3yHoy4SZiD5JKlE +BWPbIPU/scydQ8HV2316166XLOcmqDr+x+XOwteO35QAUjSPUASi6/bLR+ytU0+tFtv mYmSUDW8h5/S2IIXFTSfxXHE8qH/UleWpClCpHavrf7nw0yQPiHiw8aIg5ZvIP8qjMsS 0tnQ== 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 i8si1405245ejb.632.2020.12.09.15.11.07; Wed, 09 Dec 2020 15:11:30 -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 S1732416AbgLINg4 (ORCPT + 99 others); Wed, 9 Dec 2020 08:36:56 -0500 Received: from labrats.qualcomm.com ([199.106.110.90]:39396 "EHLO labrats.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732125AbgLINgn (ORCPT ); Wed, 9 Dec 2020 08:36:43 -0500 IronPort-SDR: 6vo7twyxgcy8FwhfTaYvGsmTN+4RZ0pG/wJGh2WtvsINyY5YuNZrdNLMcrsFknIDTTeDCcFKN7 yri5sUBm8qeTZkrVgJP4rpaekYhzJpXsQrWMt2Mm6JehqJKWocyUYyv5Ovw6ZmW6PWMD+Z+Op7 lTlC394GbddS32niZlZksk+2kJwEVdqY85VPem+cWuERVou3lVVXno0iyiFSDwSCs5IvOAC1oD wsngloc7ma3+S+JqN7YlBnZh1BEP+PjfyrzYL/30OsV9ahTf7b91Q02grTnNpDJR0EJa0w49gF ngk= X-IronPort-AV: E=Sophos;i="5.78,405,1599548400"; d="scan'208";a="29333086" Received: from unknown (HELO ironmsg01-sd.qualcomm.com) ([10.53.140.141]) by labrats.qualcomm.com with ESMTP; 09 Dec 2020 05:35:57 -0800 X-QCInternal: smtphost Received: from wsp769891wss.qualcomm.com (HELO stor-presley.qualcomm.com) ([192.168.140.85]) by ironmsg01-sd.qualcomm.com with ESMTP; 09 Dec 2020 05:35:55 -0800 Received: by stor-presley.qualcomm.com (Postfix, from userid 359480) id BF41221340; Wed, 9 Dec 2020 05:35:55 -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 2/2] scsi: ufs: Clean up ufshcd_exit_clk_scaling/gating() Date: Wed, 9 Dec 2020 05:35:41 -0800 Message-Id: <1607520942-22254-3-git-send-email-cang@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1607520942-22254-1-git-send-email-cang@codeaurora.org> References: <1607520942-22254-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 diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 12266bd..41a12d6 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1846,11 +1846,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) @@ -1894,12 +1897,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); @@ -7764,7 +7771,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); } } @@ -8201,12 +8207,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; @@ -8955,13 +8961,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); @@ -9160,7 +9162,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; } @@ -9168,7 +9170,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); @@ -9251,10 +9253,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.