All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vaibhav Gupta <vaibhavgupta40@gmail.com>
To: Bjorn Helgaas <helgaas@kernel.org>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Bjorn Helgaas <bjorn@helgaas.com>,
	Vaibhav Gupta <vaibhav.varodek@gmail.com>,
	Jens Axboe <axboe@kernel.dk>,
	Joshua Morris <josh.h.morris@us.ibm.com>,
	Philip Kelleher <pjk1939@linux.ibm.com>,
	Damien Le Moal <Damien.LeMoal@wdc.com>
Cc: Vaibhav Gupta <vaibhavgupta40@gmail.com>,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kernel-mentees@lists.linuxfoundation.org,
	Shuah Khan <skhan@linuxfoundation.org>
Subject: [PATCH v2 1/3] mtip32xx: use generic power management
Date: Mon, 20 Jul 2020 19:00:00 +0530	[thread overview]
Message-ID: <20200720133002.448809-2-vaibhavgupta40@gmail.com> (raw)
In-Reply-To: <20200720133002.448809-1-vaibhavgupta40@gmail.com>

Drivers using legacy PM have to manage PCI states and device's PM states
themselves. They also need to take care of configuration registers.

With improved and powerful support of generic PM, PCI Core takes care of
above mentioned, device-independent, jobs.

This driver makes use of PCI helper functions like
pci_save/restore_state(), pci_disable_device(), pcim_enable_device(),
pci_set_power_state() and pci_set_master() to do required operations. In
generic mode, they are no longer needed.

Change function parameter in both .suspend() and .resume() to
"struct device*" type. Use dev_get_drvdata() to get drv data.

Compile-tested only.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
---
 drivers/block/mtip32xx/mtip32xx.c | 54 +++++++------------------------
 1 file changed, 12 insertions(+), 42 deletions(-)

diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index f6bafa9a68b9..7d1280952b35 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -4246,14 +4246,13 @@ static void mtip_pci_remove(struct pci_dev *pdev)
  *	0  Success
  *	<0 Error
  */
-static int mtip_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
+static int __maybe_unused mtip_pci_suspend(struct device *dev)
 {
 	int rv = 0;
-	struct driver_data *dd = pci_get_drvdata(pdev);
+	struct driver_data *dd = dev_get_drvdata(dev);
 
 	if (!dd) {
-		dev_err(&pdev->dev,
-			"Driver private datastructure is NULL\n");
+		dev_err(dev, "Driver private datastructure is NULL\n");
 		return -EFAULT;
 	}
 
@@ -4261,21 +4260,8 @@ static int mtip_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
 
 	/* Disable ports & interrupts then send standby immediate */
 	rv = mtip_block_suspend(dd);
-	if (rv < 0) {
-		dev_err(&pdev->dev,
-			"Failed to suspend controller\n");
-		return rv;
-	}
-
-	/*
-	 * Save the pci config space to pdev structure &
-	 * disable the device
-	 */
-	pci_save_state(pdev);
-	pci_disable_device(pdev);
-
-	/* Move to Low power state*/
-	pci_set_power_state(pdev, PCI_D3hot);
+	if (rv < 0)
+		dev_err(dev, "Failed to suspend controller\n");
 
 	return rv;
 }
@@ -4287,42 +4273,25 @@ static int mtip_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
  *      0  Success
  *      <0 Error
  */
-static int mtip_pci_resume(struct pci_dev *pdev)
+static int __maybe_unused mtip_pci_resume(struct device *dev)
 {
 	int rv = 0;
 	struct driver_data *dd;
 
-	dd = pci_get_drvdata(pdev);
+	dd = dev_get_drvdata(dev);
 	if (!dd) {
-		dev_err(&pdev->dev,
-			"Driver private datastructure is NULL\n");
+		dev_err(dev, "Driver private datastructure is NULL\n");
 		return -EFAULT;
 	}
 
-	/* Move the device to active State */
-	pci_set_power_state(pdev, PCI_D0);
-
-	/* Restore PCI configuration space */
-	pci_restore_state(pdev);
-
-	/* Enable the PCI device*/
-	rv = pcim_enable_device(pdev);
-	if (rv < 0) {
-		dev_err(&pdev->dev,
-			"Failed to enable card during resume\n");
-		goto err;
-	}
-	pci_set_master(pdev);
-
 	/*
 	 * Calls hbaReset, initPort, & startPort function
 	 * then enables interrupts
 	 */
 	rv = mtip_block_resume(dd);
 	if (rv < 0)
-		dev_err(&pdev->dev, "Unable to resume\n");
+		dev_err(dev, "Unable to resume\n");
 
-err:
 	clear_bit(MTIP_DDF_RESUME_BIT, &dd->dd_flag);
 
 	return rv;
@@ -4353,14 +4322,15 @@ static const struct pci_device_id mtip_pci_tbl[] = {
 	{ 0 }
 };
 
+static SIMPLE_DEV_PM_OPS(mtip_pci_pm_ops, mtip_pci_suspend, mtip_pci_resume);
+
 /* Structure that describes the PCI driver functions. */
 static struct pci_driver mtip_pci_driver = {
 	.name			= MTIP_DRV_NAME,
 	.id_table		= mtip_pci_tbl,
 	.probe			= mtip_pci_probe,
 	.remove			= mtip_pci_remove,
-	.suspend		= mtip_pci_suspend,
-	.resume			= mtip_pci_resume,
+	.driver.pm		= &mtip_pci_pm_ops,
 	.shutdown		= mtip_pci_shutdown,
 };
 
-- 
2.27.0


WARNING: multiple messages have this Message-ID (diff)
From: Vaibhav Gupta <vaibhavgupta40@gmail.com>
To: Bjorn Helgaas <helgaas@kernel.org>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Bjorn Helgaas <bjorn@helgaas.com>,
	Vaibhav Gupta <vaibhav.varodek@gmail.com>,
	Jens Axboe <axboe@kernel.dk>,
	Joshua Morris <josh.h.morris@us.ibm.com>,
	Philip Kelleher <pjk1939@linux.ibm.com>,
	Damien Le Moal <Damien.LeMoal@wdc.com>
Cc: linux-block@vger.kernel.org,
	linux-kernel-mentees@lists.linuxfoundation.org,
	linux-kernel@vger.kernel.org,
	Vaibhav Gupta <vaibhavgupta40@gmail.com>
Subject: [Linux-kernel-mentees] [PATCH v2 1/3] mtip32xx: use generic power management
Date: Mon, 20 Jul 2020 19:00:00 +0530	[thread overview]
Message-ID: <20200720133002.448809-2-vaibhavgupta40@gmail.com> (raw)
In-Reply-To: <20200720133002.448809-1-vaibhavgupta40@gmail.com>

Drivers using legacy PM have to manage PCI states and device's PM states
themselves. They also need to take care of configuration registers.

With improved and powerful support of generic PM, PCI Core takes care of
above mentioned, device-independent, jobs.

This driver makes use of PCI helper functions like
pci_save/restore_state(), pci_disable_device(), pcim_enable_device(),
pci_set_power_state() and pci_set_master() to do required operations. In
generic mode, they are no longer needed.

Change function parameter in both .suspend() and .resume() to
"struct device*" type. Use dev_get_drvdata() to get drv data.

Compile-tested only.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
---
 drivers/block/mtip32xx/mtip32xx.c | 54 +++++++------------------------
 1 file changed, 12 insertions(+), 42 deletions(-)

diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index f6bafa9a68b9..7d1280952b35 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -4246,14 +4246,13 @@ static void mtip_pci_remove(struct pci_dev *pdev)
  *	0  Success
  *	<0 Error
  */
-static int mtip_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
+static int __maybe_unused mtip_pci_suspend(struct device *dev)
 {
 	int rv = 0;
-	struct driver_data *dd = pci_get_drvdata(pdev);
+	struct driver_data *dd = dev_get_drvdata(dev);
 
 	if (!dd) {
-		dev_err(&pdev->dev,
-			"Driver private datastructure is NULL\n");
+		dev_err(dev, "Driver private datastructure is NULL\n");
 		return -EFAULT;
 	}
 
@@ -4261,21 +4260,8 @@ static int mtip_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
 
 	/* Disable ports & interrupts then send standby immediate */
 	rv = mtip_block_suspend(dd);
-	if (rv < 0) {
-		dev_err(&pdev->dev,
-			"Failed to suspend controller\n");
-		return rv;
-	}
-
-	/*
-	 * Save the pci config space to pdev structure &
-	 * disable the device
-	 */
-	pci_save_state(pdev);
-	pci_disable_device(pdev);
-
-	/* Move to Low power state*/
-	pci_set_power_state(pdev, PCI_D3hot);
+	if (rv < 0)
+		dev_err(dev, "Failed to suspend controller\n");
 
 	return rv;
 }
@@ -4287,42 +4273,25 @@ static int mtip_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
  *      0  Success
  *      <0 Error
  */
-static int mtip_pci_resume(struct pci_dev *pdev)
+static int __maybe_unused mtip_pci_resume(struct device *dev)
 {
 	int rv = 0;
 	struct driver_data *dd;
 
-	dd = pci_get_drvdata(pdev);
+	dd = dev_get_drvdata(dev);
 	if (!dd) {
-		dev_err(&pdev->dev,
-			"Driver private datastructure is NULL\n");
+		dev_err(dev, "Driver private datastructure is NULL\n");
 		return -EFAULT;
 	}
 
-	/* Move the device to active State */
-	pci_set_power_state(pdev, PCI_D0);
-
-	/* Restore PCI configuration space */
-	pci_restore_state(pdev);
-
-	/* Enable the PCI device*/
-	rv = pcim_enable_device(pdev);
-	if (rv < 0) {
-		dev_err(&pdev->dev,
-			"Failed to enable card during resume\n");
-		goto err;
-	}
-	pci_set_master(pdev);
-
 	/*
 	 * Calls hbaReset, initPort, & startPort function
 	 * then enables interrupts
 	 */
 	rv = mtip_block_resume(dd);
 	if (rv < 0)
-		dev_err(&pdev->dev, "Unable to resume\n");
+		dev_err(dev, "Unable to resume\n");
 
-err:
 	clear_bit(MTIP_DDF_RESUME_BIT, &dd->dd_flag);
 
 	return rv;
@@ -4353,14 +4322,15 @@ static const struct pci_device_id mtip_pci_tbl[] = {
 	{ 0 }
 };
 
+static SIMPLE_DEV_PM_OPS(mtip_pci_pm_ops, mtip_pci_suspend, mtip_pci_resume);
+
 /* Structure that describes the PCI driver functions. */
 static struct pci_driver mtip_pci_driver = {
 	.name			= MTIP_DRV_NAME,
 	.id_table		= mtip_pci_tbl,
 	.probe			= mtip_pci_probe,
 	.remove			= mtip_pci_remove,
-	.suspend		= mtip_pci_suspend,
-	.resume			= mtip_pci_resume,
+	.driver.pm		= &mtip_pci_pm_ops,
 	.shutdown		= mtip_pci_shutdown,
 };
 
-- 
2.27.0

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

  reply	other threads:[~2020-07-20 13:31 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-17  8:09 [PATCH v1 0/3] block: use generic power management Vaibhav Gupta
2020-07-17  8:09 ` [Linux-kernel-mentees] " Vaibhav Gupta
2020-07-17  8:09 ` [PATCH v1 1/3] mtip32xx: " Vaibhav Gupta
2020-07-17  8:09   ` [Linux-kernel-mentees] " Vaibhav Gupta
2020-07-17  8:09 ` [PATCH v1 2/3] rsxx: " Vaibhav Gupta
2020-07-17  8:09   ` [Linux-kernel-mentees] " Vaibhav Gupta
2020-07-17  8:09 ` [PATCH v1 3/3] skd: " Vaibhav Gupta
2020-07-17  8:09   ` [Linux-kernel-mentees] " Vaibhav Gupta
2020-07-20 12:52   ` Damien Le Moal
2020-07-20 12:52     ` [Linux-kernel-mentees] " Damien Le Moal
2020-07-20 13:16     ` Vaibhav Gupta
2020-07-20 13:16       ` [Linux-kernel-mentees] " Vaibhav Gupta
2020-07-21  2:49       ` Damien Le Moal
2020-07-21  2:49         ` [Linux-kernel-mentees] " Damien Le Moal
2020-07-21  7:04         ` Vaibhav Gupta
2020-07-21  7:04           ` [Linux-kernel-mentees] " Vaibhav Gupta
2020-07-20 13:29     ` [PATCH v2 0/3] block: " Vaibhav Gupta
2020-07-20 13:29       ` [Linux-kernel-mentees] " Vaibhav Gupta
2020-07-20 13:30       ` Vaibhav Gupta [this message]
2020-07-20 13:30         ` [Linux-kernel-mentees] [PATCH v2 1/3] mtip32xx: " Vaibhav Gupta
2020-07-20 13:30       ` [PATCH v2 2/3] rsxx: " Vaibhav Gupta
2020-07-20 13:30         ` [Linux-kernel-mentees] " Vaibhav Gupta
2020-07-20 13:30       ` [PATCH v2 3/3] skd: " Vaibhav Gupta
2020-07-20 13:30         ` [Linux-kernel-mentees] " Vaibhav Gupta
2020-07-21  2:57         ` Damien Le Moal
2020-07-21  2:57           ` [Linux-kernel-mentees] " Damien Le Moal
2020-07-21  7:09           ` Vaibhav Gupta
2020-07-21  7:09             ` [Linux-kernel-mentees] " Vaibhav Gupta
2020-07-22  6:28             ` Damien Le Moal
2020-07-22  6:28               ` [Linux-kernel-mentees] " Damien Le Moal
2020-07-22  7:21               ` Vaibhav Gupta
2020-07-22  7:21                 ` [Linux-kernel-mentees] " Vaibhav Gupta
2020-07-22  8:33               ` [PATCH v3 0/3] block: " Vaibhav Gupta
2020-07-22  8:33                 ` [Linux-kernel-mentees] " Vaibhav Gupta
2020-07-22  8:33                 ` [PATCH v3 1/3] mtip32xx: " Vaibhav Gupta
2020-07-22  8:33                   ` [Linux-kernel-mentees] " Vaibhav Gupta
2020-07-22  8:33                 ` [PATCH v3 2/3] rsxx: " Vaibhav Gupta
2020-07-22  8:33                   ` [Linux-kernel-mentees] " Vaibhav Gupta
2020-07-22  8:33                 ` [PATCH v3 3/3] skd: " Vaibhav Gupta
2020-07-22  8:33                   ` [Linux-kernel-mentees] " Vaibhav Gupta
2020-07-27  2:14                   ` Damien Le Moal
2020-07-27  2:14                     ` [Linux-kernel-mentees] " Damien Le Moal
2020-08-17  7:55                 ` [PATCH v3 0/3] block: " Vaibhav Gupta
2020-08-17  7:55                   ` [Linux-kernel-mentees] " Vaibhav Gupta
2021-01-14 11:54                 ` [PATCH v4 " Vaibhav Gupta
2021-01-14 11:54                   ` [Linux-kernel-mentees] " Vaibhav Gupta
2021-01-14 11:54                   ` [PATCH v4 1/3] mtip32xx: " Vaibhav Gupta
2021-01-14 11:54                     ` [Linux-kernel-mentees] " Vaibhav Gupta
2021-01-14 11:54                   ` [PATCH v4 2/3] rsxx: " Vaibhav Gupta
2021-01-14 11:54                     ` [Linux-kernel-mentees] " Vaibhav Gupta
2021-01-14 11:54                   ` [PATCH v4 3/3] skd: " Vaibhav Gupta
2021-01-14 11:54                     ` [Linux-kernel-mentees] " Vaibhav Gupta
2020-07-22 17:52             ` [PATCH v2 " Bjorn Helgaas
2020-07-22 17:52               ` [Linux-kernel-mentees] " Bjorn Helgaas
2020-07-22 18:07               ` Vaibhav Gupta
2020-07-22 18:07                 ` [Linux-kernel-mentees] " Vaibhav Gupta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200720133002.448809-2-vaibhavgupta40@gmail.com \
    --to=vaibhavgupta40@gmail.com \
    --cc=Damien.LeMoal@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=bhelgaas@google.com \
    --cc=bjorn@helgaas.com \
    --cc=helgaas@kernel.org \
    --cc=josh.h.morris@us.ibm.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pjk1939@linux.ibm.com \
    --cc=skhan@linuxfoundation.org \
    --cc=vaibhav.varodek@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.