Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp3438825pxx; Mon, 2 Nov 2020 08:55:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJwqDSwklwGZEC/CuzQ65XOWISKYP4BNTeR9gf1ok4a60cYzVO1NaIFWHk+AvNsptjetIvSn X-Received: by 2002:a17:906:51dd:: with SMTP id v29mr16363385ejk.69.1604336147411; Mon, 02 Nov 2020 08:55:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604336147; cv=none; d=google.com; s=arc-20160816; b=EAiylPKjL5YhXyL5UQqSM1U58AkfZEZ6cZ48w/gJJrLAjY3k/cTxzNasuY8I7OeE3B Raeuz5Gzglw/Fnzu7iFgGCwYyAMdooJmEzdqPIGI6MgR+IpPKhgr8MY13GjRVV9FcI/N gPEsa6X68FCfNXgjS40yZ0O9eO0CBMXxcjWTmpTgHBaG6RrHb2RuUKEKyhmJdIXDdLpo mh03bfdd8FO9jWQf13jZoPxEE5snO8uYcJ19Jm8ZwEBLv3GmfFW+sfn6hsurpPWwBAjR ATgW4WfV0WEfVYyEpFwtOgXEjp3glh+JRdJEC2FOFL5Um7l8k26j8tbirnx2BIqOt+AE OECg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WUBvgbl6iGKCFFzOFeem+Ak5qZZi8vOAFv31Ry1s8Ag=; b=y3jmrI+23U7gzL2zakLlmCCvgeYg5U+KIc+5OLlPxK2lnBtcaxMDDB9W6hwTBWKEt+ SF2GrhH5yFo8D89ffl8ytYaCQ0xf/8Ock/JbvEkBR/WjkQCiIPfnsilEvVbs5Q0BcAj/ 6OwwdAjxN06iQSG/KoEGMwe+oElrJo9i+CSzJWJmNQ8CfF60vPp2/72CddAtKq2X5Ncl OPaT5SN2JZAJzbn+J8QOu06Hunxeazg12n/b/dokT/EF8P2nhbsDMFpdd7fbGN3v0fVn pqMDr3YpuyG3EakED7JvacfVU6o9vRMbzRfapsaTSuPM0nQYMDnKCdQE10uUNeTihp/3 UCow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qeGq4sy0; 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 h90si11688749edd.326.2020.11.02.08.55.23; Mon, 02 Nov 2020 08:55:47 -0800 (PST) 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=qeGq4sy0; 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 S1727429AbgKBQwh (ORCPT + 99 others); Mon, 2 Nov 2020 11:52:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726913AbgKBQwg (ORCPT ); Mon, 2 Nov 2020 11:52:36 -0500 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5F74C0617A6; Mon, 2 Nov 2020 08:52:35 -0800 (PST) Received: by mail-pg1-x542.google.com with SMTP id i26so11278254pgl.5; Mon, 02 Nov 2020 08:52:35 -0800 (PST) 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=WUBvgbl6iGKCFFzOFeem+Ak5qZZi8vOAFv31Ry1s8Ag=; b=qeGq4sy0Twb2LAXIoCUbswcwn5ARIZjtbvsgY+oMv6tpsKJBflcN0heggKOvGtAqlF 5lWH8QI0yCIRswe3y9aFtE4ifNs/DVlApOrcyVqC+BWmQvc3TF2UsKcW2AvIOOf2Q5Xp eYffTtiEej9hzNYv+Ao6e5/9+dOMgx3vPfbwOh+YLptr1r/Zc88Yhm68bvLv4bNzolZ7 2pISvCLddMw9n0rFCiEzmY5pEMguW+KZ2mqsL0Poev7+GgE8Av4S/6rbZKZGxl4O5S0S CUlraZ6y34Q6SjK0QqTBWFJ18eEmU2626VUSvimPY1VA8lXybPhbRpHTHa7JCe8zQNHm 3Avw== 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=WUBvgbl6iGKCFFzOFeem+Ak5qZZi8vOAFv31Ry1s8Ag=; b=ianSS/mVTn5iZYF4mzv7P5UeURgWAyYQ22eQviFob9nxWSKvPUVVuZU3TNHe/Ymdm1 wL4rhgXIt9a6sJ3ir12I5sSG1Ovcdod4WgY8r0OSWbg9bMJNlzvuQCTvJzwgn1zdSLxa vbyBLLQ9ibyY3FF1p9wNMcvUWS1hCelLvxoHVABCfb1eFUTTaZku5N9Q2ythhoCfanuk Ct3hweVFQI8Cds4QOd4UUefKk0u35KpjZm9p3SwJIiEy3USzdpRt8yYqbDByqnxtWn6I KofVad6UZwyBoVRTATYswCe56daRFUivcnblyNwD0Njp2yVrY+EV+4lTyTJYN3Idv0g1 1lNA== X-Gm-Message-State: AOAM532yVmbLXmj/CWoGAXzprvzCrtFahXBTxgWOXPl4/mVKRWxXGV7t IbCLeK1SA+OPSpdKc2Abay0= X-Received: by 2002:a05:6a00:2cf:b029:160:c0c:a95c with SMTP id b15-20020a056a0002cfb02901600c0ca95cmr21990295pft.76.1604335955469; Mon, 02 Nov 2020 08:52:35 -0800 (PST) Received: from varodek.localdomain ([223.179.149.110]) by smtp.gmail.com with ESMTPSA id t74sm4953233pfc.47.2020.11.02.08.52.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 08:52:34 -0800 (PST) From: Vaibhav Gupta To: Bjorn Helgaas , Bjorn Helgaas , Bjorn Helgaas , Vaibhav Gupta , Adam Radford , "James E.J. Bottomley" , "Martin K. Petersen" , Adaptec OEM Raid Solutions , Hannes Reinecke , Bradley Grove , John Garry , Don Brace , Xiang Chen , James Smart , Dick Kennedy , Kashyap Desai , Sumit Saxena , Shivasharan S , Sathya Prakash , Sreekanth Reddy , Suganath Prabu Subramani , Jack Wang , Balsundar P Cc: Vaibhav Gupta , Shuah Khan , linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, linux-scsi@vger.kernel.org, esc.storagedev@microsemi.com, megaraidlinux.pdl@broadcom.com, MPT-FusionLinux.pdl@broadcom.com Subject: [PATCH v4 11/29] scsi: esas2r: use generic power management Date: Mon, 2 Nov 2020 22:17:12 +0530 Message-Id: <20201102164730.324035-12-vaibhavgupta40@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201102164730.324035-1-vaibhavgupta40@gmail.com> References: <20201102164730.324035-1-vaibhavgupta40@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Drivers should do only device-specific jobs. But in general, drivers using legacy PCI PM framework for .suspend()/.resume() have to manage many PCI PM-related tasks themselves which can be done by PCI Core itself. This brings extra load on the driver and it directly calls PCI helper functions to handle them. Switch to the new generic framework by updating function signatures and define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove unnecessary calls to the PCI Helper functions along with the legacy .suspend & .resume bindings. Signed-off-by: Vaibhav Gupta --- drivers/scsi/esas2r/esas2r.h | 5 ++-- drivers/scsi/esas2r/esas2r_init.c | 44 +++++++++---------------------- drivers/scsi/esas2r/esas2r_main.c | 3 +-- 3 files changed, 16 insertions(+), 36 deletions(-) diff --git a/drivers/scsi/esas2r/esas2r.h b/drivers/scsi/esas2r/esas2r.h index e30d2f1f5368..ed63f7a9ea54 100644 --- a/drivers/scsi/esas2r/esas2r.h +++ b/drivers/scsi/esas2r/esas2r.h @@ -996,8 +996,9 @@ void esas2r_adapter_tasklet(unsigned long context); irqreturn_t esas2r_interrupt(int irq, void *dev_id); irqreturn_t esas2r_msi_interrupt(int irq, void *dev_id); void esas2r_kickoff_timer(struct esas2r_adapter *a); -int esas2r_suspend(struct pci_dev *pcid, pm_message_t state); -int esas2r_resume(struct pci_dev *pcid); + +extern const struct dev_pm_ops esas2r_pm_ops; + void esas2r_fw_event_off(struct esas2r_adapter *a); void esas2r_fw_event_on(struct esas2r_adapter *a); bool esas2r_nvram_write(struct esas2r_adapter *a, struct esas2r_request *rq, diff --git a/drivers/scsi/esas2r/esas2r_init.c b/drivers/scsi/esas2r/esas2r_init.c index 905a6c874789..eb7763af7089 100644 --- a/drivers/scsi/esas2r/esas2r_init.c +++ b/drivers/scsi/esas2r/esas2r_init.c @@ -640,49 +640,27 @@ void esas2r_kill_adapter(int i) } } -int esas2r_suspend(struct pci_dev *pdev, pm_message_t state) +static int __maybe_unused esas2r_suspend(struct device *dev) { - struct Scsi_Host *host = pci_get_drvdata(pdev); - u32 device_state; + struct Scsi_Host *host = dev_get_drvdata(dev); struct esas2r_adapter *a = (struct esas2r_adapter *)host->hostdata; - esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev), "suspending adapter()"); + esas2r_log_dev(ESAS2R_LOG_INFO, dev, "suspending adapter()"); if (!a) return -ENODEV; esas2r_adapter_power_down(a, 1); - device_state = pci_choose_state(pdev, state); - esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev), - "pci_save_state() called"); - pci_save_state(pdev); - esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev), - "pci_disable_device() called"); - pci_disable_device(pdev); - esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev), - "pci_set_power_state() called"); - pci_set_power_state(pdev, device_state); - esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev), "esas2r_suspend(): 0"); + esas2r_log_dev(ESAS2R_LOG_INFO, dev, "esas2r_suspend(): 0"); return 0; } -int esas2r_resume(struct pci_dev *pdev) +static int __maybe_unused esas2r_resume(struct device *dev) { - struct Scsi_Host *host = pci_get_drvdata(pdev); + struct Scsi_Host *host = dev_get_drvdata(dev); struct esas2r_adapter *a = (struct esas2r_adapter *)host->hostdata; - int rez; - - esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev), "resuming adapter()"); - esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev), - "pci_set_power_state(PCI_D0) " - "called"); - pci_set_power_state(pdev, PCI_D0); - esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev), - "pci_restore_state() called"); - pci_restore_state(pdev); - esas2r_log_dev(ESAS2R_LOG_INFO, &(pdev->dev), - "pci_enable_device() called"); - rez = pci_enable_device(pdev); - pci_set_master(pdev); + int rez = 0; + + esas2r_log_dev(ESAS2R_LOG_INFO, dev, "resuming adapter()"); if (!a) { rez = -ENODEV; @@ -726,11 +704,13 @@ int esas2r_resume(struct pci_dev *pdev) } error_exit: - esas2r_log_dev(ESAS2R_LOG_CRIT, &(pdev->dev), "esas2r_resume(): %d", + esas2r_log_dev(ESAS2R_LOG_CRIT, dev, "esas2r_resume(): %d", rez); return rez; } +SIMPLE_DEV_PM_OPS(esas2r_pm_ops, esas2r_suspend, esas2r_resume); + bool esas2r_set_degraded_mode(struct esas2r_adapter *a, char *error_str) { set_bit(AF_DEGRADED_MODE, &a->flags); diff --git a/drivers/scsi/esas2r/esas2r_main.c b/drivers/scsi/esas2r/esas2r_main.c index 7b49e2e9fcde..aab3ea580e6b 100644 --- a/drivers/scsi/esas2r/esas2r_main.c +++ b/drivers/scsi/esas2r/esas2r_main.c @@ -346,8 +346,7 @@ static struct pci_driver .id_table = esas2r_pci_table, .probe = esas2r_probe, .remove = esas2r_remove, - .suspend = esas2r_suspend, - .resume = esas2r_resume, + .driver.pm = &esas2r_pm_ops, }; static int esas2r_probe(struct pci_dev *pcid, -- 2.28.0