Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1663948ybg; Wed, 29 Jul 2020 22:21:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEEmf7xVfd4UAQ9ZHp1UF56qUzdG+jJJFL2eTFdxdGe84JxQhYcpHC/6/ay2G/C3L4ABpQ X-Received: by 2002:a17:906:7155:: with SMTP id z21mr1025535ejj.282.1596086482109; Wed, 29 Jul 2020 22:21:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596086482; cv=none; d=google.com; s=arc-20160816; b=o/nU7F3buz+PhpwrtMY8jrfqWHth/uM2bNynytI67UsmrNDUwVwxhE3axGkVrYK91U LkFcSdm11lG56nLfqXaijBLEZT170vWsm5ZFm2/PuVvMM0A0y8e6AtyGSohaSLZJHjCz +dhqInsMzGVvTpV07E/5YLIJId6jixgg6ikNs3p+bycZMZjlOz89GTTQDysK5kndiMnA ODY/O499MbPXSCh0GmUUkwMVvIIBFWA24LETnYycCBB9HNXDLM11U6mkCRXzHDwITtsV tblth4i3pZnzqlz44pPKTyQONcHY14o2wobU6jHCt8/L8HZChmvxnpwAS7TGHJFhintj JzvQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=EnGXeNbQwuYNZ4/SgA8a2g0/K9Xn2zkd8XxAO1wpPBE=; b=0V315weSsf3gMoFW0LcSGqogU4DvisSIf6loz+2HEUE5ouRuVX8GmCz+X3XeDLiqWF VbOfOctka0oP45osVRSGCoeEpBWrGXJyoYVaVtAn3sRJo11UtOS/uZRIEzRed7TRFdg4 s6RbtLRAIqZyqRXcxIgRuts3PshgeYyIJ61jiOmv6E9te7lvguoRwUbmsf+9/bmIW4rx ljOiCTODzlOsI//JglCLAQydMxwAN1+ErCWxZSZv9ppQxmS4d5PqrpH4uR1WULKvW0RV DSXsCQ/hOyDUGZ+aB1leZ3Njpd5nluK7mM6NVHE307ROuKGv5caye021p+9rZVFqB5Sc TNjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=CNYeSPa5; 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 g7si2616889edj.525.2020.07.29.22.20.59; Wed, 29 Jul 2020 22:21:22 -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=CNYeSPa5; 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 S1728645AbgG3FTk (ORCPT + 99 others); Thu, 30 Jul 2020 01:19:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727838AbgG3FTj (ORCPT ); Thu, 30 Jul 2020 01:19:39 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC975C061794; Wed, 29 Jul 2020 22:19:39 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id u10so3655203plr.7; Wed, 29 Jul 2020 22:19:39 -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:mime-version :content-transfer-encoding; bh=EnGXeNbQwuYNZ4/SgA8a2g0/K9Xn2zkd8XxAO1wpPBE=; b=CNYeSPa5UHoQU/zAXoMxTvIy8LM9ZnpBrUa+u5uUMyQdzorRKQusWkM0WWRphxi5ru p/FmoF5qPGgJNNY0+EDETyed1MxEEDnBRCn9/qFltha0m+8igcWmCh9nFCRh3mRLf5qE oXYFuLxMrynBJjPTQ7xkCv/VoWYHHQ2CxG1MYDb+mDbsqpKjABOqr2615HF+D0k0Y0bq hwvXDejkhM7UM6Kq06SzRnTtf4aB1nJ4vOVO7tFo3BKYD0PajnvSPrWUBK29IIfPQCAQ blSwhF47KNibbIJ0e+vT7gwNsoX4dZds4/os/tKEW05Jbq9BhC9BWwcZUM8GY/o0iiOY 5Fpg== 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:mime-version :content-transfer-encoding; bh=EnGXeNbQwuYNZ4/SgA8a2g0/K9Xn2zkd8XxAO1wpPBE=; b=ZpvvJcx1L6B6EVe5tw0dnjBR5DrHJlZZrXLfE7E/t8FhC1ixH4/O4ECQ70BxzuF8z1 oUCQ6lEitwFG9xR9wFBlenq8V0iVcHCLw5k3sO6uLdj0q16um5Isx6VPHqmh8R2PyTPL Jos1Gc//WtjkpbOJaBleR4ROf+YVF2O+OUIulCnNEy4wNn4YNldfaM4c1HyzSm++oc9j NeV7/WyJPHlNWdm8cMYQcjyMH2GD1pSsCxj1S7aMc2oqSpG+3N+6dBaYJC7TCM8zNnSV w38UOojlPlzFl95beAFYXZJOkmd8R7gGasap+CQ2zsUUrk8e6xS/wC206+xe6PXcDik6 m2kQ== X-Gm-Message-State: AOAM5323x6vWTIReWcWarTVeRKGubv1IC3brQBmDrVegkYNqtwI3vmtm mYkLh0/8Xr69ATGg6k7hPeY= X-Received: by 2002:a17:902:103:: with SMTP id 3mr31556502plb.195.1596086379202; Wed, 29 Jul 2020 22:19:39 -0700 (PDT) Received: from varodek.iballbatonwifi.com ([103.105.152.86]) by smtp.gmail.com with ESMTPSA id 9sm4224025pfx.131.2020.07.29.22.19.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jul 2020 22:19:38 -0700 (PDT) From: Vaibhav Gupta To: Bjorn Helgaas , Bjorn Helgaas , Bjorn Helgaas , Vaibhav Gupta , "James E.J. Bottomley" , "Martin K. Petersen" Cc: Vaibhav Gupta , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, Shuah Khan Subject: [PATCH v1] scsi: stex: use generic power management Date: Thu, 30 Jul 2020 10:47:33 +0530 Message-Id: <20200730051733.113652-1-vaibhavgupta40@gmail.com> X-Mailer: git-send-email 2.27.0 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 Drivers using legacy power management .suspen()/.resume() callbacks have to manage PCI states and device's PM states themselves. They also need to take care of standard configuration registers. Switch to generic power management framework using a single "struct dev_pm_ops" variable to take the unnecessary load from the driver. This also avoids the need for the driver to directly call most of the PCI helper functions and device power state control functions, as through the generic framework PCI Core takes care of the necessary operations, and drivers are required to do only device-specific jobs. Signed-off-by: Vaibhav Gupta --- drivers/scsi/stex.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c index d4f10c0d813c..9500666b521a 100644 --- a/drivers/scsi/stex.c +++ b/drivers/scsi/stex.c @@ -1972,9 +1972,9 @@ static int stex_choice_sleep_mic(struct st_hba *hba, pm_message_t state) } } -static int stex_suspend(struct pci_dev *pdev, pm_message_t state) +static int stex_suspend_late(struct device *dev, pm_message_t state) { - struct st_hba *hba = pci_get_drvdata(pdev); + struct st_hba *hba = dev_get_drvdata(dev); if ((hba->cardtype == st_yel || hba->cardtype == st_P3) && hba->supports_pm == 1) @@ -1984,9 +1984,24 @@ static int stex_suspend(struct pci_dev *pdev, pm_message_t state) return 0; } -static int stex_resume(struct pci_dev *pdev) +static int stex_suspend(struct device *dev) { - struct st_hba *hba = pci_get_drvdata(pdev); + return stex_suspend_late(dev, PMSG_SUSPEND); +} + +static int stex_hibernate(struct device *dev) +{ + return stex_suspend_late(dev, PMSG_HIBERNATE); +} + +static int stex_freeze(struct device *dev) +{ + return stex_suspend_late(dev, PMSG_FREEZE); +} + +static int stex_resume(struct device *dev) +{ + struct st_hba *hba = dev_get_drvdata(dev); hba->mu_status = MU_STATE_STARTING; stex_handshake(hba); @@ -2000,14 +2015,22 @@ static int stex_halt(struct notifier_block *nb, unsigned long event, void *buf) } MODULE_DEVICE_TABLE(pci, stex_pci_tbl); +static const struct dev_pm_ops stex_pm_ops = { + .suspend = stex_suspend, + .resume = stex_resume, + .freeze = stex_freeze, + .thaw = stex_resume, + .poweroff = stex_hibernate, + .restore = stex_resume, +}; + static struct pci_driver stex_pci_driver = { .name = DRV_NAME, .id_table = stex_pci_tbl, .probe = stex_probe, .remove = stex_remove, .shutdown = stex_shutdown, - .suspend = stex_suspend, - .resume = stex_resume, + .driver.pm = &stex_pm_ops, }; static int __init stex_init(void) -- 2.27.0