Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2126903pxa; Mon, 17 Aug 2020 01:13:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2k6lVjkchpUzENMyIJZvc2ydqlY0NUr7oJyKqnAyrRB1ZYh5AEAgzkiRc65EaA+1gMyET X-Received: by 2002:a17:906:73d9:: with SMTP id n25mr14468216ejl.412.1597651994224; Mon, 17 Aug 2020 01:13:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597651994; cv=none; d=google.com; s=arc-20160816; b=FwD3BaBFU5Mo8oHzbNctp44trttZNaJuO3x/wpvNy79o6VeNPSUOsjz8t7TCHOFmyD OtIfse4dX1h/w2lgKTh/GkQr42XZtivoI7tjuJfE4QNyH29xYgFx+rXb7SmwvhDOHmCp AB8Ze81j2REwS1b4VmwS2LbO8DcowR1O2/GtLP1DSHZ6Ps9/fhEC3e1Lb/4+9Y0Wm+C0 5av9POzM3nGe2Xlkf1eT9un9KTDyqes4duTin/3BAuuOqq8izCJ9hmk6HIPlSVXZvF8V cgPbBDhsEvAEpTL/J2HFPXoWytQ2dfNCNu/zBhj6vYMFwm2Vo1TR++JRC6xbTHaF2qL3 lbOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=vrc3902/LyjUToaP0T6jczt+Dazk6Byup+Z2y7wGrvo=; b=q9hAWO31xTZcvCphk7GIQjiiq1YEoN2g6MkDHO46lHnmLKfWo32HrcbHjWdyw38lRB 5og88Tp4vuZMVwVGxjxgK4x8faYJTf5oPLVBeOuEkabsupoGMz/Um8DTir1bjuf00fjy yzseq0wVJBE4+bW0uvrDWPbEbPhwmod5d6z1L7ThhQfxlvVoVEJH0Mdq/KrY9EBNQzlL Fm2be7d2FsifS1AIvk1sMeGS9N7ls0ejCuuW8G7+Hhveeytw6QRPaJSkZetzGtfgBZ4C eHR7FQaVWA/Y6E0pYBM3zqVr4E4I8znP4bXb/t9eGFBy0XLaDMCH5Sdp9WffwsjiX7r9 QBKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ByO3yBfH; 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 g16si11406186ejf.103.2020.08.17.01.12.51; Mon, 17 Aug 2020 01:13:14 -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=ByO3yBfH; 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 S1727935AbgHQILg (ORCPT + 99 others); Mon, 17 Aug 2020 04:11:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727897AbgHQILW (ORCPT ); Mon, 17 Aug 2020 04:11:22 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1AB9C061388; Mon, 17 Aug 2020 01:11:22 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id s15so7747482pgc.8; Mon, 17 Aug 2020 01:11:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=vrc3902/LyjUToaP0T6jczt+Dazk6Byup+Z2y7wGrvo=; b=ByO3yBfHuC8Oi3Go9E9JvdznzILTxNU0krXeVns4vevfXHOBzuW8RUC5nPT1Inugth EkTLvMFjz9X8Y6qU1Hn2S2f2o1ZjPcTvmc/XO9CMb23IP7QMwR5ThDVv7DJR8gUym87Z 86TFejRu2JpzV/DNekTLCyl/dYZyduvNe2bvE2YaklYM9x/ZweDQE25z7ZVAuzZnmU3S oaiF+2jKHvJvSqXj8jp2DPFVL24k9YUu2S4t5flwPCfY4YLLFWV8rPiYLIT5B+maHsfJ 5YHP/fNZbAvAG8dyEv+2YSMbf1Ow2mGXtNWmxoOrS8mXzxbY3mT0GE1j6xWlabFlzJcz RmSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=vrc3902/LyjUToaP0T6jczt+Dazk6Byup+Z2y7wGrvo=; b=MjofrUaN3QLgfI4+omGjRYs7cQQQgaqqDManvmoMYqNC+zTAGuoxGb9bIsWLYnwSs4 McxbkH8xcrmaQQjT8ZKa1YhG22JwqwjhdGbDw2GZaCPEB1Mhu+v0S6Grl6sdUHf8i/Kb 9P1V5jIcvBBXLvHbnz+hJy4r5jHtRRWr0EcbTM2XCJ9gaeazbEwipJEYm0GGAHgHnKCA udRW320qhNRQeCr6Z1ULe7b9Uh80m4vel4NsX6sQ0YCMvcTtI9NRWu4VAvrchCIfXVAW UqOrEa28juedWiSSIC5oy/c01zLHRwgY1EwRYJYeVWrTGjwcPsc/Rz/d6JKHQZ3JlTu0 9Thw== X-Gm-Message-State: AOAM532GSvz/RMIuKLH2F8JxyB+mSckfgtdX0RCc5SW2z/uYyrJYj2Mm eN/Vg/55LJ9z/YjZdkj1/ME= X-Received: by 2002:a05:6a00:790:: with SMTP id g16mr10469418pfu.312.1597651882145; Mon, 17 Aug 2020 01:11:22 -0700 (PDT) Received: from gmail.com ([103.105.152.86]) by smtp.gmail.com with ESMTPSA id g7sm16961220pjj.2.2020.08.17.01.11.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2020 01:11:21 -0700 (PDT) Date: Mon, 17 Aug 2020 13:39:45 +0530 From: Vaibhav Gupta To: Bjorn Helgaas , Bjorn Helgaas , Bjorn Helgaas , Vaibhav Gupta , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, Shuah Khan Subject: Re: [PATCH v2] scsi: stex: use generic power management Message-ID: <20200817080945.GG5869@gmail.com> References: <20200730101658.576205-1-vaibhavgupta40@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200730101658.576205-1-vaibhavgupta40@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 30, 2020 at 03:46:58PM +0530, Vaibhav Gupta wrote: > 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 | 37 +++++++++++++++++++++++++++++++------ > 1 file changed, 31 insertions(+), 6 deletions(-) > > diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c > index d4f10c0d813c..5ef6f3cbac11 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 __maybe_unused stex_suspend(struct device *dev) > { > - struct st_hba *hba = pci_get_drvdata(pdev); > + return stex_suspend_late(dev, PMSG_SUSPEND); > +} > + > +static int __maybe_unused stex_hibernate(struct device *dev) > +{ > + return stex_suspend_late(dev, PMSG_HIBERNATE); > +} > + > +static int __maybe_unused stex_freeze(struct device *dev) > +{ > + return stex_suspend_late(dev, PMSG_FREEZE); > +} > + > +static int __maybe_unused 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,24 @@ 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 = { > +#ifdef CONFIG_PM_SLEEP > + .suspend = stex_suspend, > + .resume = stex_resume, > + .freeze = stex_freeze, > + .thaw = stex_resume, > + .poweroff = stex_hibernate, > + .restore = stex_resume, > +#endif > +}; > + > 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 >