From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B0E6C433EB for ; Wed, 22 Jul 2020 08:35:11 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3C24020787 for ; Wed, 22 Jul 2020 08:35:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GmynCEVD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3C24020787 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-kernel-mentees-bounces@lists.linuxfoundation.org Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id E74DC203F3; Wed, 22 Jul 2020 08:35:10 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IinExmLZ9ilk; Wed, 22 Jul 2020 08:35:10 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id F143E203D0; Wed, 22 Jul 2020 08:35:09 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E6799C004E; Wed, 22 Jul 2020 08:35:09 +0000 (UTC) Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7A9CAC004C for ; Wed, 22 Jul 2020 08:35:08 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 6FF8188615 for ; Wed, 22 Jul 2020 08:35:08 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dVPZjSwBGaU2 for ; Wed, 22 Jul 2020 08:35:07 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by hemlock.osuosl.org (Postfix) with ESMTPS id D8D6288256 for ; Wed, 22 Jul 2020 08:35:07 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id o1so608868plk.1 for ; Wed, 22 Jul 2020 01:35:07 -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=28LVHZQ5kNi3X4WVWRNBhsyjK8e2AXuHyTrkUX2gYzI=; b=GmynCEVDYL8vUdF/dEi+NEtI+iKXNlgK/RQ7XrkC2bdnEwCeiQfM1MQxJyBxznCxdP kmxk4C66hNqBKB2QUc1skHhm0mSkkVJ/LRRTFxUfyzsd8PXE3ddJtkc7VEk1yxt8G/SS hMX+b0zA3PVxDyNytY3xg9t2INZFXrYXhQWH7nWt3WWjjmRPcwAx+frJioOPSFP1aLJ+ LC46zqpag99ScnDKs+RI6xPDmy25JXWhh+xOlQ/Fg0c1KwuP7O/PJgEYXV9XgjoET6UL tljtmCnUcXhtWWu/8iHiwKn6W0INYH2kTKw82cxg79tJYMfI1Ct0MhyoducO00LIDmH4 LOrw== 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=28LVHZQ5kNi3X4WVWRNBhsyjK8e2AXuHyTrkUX2gYzI=; b=eZ2hTykV7OYiAmBHORGGFIP5fU9eKFdck1tjnCFmh9rhfIKo97SeL94jm/XB3bnVSC vpg6Av7oD8HfcHe3q/LlChoreN1bE1b7I0sRmdlVK1smzCmje1etgBG3ptx5/EokobmC OazegQ5YnPnbEmrGOohsy2wx5Gl4A1+Hcm3dsPtcxXSJMT2JBH6RGxWg3rYpXF58juMg MAXPLrqgP+wby/iO8hZPQSj+HFurBqWGM2gdyipZl//aeAEzbmhrHz/lq7DsjqREz82O o0o+cqR6sTM/eKFSrldM6/DLuGR022XHYEub8GVAm3XaUkOZi4/nQLSnzxe5J8mmUgeZ NpVg== X-Gm-Message-State: AOAM531msL7OgDxvqU1rGjRty3fdBFLtjFwmTroeWLi9e3tbleNtryg1 FGtnoQm5vfZHT0eTyVxFjFE= X-Google-Smtp-Source: ABdhPJwbgrO0RP+E/o1QaKac8oSWHOrV2QrpXZWoauBIG5d+sFnfguSNdUB9tr89uey4iD3pQ1ow3w== X-Received: by 2002:a17:902:a5c5:: with SMTP id t5mr25735544plq.47.1595406907398; Wed, 22 Jul 2020 01:35:07 -0700 (PDT) Received: from varodek.iballbatonwifi.com ([103.105.153.67]) by smtp.gmail.com with ESMTPSA id g13sm5777319pje.29.2020.07.22.01.35.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 01:35:06 -0700 (PDT) From: Vaibhav Gupta To: Bjorn Helgaas , Bjorn Helgaas , Bjorn Helgaas , Vaibhav Gupta , Jens Axboe , Joshua Morris , Philip Kelleher , Damien Le Moal Date: Wed, 22 Jul 2020 14:03:33 +0530 Message-Id: <20200722083335.50068-2-vaibhavgupta40@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200722083335.50068-1-vaibhavgupta40@gmail.com> References: <20200722083335.50068-1-vaibhavgupta40@gmail.com> MIME-Version: 1.0 Cc: linux-block@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-kernel@vger.kernel.org, Vaibhav Gupta Subject: [Linux-kernel-mentees] [PATCH v3 1/3] mtip32xx: use generic power management X-BeenThere: linux-kernel-mentees@lists.linuxfoundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-kernel-mentees-bounces@lists.linuxfoundation.org Sender: "Linux-kernel-mentees" 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/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