From patchwork Thu May 13 08:36:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kashyap Desai X-Patchwork-Id: 437607 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=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MIME_HEADER_CTYPE_ONLY, SPF_HELO_NONE, SPF_PASS, T_TVD_MIME_NO_HEADERS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham 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 08C8CC43461 for ; Thu, 13 May 2021 08:34:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CDDEC613F6 for ; Thu, 13 May 2021 08:34:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232017AbhEMIfc (ORCPT ); Thu, 13 May 2021 04:35:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231976AbhEMIfN (ORCPT ); Thu, 13 May 2021 04:35:13 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8B2BC06138E for ; Thu, 13 May 2021 01:33:45 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id 10so21195685pfl.1 for ; Thu, 13 May 2021 01:33:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Oc0IZycrI7y5OZFxmREUWSvfPIQ5loP6tO4zJHd4L5g=; b=eaVhMWg2p9tR40GUBu+BBJz8oyJIXFzYbvaYw6RHRuUx6nJ0BYEqRwK9ghkYbGqFfU D8QXFyYoug+2EZATqYSz346enp5bll9NyxKtvsBEoPm4tIiQP5ZFylYiPvbwE2uF7Y5P PNLLeNOME71IlS5JIjpNcb964Fp3PgWv7gLmQ= 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; bh=Oc0IZycrI7y5OZFxmREUWSvfPIQ5loP6tO4zJHd4L5g=; b=Un1c1GcLr7r1032GFoG9PaCZeh3NVH4Ez0h+0+Kkr0iPhRZ1W0ED4LNgqC8wKqaruH oyy8O1Itr8xhdTzhvWQc2bgrRXNa4D1bNDUbT51trbuI52ZrS4JWKl0O/EMTvV+IKIao Y24MUYtYYoZP1/ig4m2iL0+QOMFKPNg7oto51oh3OHz42LncsFAyD732VNybWaUzVnFf yArO9F0ZAK2s87Dgqc0tu/LUY28OKYNalltW583rmPiVFQvs8uF2hDoYyW/QFOfsj1RK /bF/Unv14x/k9TIHlRN69FstiSsiDEuYPV3hVz3hzwMKqX7ljHtWM6Mm7Ljtdn0NZ8OK PGgw== X-Gm-Message-State: AOAM530e/tfF6ODnFFQhhLIwnmjsOQRQ8BYODo9Z07d1uRTqURBBLdq2 wBDaeSSFhj6N4R2PuwmvaZMl/YtpT1CgR0rpK0frrO15R0Nku8JC8W30hMHCmch3q4jtZcASLpy 5pWbakMdPETGy22QjR0dHI+B5vh0HK4zYPG6kps5g/vLVGGyyFNY8vTOhwmtn2N7QLX8qFwfvnA qxq+7a6w== X-Google-Smtp-Source: ABdhPJxfuGSzOkxpgHk8t3bi0Oe1yQRM2mVdHqmXNlj5gCvOlk0WVQNJn5I7m68S1r8zNz5Zy2+4BQ== X-Received: by 2002:a63:5d13:: with SMTP id r19mr4162392pgb.379.1620894824852; Thu, 13 May 2021 01:33:44 -0700 (PDT) Received: from drv-bst-rhel8.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id i123sm1632468pfc.53.2021.05.13.01.33.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 May 2021 01:33:44 -0700 (PDT) From: Kashyap Desai To: linux-scsi@vger.kernel.org Cc: jejb@linux.ibm.com, martin.petersen@oracle.com, steve.hagan@broadcom.com, peter.rivera@broadcom.com, mpi3mr-linuxdrv.pdl@broadcom.com, Kashyap Desai , sathya.prakash@broadcom.com Subject: [PATCH v5 21/24] mpi3mr: add support of PM suspend and resume Date: Thu, 13 May 2021 14:06:05 +0530 Message-Id: <20210513083608.2243297-22-kashyap.desai@broadcom.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20210513083608.2243297-1-kashyap.desai@broadcom.com> References: <20210513083608.2243297-1-kashyap.desai@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Signed-off-by: Kashyap Desai Reviewed-by: Hannes Reinecke Reviewed-by: Tomas Henzl Reviewed-by: Himanshu Madhani Cc: sathya.prakash@broadcom.com --- drivers/scsi/mpi3mr/mpi3mr_os.c | 84 +++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/drivers/scsi/mpi3mr/mpi3mr_os.c b/drivers/scsi/mpi3mr/mpi3mr_os.c index 022356a1cd01..2f494bc8ea0d 100644 --- a/drivers/scsi/mpi3mr/mpi3mr_os.c +++ b/drivers/scsi/mpi3mr/mpi3mr_os.c @@ -3398,6 +3398,86 @@ static void mpi3mr_shutdown(struct pci_dev *pdev) mpi3mr_cleanup_ioc(mrioc, 0); } +#ifdef CONFIG_PM +/** + * mpi3mr_suspend - PCI power management suspend callback + * @pdev: PCI device instance + * @state: New power state + * + * Change the power state to the given value and cleanup the IOC + * by issuing MUR and shutdown notification + * + * Return: 0 always. + */ +static int mpi3mr_suspend(struct pci_dev *pdev, pm_message_t state) +{ + struct Scsi_Host *shost = pci_get_drvdata(pdev); + struct mpi3mr_ioc *mrioc; + pci_power_t device_state; + + if (!shost) + return 0; + + mrioc = shost_priv(shost); + while (mrioc->reset_in_progress || mrioc->is_driver_loading) + ssleep(1); + mrioc->stop_drv_processing = 1; + mpi3mr_cleanup_fwevt_list(mrioc); + scsi_block_requests(shost); + mpi3mr_stop_watchdog(mrioc); + mpi3mr_cleanup_ioc(mrioc, 1); + + device_state = pci_choose_state(pdev, state); + ioc_info(mrioc, "pdev=0x%p, slot=%s, entering operating state [D%d]\n", + pdev, pci_name(pdev), device_state); + pci_save_state(pdev); + pci_set_power_state(pdev, device_state); + mpi3mr_cleanup_resources(mrioc); + + return 0; +} + +/** + * mpi3mr_resume - PCI power management resume callback + * @pdev: PCI device instance + * + * Restore the power state to D0 and reinitialize the controller + * and resume I/O operations to the target devices + * + * Return: 0 on success, non-zero on failure + */ +static int mpi3mr_resume(struct pci_dev *pdev) +{ + struct Scsi_Host *shost = pci_get_drvdata(pdev); + struct mpi3mr_ioc *mrioc; + pci_power_t device_state = pdev->current_state; + int r; + + mrioc = shost_priv(shost); + + ioc_info(mrioc, "pdev=0x%p, slot=%s, previous operating state [D%d]\n", + pdev, pci_name(pdev), device_state); + pci_set_power_state(pdev, PCI_D0); + pci_enable_wake(pdev, PCI_D0, 0); + pci_restore_state(pdev); + mrioc->pdev = pdev; + mrioc->cpu_count = num_online_cpus(); + r = mpi3mr_setup_resources(mrioc); + if (r) { + ioc_info(mrioc, "%s: Setup resources failed[%d]\n", + __func__, r); + return r; + } + + mrioc->stop_drv_processing = 0; + mpi3mr_init_ioc(mrioc, 1); + scsi_unblock_requests(shost); + mpi3mr_start_watchdog(mrioc); + + return 0; +} +#endif + static const struct pci_device_id mpi3mr_pci_id_table[] = { { PCI_DEVICE_SUB(PCI_VENDOR_ID_LSI_LOGIC, 0x00A5, @@ -3413,6 +3493,10 @@ static struct pci_driver mpi3mr_pci_driver = { .probe = mpi3mr_probe, .remove = mpi3mr_remove, .shutdown = mpi3mr_shutdown, +#ifdef CONFIG_PM + .suspend = mpi3mr_suspend, + .resume = mpi3mr_resume, +#endif }; static int __init mpi3mr_init(void)