Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp3439431pxx; Mon, 2 Nov 2020 08:56:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzmE2ZRNIR327IXNRVY0Fk4pbiLdRq/DiMLucyXwXKPn3aMeSDvYZUCE4qEnhS8yZaH319j X-Received: by 2002:a17:906:491a:: with SMTP id b26mr2805680ejq.385.1604336206837; Mon, 02 Nov 2020 08:56:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604336206; cv=none; d=google.com; s=arc-20160816; b=VRaMrnOEcUTengTxuS+YFAbIsCAAr3k6ggcZVAB4MvHdTJhsf9ejBF6jVPZNq8Taln VLEeo/+A0j8UfVcDwkzKcDEp7K70NMQjD3J92nT5A51YpYbG/bM4YX3aAChbMJYMxbj/ UnNoez3y3sPDAxXBplkWpkHwF3tEiSn11GFQlk3nVdUzgKMOA5VHLXlsBKOvH29mjzMs xFEmOIJt58g59LC7QeOnAVsDbpgTMbwxCy2pxaI2v+FfIgVmB9zcO0YBPwVN3t2+iRlY St+ldwTm5MyRwbGc+MFlfVhlxtm/j+nUtUcVWQoq1QXe83+H60fmsOuvjS5ksXeoYHkV glVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VhabbmrVlKfIcloXKiUycGjVLZHaLqGck6HUDFpjzd4=; b=KVuVy2Osg6UJ6b0KDE/J4DeizYr+DchQ6XbJaecSZcZezpyrxMau433PTklTdVeiBs 9ex/ZCV12EmSd0jQ+JM4qdHeQJ8ogprn4Zier6Z7JK0YSePmu7TB0/9Vv/RvzqM0yNBy 7AKJbwJvBQl088hvEIqWgoE1gcOCGJswG0gnjQNG3+8qEivlRBCZ77I7dxvk+gc9aRV1 v8skZ182bt4VdjEeOemHxaEywn2nur3CXGpYb8CQSz2+IvPyKhjQt6kgP/ENEZ2UyGJb Hr0OPboqD3u5kul3JdKXbp4NWGwvdn0+NBgBnGsF8gTkq2xAeZrDrAOVmpOo7isphKLh P6mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FNiyl1hX; 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 qt18si5128609ejb.602.2020.11.02.08.56.24; Mon, 02 Nov 2020 08:56:46 -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=@gmail.com header.s=20161025 header.b=FNiyl1hX; 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 S1727327AbgKBQyE (ORCPT + 99 others); Mon, 2 Nov 2020 11:54:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726619AbgKBQyD (ORCPT ); Mon, 2 Nov 2020 11:54:03 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73560C0617A6; Mon, 2 Nov 2020 08:54:03 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id w4so1059280pgg.13; Mon, 02 Nov 2020 08:54:03 -0800 (PST) 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=VhabbmrVlKfIcloXKiUycGjVLZHaLqGck6HUDFpjzd4=; b=FNiyl1hXUBQIr2AqRDMiQQrHQtakYZefo7BHUUaFEaNe3AON3Ra5wz0jv1lYLopD/J 9q8+190FFV4gQaefv/2wGEECM1DanKSBBp6LpCc5bFyiS/gJ+vAWZ2XhBgvBprgyn077 FtvPNPx+RM9xASBAwpDud3V4EfOVN+Dh/9fc+LvsrT2IGgKnHDRKA1uwwlTf8TFb4Mo7 Xe3hTU/lEOs5umAd2rcm6QQ20EQOL36vlpNKBpAt/kwzfLP8K3TFO6RzPr+MypS1qIDV vuob7yY27jvqqNGxWe15ZTzBVzQdcCPRfXzff+iC9VGLk3vk1aq6qMg6V2WoZ2bF7s5E YD/A== 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=VhabbmrVlKfIcloXKiUycGjVLZHaLqGck6HUDFpjzd4=; b=etcvYIQRsfAcgWccS/1ttbZOzfAQKrx0/PFAhM+H1BBhHlIND6ShCVwAHZcAOrR/kX P/6Ewa8JGI3B0iCf4HttrHI8CmixXcXtv9MpoSRkY/jsRYqt1JkAvKagIvciXKIzVnmq DpbrykCdNbJhOVStoB9CGB6AAzbq8LEpfIqS6DslCgzVyOdvpisT7nmQuoVlPGTTnWJ3 UA7fyM5il8BjLYmB+Gtk3ywobeKo18FkTA/kM6l3NxXVn/xeJFDtI7/rV6DWYzySpNcN 3ZkaNaC8dnzbeeUrYdT2zu6jGzObTIyqOXyRMMCDJJFH3GFauiVuTdjcDNyKBzCT69FZ FkKg== X-Gm-Message-State: AOAM5309TZOT0f/P8k13KvBt4kSmN9Juci8JmxT0uysqYy2FwmgOsrAg cGAYL4dhn0roGfDuG1L3cOU= X-Received: by 2002:a17:90a:4a15:: with SMTP id e21mr4038914pjh.130.1604336042989; Mon, 02 Nov 2020 08:54:02 -0800 (PST) Received: from varodek.localdomain ([223.179.149.110]) by smtp.gmail.com with ESMTPSA id t74sm4953233pfc.47.2020.11.02.08.53.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 08:54:02 -0800 (PST) From: Vaibhav Gupta To: Bjorn Helgaas , Bjorn Helgaas , Bjorn Helgaas , Vaibhav Gupta , Adam Radford , "James E.J. Bottomley" , "Martin K. Petersen" , Adaptec OEM Raid Solutions , Hannes Reinecke , Bradley Grove , John Garry , Don Brace , Xiang Chen , James Smart , Dick Kennedy , Kashyap Desai , Sumit Saxena , Shivasharan S , Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani , Jack Wang , Balsundar P 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 v4 19/29] scsi: pm_8001: use generic power management Date: Mon, 2 Nov 2020 22:17:20 +0530 Message-Id: <20201102164730.324035-20-vaibhavgupta40@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201102164730.324035-1-vaibhavgupta40@gmail.com> References: <20201102164730.324035-1-vaibhavgupta40@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Drivers should do only device-specific jobs. But in general, drivers using legacy PCI PM framework for .suspend()/.resume() have to manage many PCI PM-related tasks themselves which can be done by PCI Core itself. This brings extra load on the driver and it directly calls PCI helper functions to handle them. Switch to the new generic framework by updating function signatures and define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove unnecessary calls to the PCI Helper functions along with the legacy .suspend & .resume bindings. Signed-off-by: Vaibhav Gupta --- drivers/scsi/pm8001/pm8001_init.c | 45 +++++++++++-------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c index d47ed9a33173..7a732fd09b38 100644 --- a/drivers/scsi/pm8001/pm8001_init.c +++ b/drivers/scsi/pm8001/pm8001_init.c @@ -1257,23 +1257,21 @@ static void pm8001_pci_remove(struct pci_dev *pdev) /** * pm8001_pci_suspend - power management suspend main entry point - * @pdev: PCI device struct - * @state: PM state change to (usually PCI_D3) + * @dev: Device struct * * Returns 0 success, anything else error. */ -static int pm8001_pci_suspend(struct pci_dev *pdev, pm_message_t state) +static int __maybe_unused pm8001_pci_suspend(struct device *dev) { + struct pci_dev *pdev = to_pci_dev(dev); struct sas_ha_struct *sha = pci_get_drvdata(pdev); - struct pm8001_hba_info *pm8001_ha; + struct pm8001_hba_info *pm8001_ha = sha->lldd_ha; int i, j; - u32 device_state; - pm8001_ha = sha->lldd_ha; sas_suspend_ha(sha); flush_workqueue(pm8001_wq); scsi_block_requests(pm8001_ha->shost); if (!pdev->pm_cap) { - dev_err(&pdev->dev, " PCI PM not supported\n"); + dev_err(dev, " PCI PM not supported\n"); return -ENODEV; } PM8001_CHIP_DISP->interrupt_disable(pm8001_ha, 0xFF); @@ -1296,24 +1294,21 @@ static int pm8001_pci_suspend(struct pci_dev *pdev, pm_message_t state) for (j = 0; j < PM8001_MAX_MSIX_VEC; j++) tasklet_kill(&pm8001_ha->tasklet[j]); #endif - device_state = pci_choose_state(pdev, state); pm8001_printk("pdev=0x%p, slot=%s, entering " - "operating state [D%d]\n", pdev, - pm8001_ha->name, device_state); - pci_save_state(pdev); - pci_disable_device(pdev); - pci_set_power_state(pdev, device_state); + "suspended state\n", pdev, + pm8001_ha->name); return 0; } /** * pm8001_pci_resume - power management resume main entry point - * @pdev: PCI device struct + * @dev: Device struct * * Returns 0 success, anything else error. */ -static int pm8001_pci_resume(struct pci_dev *pdev) +static int __maybe_unused pm8001_pci_resume(struct device *dev) { + struct pci_dev *pdev = to_pci_dev(dev); struct sas_ha_struct *sha = pci_get_drvdata(pdev); struct pm8001_hba_info *pm8001_ha; int rc; @@ -1326,16 +1321,6 @@ static int pm8001_pci_resume(struct pci_dev *pdev) pm8001_printk("pdev=0x%p, slot=%s, resuming from previous " "operating state [D%d]\n", pdev, pm8001_ha->name, device_state); - pci_set_power_state(pdev, PCI_D0); - pci_restore_state(pdev); - rc = pci_enable_device(pdev); - if (rc) { - pm8001_printk("slot=%s Enable device failed during resume\n", - pm8001_ha->name); - goto err_out_enable; - } - - pci_set_master(pdev); rc = pci_go_44(pdev); if (rc) goto err_out_disable; @@ -1396,8 +1381,7 @@ static int pm8001_pci_resume(struct pci_dev *pdev) err_out_disable: scsi_remove_host(pm8001_ha->shost); - pci_disable_device(pdev); -err_out_enable: + return rc; } @@ -1480,13 +1464,16 @@ static struct pci_device_id pm8001_pci_table[] = { {} /* terminate list */ }; +static SIMPLE_DEV_PM_OPS(pm8001_pci_pm_ops, + pm8001_pci_suspend, + pm8001_pci_resume); + static struct pci_driver pm8001_pci_driver = { .name = DRV_NAME, .id_table = pm8001_pci_table, .probe = pm8001_pci_probe, .remove = pm8001_pci_remove, - .suspend = pm8001_pci_suspend, - .resume = pm8001_pci_resume, + .driver.pm = &pm8001_pci_pm_ops, }; /** -- 2.28.0