Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1759308ybh; Thu, 16 Jul 2020 23:39:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2rj3l/pwAkrYV3WPgG0pV5VP5rscv/hCTXzOjyst2fBNW/AIhLGQ1/Gorm34hE+9uXI/9 X-Received: by 2002:a17:906:1a54:: with SMTP id j20mr7091034ejf.455.1594967953882; Thu, 16 Jul 2020 23:39:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594967953; cv=none; d=google.com; s=arc-20160816; b=WxvDDUbB35mq25YA/5Ud0gGoabl3B3YOOFndja6KQRdKDwQIkKEn+WgGCMEUwimgh6 u6NDjnwTfJGMVy7oSzrUwqOuDjpTY2h0vZ3wUoePqNR39A5HNxsSr8sHXmtVeg1CSTGv XIZ3Cs6je2GfmwBcr0GdAyYPnQ39OceVkaoJgLppbazvygoZJCNCepaum+wwVUyBY/WL GtWMswQTtPQUJrWhn9we00ykgIThB6HV+l5lMxn8T0ke2vodxb9sijomepAC6LqKUZyM n7rrCmMx8CR+KAUeqE/2R/IJDUR3c0dDxgtUGXBm5OPQOeMYo4f8ca90sxvF9xiXqPRP vJvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sRkE7ksFL2ebr2n2v9nXbzY1XW3YY8T5bASrkjktDKo=; b=skFdjV+Gfq8Gzj3+WpTTELS/259UxB0bQ7ekHDY9z6bXORD0gU4+aXqdaRL5zVQ7YO 3hDgJl54zQeFkyNX9SQwhGzu6iLxES7m9rQ15sycU0GOXGS0Kaum6zpFY0RdWLDsnMmI dTBfjhQATB9yj5Y1sBcN27C3OpuuQ2U27rjPCFB6SzSRQzJaBThfpmrKEBzGhjSHrDdb UcDKP2L0GLT8t3UCWBz23jZOmJ32bZU1gx9sb17aBrseS5YEgqh5xjTHs7pfWVOgTEaJ KuUEVfWW6hTFfx50S+p1BuOhsQKBBa8nujpaCPTFKGJq1VZB0nFgCU/ciqsJhcaeRG7+ w5Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uOV9K5F4; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rv21si3444048ejb.457.2020.07.16.23.38.50; Thu, 16 Jul 2020 23:39:13 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=uOV9K5F4; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727115AbgGQGg3 (ORCPT + 99 others); Fri, 17 Jul 2020 02:36:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726141AbgGQGg2 (ORCPT ); Fri, 17 Jul 2020 02:36:28 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2448C061755; Thu, 16 Jul 2020 23:36:28 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id b9so5032837plx.6; Thu, 16 Jul 2020 23:36:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sRkE7ksFL2ebr2n2v9nXbzY1XW3YY8T5bASrkjktDKo=; b=uOV9K5F4ab4r2ImEgZz3T7yRcZwuq3d2y0cXjv84ZmB0wcl2VKO8bKEyIsnnjrERDI +kvchZ6WVHJDiEDAXJ1G+SMZLkETwkZYKRRbu+ma6m8pOw+juKUptrbwxPm4t2VgDtST G06UNh0ujWMLPwY0KUL/uGsXepRhP1LPco9v6mFiY5W4S3/T2MvF2aRINcfd0T+UUH1f Y2wWLFwHXkCs1IEyOKM0VsZnMa5wOlKk+6duJrcKgAHyFCw48TwJMIRaaxPgvKHqwQGq 6F/rKOjiJUvakOtcTtDmA4HskaV8FSCh3Lrbx0DulzS6RtfKtiHh6ZmXe0sJyH//vOYL CkAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sRkE7ksFL2ebr2n2v9nXbzY1XW3YY8T5bASrkjktDKo=; b=hrHO0mgKJopM5xJVTzhDvWBX07/Iux3tu6U/fZmi6a6PGiVe+UCRgHkbIG/HNeVVNo RLY6zdCkCBeWeLvbXk+YbEVV7P11lImjc2hF99tuWNkKfk95lc9EGlmmq36bnl7v66MI NGqSaiMdlp/z6qbDdC0l5lyHFzVyBVBjo9c7BWZq+dkJgj0oHv/L4+OGm2USCVH6w2tg mpLjLMA6Agoca2EpQTaCsfJZuQfpa/rVRMEAW5ehyPmQDIb2LRSb3qef/hfa8mSAubsV NJFoqLRu+4w6N1hQUyOs5jDhhZ33PHOREWX0kd1hd0t2OK7wqTyxs3DRrRhpvf9xYRBv DECw== X-Gm-Message-State: AOAM533BFOfN9vx4ZgSIr4GS1M5Vn+U1AURxjBEtrKb2lKHFMIT3V+0+ m6UTETY+wocs66YZHMGYnY0= X-Received: by 2002:a17:90b:4910:: with SMTP id kr16mr8409682pjb.126.1594967788167; Thu, 16 Jul 2020 23:36:28 -0700 (PDT) Received: from varodek.iballbatonwifi.com ([103.105.153.67]) by smtp.gmail.com with ESMTPSA id y22sm1683392pjp.41.2020.07.16.23.36.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jul 2020 23:36:27 -0700 (PDT) From: Vaibhav Gupta To: Bjorn Helgaas , Bjorn Helgaas , Bjorn Helgaas , Adam Radford , "James E.J. Bottomley" , "Martin K. Petersen" , Adaptec OEM Raid Solutions , Hannes Reinecke , Bradley Grove , John Garry , Don Brace , James Smart , Dick Kennedy , Kashyap Desai , Sumit Saxena , Shivasharan S , Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani , Jack Wang , Vaibhav Gupta Cc: Vaibhav Gupta , Shuah Khan , linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-scsi@vger.kernel.org, esc.storagedev@microsemi.com, megaraidlinux.pdl@broadcom.com, MPT-FusionLinux.pdl@broadcom.com Subject: [PATCH v1 01/15] scsi: megaraid_sas: use generic power management Date: Fri, 17 Jul 2020 12:04:24 +0530 Message-Id: <20200717063438.175022-2-vaibhavgupta40@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200717063438.175022-1-vaibhavgupta40@gmail.com> References: <20200717063438.175022-1-vaibhavgupta40@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With legacy PM hooks, it was the responsibility of a driver to manage PCI states and also the device's power state. The generic approach is to let the PCI core handle the work. PCI core passes "struct device*" as an argument to the .suspend() and .resume() callbacks. As the .suspend() work with "struct instance*", extract it from "struct device*" using dev_get_drv_data(). Driver was also using PCI helper functions like pci_save/restore_state(), pci_disable/enable_device(), pci_set_power_state() and pci_enable_wake(). They should not be invoked by the driver. Compile-tested only. Signed-off-by: Vaibhav Gupta --- drivers/scsi/megaraid/megaraid_sas_base.c | 57 +++++++---------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c index 00668335c2af..c1bf429d29db 100644 --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -7539,25 +7539,23 @@ static void megasas_shutdown_controller(struct megasas_instance *instance, megasas_return_cmd(instance, cmd); } -#ifdef CONFIG_PM /** * megasas_suspend - driver suspend entry point - * @pdev: PCI device structure - * @state: PCI power state to suspend routine + * @dev: Device structure */ -static int -megasas_suspend(struct pci_dev *pdev, pm_message_t state) +static int __maybe_unused +megasas_suspend(struct device *dev) { struct megasas_instance *instance; - instance = pci_get_drvdata(pdev); + instance = dev_get_drvdata(dev); if (!instance) return 0; instance->unload = 1; - dev_info(&pdev->dev, "%s is called\n", __func__); + dev_info(dev, "%s is called\n", __func__); /* Shutdown SR-IOV heartbeat timer */ if (instance->requestorId && !instance->skip_heartbeat_timer_del) @@ -7579,7 +7577,7 @@ megasas_suspend(struct pci_dev *pdev, pm_message_t state) tasklet_kill(&instance->isr_tasklet); - pci_set_drvdata(instance->pdev, instance); + dev_set_drvdata(dev, instance); instance->instancet->disable_intr(instance); megasas_destroy_irqs(instance); @@ -7587,48 +7585,30 @@ megasas_suspend(struct pci_dev *pdev, pm_message_t state) if (instance->msix_vectors) pci_free_irq_vectors(instance->pdev); - pci_save_state(pdev); - pci_disable_device(pdev); - - pci_set_power_state(pdev, pci_choose_state(pdev, state)); - return 0; } /** * megasas_resume- driver resume entry point - * @pdev: PCI device structure + * @dev: Device structure */ -static int -megasas_resume(struct pci_dev *pdev) +static int __maybe_unused +megasas_resume(struct device *dev) { int rval; struct Scsi_Host *host; struct megasas_instance *instance; u32 status_reg; - instance = pci_get_drvdata(pdev); + instance = dev_get_drvdata(dev); if (!instance) return 0; host = instance->host; - pci_set_power_state(pdev, PCI_D0); - pci_enable_wake(pdev, PCI_D0, 0); - pci_restore_state(pdev); + device_wakeup_disable(dev); - dev_info(&pdev->dev, "%s is called\n", __func__); - /* - * PCI prepping: enable device set bus mastering and dma mask - */ - rval = pci_enable_device_mem(pdev); - - if (rval) { - dev_err(&pdev->dev, "Enable device failed\n"); - return rval; - } - - pci_set_master(pdev); + dev_info(dev, "%s is called\n", __func__); /* * We expect the FW state to be READY @@ -7754,14 +7734,8 @@ megasas_resume(struct pci_dev *pdev) fail_set_dma_mask: fail_ready_state: - pci_disable_device(pdev); - return -ENODEV; } -#else -#define megasas_suspend NULL -#define megasas_resume NULL -#endif static inline int megasas_wait_for_adapter_operational(struct megasas_instance *instance) @@ -7931,7 +7905,7 @@ static void megasas_detach_one(struct pci_dev *pdev) /** * megasas_shutdown - Shutdown entry point - * @device: Generic device structure + * @pdev: PCI device structure */ static void megasas_shutdown(struct pci_dev *pdev) { @@ -8508,6 +8482,8 @@ static const struct file_operations megasas_mgmt_fops = { .llseek = noop_llseek, }; +static SIMPLE_DEV_PM_OPS(megasas_pm_ops, megasas_suspend, megasas_resume); + /* * PCI hotplug support registration structure */ @@ -8517,8 +8493,7 @@ static struct pci_driver megasas_pci_driver = { .id_table = megasas_pci_table, .probe = megasas_probe_one, .remove = megasas_detach_one, - .suspend = megasas_suspend, - .resume = megasas_resume, + .driver.pm = &megasas_pm_ops, .shutdown = megasas_shutdown, }; -- 2.27.0