Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp602502ybt; Wed, 1 Jul 2020 06:04:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhg4UU6yQ4ijjyZJyAj+hBAmG1QQ3dtc1J1WYAD0+bR7bPxCeRNJoYTEYSV5JiF2Ifs2nZ X-Received: by 2002:aa7:d989:: with SMTP id u9mr11207652eds.85.1593608670072; Wed, 01 Jul 2020 06:04:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593608670; cv=none; d=google.com; s=arc-20160816; b=gvQiVzbKTMSPNivmwPFuBgXd/PuQg2iLY78EwwU9omWsUrT36/Vis9tmAV0gLMElp/ Js+3azgJ9aWu0XtvYrlxriEWTYxJkUMtDR3d/o4ppr8uvABhor4J+TafxXnfcrldng79 d5BhyOsynAmYt6FdWqPuGS8ywLzJEYIdPENZ92vvpAtwnM54uNOJh00lFk85aC9xrxwN CAqMpAFLrCzv16QM3YEqaS/uKBkBWziR34U1nV9wDKDQZBu96qsUrrnGG7ktyrpTZK1Q VYJfWfDHgFFBa5v1WvyD5ZvuCpUZ9ggk47IUuwa+E9OS1fWR9V6fVff3kbe0iNdcBmNS wD0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2OLtDqAl4GQ2i7cTj9ta2eBmWz0EGmYq4wIiRHp9/FE=; b=AFIP+lq6pEHePmcUsAq23g5ZkCrV4dLWlttyuQWE+WFUfWRx4mlaZRpDvLge2Pc3Id LAU5tGZh0qYgujfgpwM63Ew9xLh+ytvdzFncTknUKAHY4fdwaoyMfdPZ5wAnE59tdPIe oXqB+ZlT2ZhwReDDgp8jeN6IPXdycq6A6N1XWp4zsodjrjbXus+m/C7Cp3aQ3n2NytA7 Gnq4Kbq9xArY7y+IHOjX/ZhKxPD5bH0Nszq7QR1QZWu7AhgSJtWHaA6OHoQHbIL1W6eL Yi4OCdF/mGogpdLxN88aMXHkvI8TcW64CabO4Fp00neBFvsAwIyiKdRZ/DiL6NrOBHPh jStw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=E1v7YWBn; 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 dg12si3672447edb.81.2020.07.01.06.04.05; Wed, 01 Jul 2020 06:04:30 -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=E1v7YWBn; 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 S1730794AbgGANBg (ORCPT + 99 others); Wed, 1 Jul 2020 09:01:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730271AbgGANBf (ORCPT ); Wed, 1 Jul 2020 09:01:35 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F088C03E979; Wed, 1 Jul 2020 06:01:35 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id b92so11021604pjc.4; Wed, 01 Jul 2020 06:01:35 -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=2OLtDqAl4GQ2i7cTj9ta2eBmWz0EGmYq4wIiRHp9/FE=; b=E1v7YWBnZy/6D8OpTUzwkwr/HwxzEV2bD0PivosnKEP8vNMQ18ZyF5/DN+iiB8ZJ0z R1jtKjOfwTFc5KkQJfIRkRFWoFNAEyWs0QHabsAWYTacOFSEpKynq5XgeQNcZWTz6V6Y IWJWTq7jbnWGBh2wyg1t4XurPAdXJE+FtWOT09GtxUID8EhFotqerSHwXkQPk8umaREf 7BYLTVoi3Ama+5QeSK0ZFnKAbR9BkyTNaT6JANWVXLl12MjzdhDZ57Wcru2eQbHo0fGW 8Jpxi1juIN1vaUAhCcqHfCI/1Wm05Y6gTrg5FxDCiq9ePpnidLForpbC+x6+tOnp11C3 iz5g== 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=2OLtDqAl4GQ2i7cTj9ta2eBmWz0EGmYq4wIiRHp9/FE=; b=A3uEzM+QRHpsMbf6CnvCmAa83FWOjWTkFx9bAz/GKYm0xIne4PZWvcqJ1ALl6NmaIO 33VMh6VLig0aRO1wZ4DPjPPyidhoGlCDd/7ycIquSz4wyP5+ZvzzxnIr70eZpHcktwVv tlsTnAq0OKBsVKnt5ZgdqsfyLkNHvS/M6Ld3uwnhX4RyNxCH/Moj5ngVpU+pPDiac2SW LL4/NUfHgWJIWzM7eWQp3s6kA/Zu1yi7Rxf82y/l7E7m6so/vfqBrabOUwO7X/p+vDlV inGlTA+CH/P/Sf0GuQeq9Y6KD8eYqrmEKwAgTahWZQah6hdQzlKfxry4hmiVBV7YifUK nmeA== X-Gm-Message-State: AOAM533SdG/88bINZN1SHVJ29cJBYNj5t4dy3Zhj/8zssUbV5SMJaTS+ KowT4U/5cQ5WvwBvEkyjsEc= X-Received: by 2002:a17:90b:1491:: with SMTP id js17mr28856528pjb.118.1593608494762; Wed, 01 Jul 2020 06:01:34 -0700 (PDT) Received: from varodek.iballbatonwifi.com ([103.105.153.57]) by smtp.gmail.com with ESMTPSA id d9sm6070908pgv.45.2020.07.01.06.01.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2020 06:01:34 -0700 (PDT) From: Vaibhav Gupta To: Bjorn Helgaas , Bjorn Helgaas , bjorn@helgaas.com, Vaibhav Gupta , "David S. Miller" , Jakub Kicinski , David Dillow , Ion Badulescu , Netanel Belgazal , Arthur Kiyanovski , Guy Tzalik , Saeed Bishara , Zorik Machulsky , Derek Chickles , Satanand Burla , Felix Manlunas , Denis Kirjanov , Ajit Khaparde , Sriharsha Basavapatna , Somnath Kotur , Tariq Toukan , Jon Mason Cc: Vaibhav Gupta , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, skhan@linuxfoundation.org Subject: [PATCH v1 01/11] typhoon: use generic power management Date: Wed, 1 Jul 2020 18:29:28 +0530 Message-Id: <20200701125938.639447-2-vaibhavgupta40@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200701125938.639447-1-vaibhavgupta40@gmail.com> References: <20200701125938.639447-1-vaibhavgupta40@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With legacy PM, drivers themselves were responsible for managing the device's power states and takes care of register states. And they use PCI helper functions to do it. After upgrading to the generic structure, PCI core will take care of required tasks and drivers should do only device-specific operations. In this driver: typhoon_resume() calls typhoon_wakeup() which then calls PCI helper functions pci_set_power_state() and pci_restore_state(). The only other function, using typhoon_wakeup() is typhoon_open(). Thus remove the pci_*() calls from tyhpoon_wakeup() and place them in typhoon_open(), maintaining the order, to retain the normal behavior of the function Now, typhoon_suspend() calls typhoon_sleep() which then calls PCI helper functions pci_enable_wake(), pci_disable_device() and pci_set_power_state(). Other functions: - typhoon_open() - typhoon_close() - typhoon_init_one() are also invoking typhoon_sleep(). Thus, in this case, cannot simply move PCI helper functions call. Hence, define a new function typhoon_sleep_early() which will do all the operations, which typhoon_sleep() was doing before calling PCI helper functions. Now typhoon_sleep() will call typhoon_sleep_early() to do those tasks, hence, the behavior for _open(), _close and _init_one() remain unchanged. And typhon_suspend() only requires typhoon_sleep_early(). Compile-tested only. Signed-off-by: Vaibhav Gupta --- drivers/net/ethernet/3com/typhoon.c | 53 +++++++++++++++++------------ 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/drivers/net/ethernet/3com/typhoon.c b/drivers/net/ethernet/3com/typhoon.c index 5ed33c2c4742..d3b30bacc94e 100644 --- a/drivers/net/ethernet/3com/typhoon.c +++ b/drivers/net/ethernet/3com/typhoon.c @@ -1801,9 +1801,8 @@ typhoon_free_rx_rings(struct typhoon *tp) } static int -typhoon_sleep(struct typhoon *tp, pci_power_t state, __le16 events) +typhoon_sleep_early(struct typhoon *tp, __le16 events) { - struct pci_dev *pdev = tp->pdev; void __iomem *ioaddr = tp->ioaddr; struct cmd_desc xp_cmd; int err; @@ -1832,20 +1831,29 @@ typhoon_sleep(struct typhoon *tp, pci_power_t state, __le16 events) */ netif_carrier_off(tp->dev); + return 0; +} + +static int +typhoon_sleep(struct typhoon *tp, pci_power_t state, __le16 events) +{ + int err; + + err = typhoon_sleep_early(tp, events); + + if (err) + return err; + pci_enable_wake(tp->pdev, state, 1); - pci_disable_device(pdev); - return pci_set_power_state(pdev, state); + pci_disable_device(tp->pdev); + return pci_set_power_state(tp->pdev, state); } static int typhoon_wakeup(struct typhoon *tp, int wait_type) { - struct pci_dev *pdev = tp->pdev; void __iomem *ioaddr = tp->ioaddr; - pci_set_power_state(pdev, PCI_D0); - pci_restore_state(pdev); - /* Post 2.x.x versions of the Sleep Image require a reset before * we can download the Runtime Image. But let's not make users of * the old firmware pay for the reset. @@ -2049,6 +2057,9 @@ typhoon_open(struct net_device *dev) if (err) goto out; + pci_set_power_state(tp->pdev, PCI_D0); + pci_restore_state(tp->pdev); + err = typhoon_wakeup(tp, WaitSleep); if (err < 0) { netdev_err(dev, "unable to wakeup device\n"); @@ -2114,11 +2125,10 @@ typhoon_close(struct net_device *dev) return 0; } -#ifdef CONFIG_PM -static int -typhoon_resume(struct pci_dev *pdev) +static int __maybe_unused +typhoon_resume(struct device *dev_d) { - struct net_device *dev = pci_get_drvdata(pdev); + struct net_device *dev = dev_get_drvdata(dev_d); struct typhoon *tp = netdev_priv(dev); /* If we're down, resume when we are upped. @@ -2144,9 +2154,10 @@ typhoon_resume(struct pci_dev *pdev) return -EBUSY; } -static int -typhoon_suspend(struct pci_dev *pdev, pm_message_t state) +static int __maybe_unused +typhoon_suspend(struct device *dev_d) { + struct pci_dev *pdev = to_pci_dev(dev_d); struct net_device *dev = pci_get_drvdata(pdev); struct typhoon *tp = netdev_priv(dev); struct cmd_desc xp_cmd; @@ -2190,18 +2201,19 @@ typhoon_suspend(struct pci_dev *pdev, pm_message_t state) goto need_resume; } - if (typhoon_sleep(tp, pci_choose_state(pdev, state), tp->wol_events) < 0) { + if (typhoon_sleep_early(tp, tp->wol_events) < 0) { netdev_err(dev, "unable to put card to sleep\n"); goto need_resume; } + device_wakeup_enable(dev_d); + return 0; need_resume: - typhoon_resume(pdev); + typhoon_resume(dev_d); return -EBUSY; } -#endif static int typhoon_test_mmio(struct pci_dev *pdev) @@ -2533,15 +2545,14 @@ typhoon_remove_one(struct pci_dev *pdev) free_netdev(dev); } +static SIMPLE_DEV_PM_OPS(typhoon_pm_ops, typhoon_suspend, typhoon_resume); + static struct pci_driver typhoon_driver = { .name = KBUILD_MODNAME, .id_table = typhoon_pci_tbl, .probe = typhoon_init_one, .remove = typhoon_remove_one, -#ifdef CONFIG_PM - .suspend = typhoon_suspend, - .resume = typhoon_resume, -#endif + .driver.pm = &typhoon_pm_ops, }; static int __init -- 2.27.0