Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp82162rdb; Fri, 5 Jan 2024 03:35:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IFQOojn8st1KZZI6hEAxry5bbh0flKqWAITdu0rNiNHxHuLfzh0mzg36PdsKUswUgtUH68w X-Received: by 2002:aa7:d853:0:b0:556:ece8:559d with SMTP id f19-20020aa7d853000000b00556ece8559dmr1066014eds.80.1704454514643; Fri, 05 Jan 2024 03:35:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704454514; cv=none; d=google.com; s=arc-20160816; b=l2F7HCaO3CEgwTjBKZeDEnP06ga8bIOpz3jQ8HdZ8MGpstIPVQ2du6FjH6kY5CgHN+ Blze8RgPAV5vvejrzOTouADHgMAmWRjdCibwyC2nh0Y0+gbnrKaPFGT263bCE+xYEyLG znqvkK/Ygf5k426vweVyGSsO1h3bs1qGBNYIpuIuYxpaGuxmiVa97r0dljgKdFxDW6HW /PWVFPMOBW8Of2i08oN3XeqfxlR9ucjRndF6UHcurCRy0lLQW9yJZaO4oAy634sBlIAT Lkeu/QMKr1JsiWb0wiDA2rXFsBdr+BFVartC0BNknfgmR+YMfjRQr2ApfMpqAiO9dRo0 ZRww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=6jaKCgRgGGzCxN/P9G3gjdV4D0QDk0pe5GM1QCZjB1o=; fh=J4St9tMjBInT3r1VVHSF1O7f2qS3KxSaZBHCVggmRHk=; b=BVm6H2JJmrl4Ux3fvqJEW7CtbcOXC3zWd9d77gSLgAEaRYFDAno1KwqtnXHimKxBmf NTtctQPy2wr5PFGEQwRdongMuD5kE3FBNUvubAXmCF/r27Q0d8Zy8rfFMZ/FDT7gJwev +nrS/X2gZtXQb/cVgVktdHw9/g7zB9lun7uQf5YaenO6fQr7sGdtXxAHveNj/uTLYcim QuJQNAtPrrSRTy92GlD1Ifat7FuDTf77Dld3DUmo6jjIYjT/g+oREJJV5+O2yUWWewmI GNEMmMV/wJvoS+k0qwZatCiemRFhB4TMeZlbG7Zwn8SbTLialsgAK99AqHNfdas7qjyV +Tcw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17807-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17807-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id z1-20020a05640240c100b00556a9b61509si593241edb.77.2024.01.05.03.35.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 03:35:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17807-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-17807-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17807-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 394101F27956 for ; Fri, 5 Jan 2024 11:35:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8609B2D614; Fri, 5 Jan 2024 11:34:19 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C1B92C868; Fri, 5 Jan 2024 11:34:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=realtek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=realtek.com X-SpamFilter-By: ArmorX SpamTrap 5.78 with qID 405BY1ZV02341813, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36506.realtek.com.tw[172.21.6.27]) by rtits2.realtek.com.tw (8.15.2/2.95/5.92) with ESMTPS id 405BY1ZV02341813 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 5 Jan 2024 19:34:01 +0800 Received: from RTEXDAG02.realtek.com.tw (172.21.6.101) by RTEXH36506.realtek.com.tw (172.21.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.17; Fri, 5 Jan 2024 19:34:01 +0800 Received: from RTDOMAIN (172.21.210.160) by RTEXDAG02.realtek.com.tw (172.21.6.101) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Fri, 5 Jan 2024 19:34:01 +0800 From: Justin Lai To: CC: , , , , , , , , Justin Lai Subject: [PATCH net-next v16 09/13] rtase: Implement pci_driver suspend and resume function Date: Fri, 5 Jan 2024 19:32:53 +0800 Message-ID: <20240105113257.381090-5-justinlai0215@realtek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240105113257.381090-1-justinlai0215@realtek.com> References: <20240105112811.380952-1-justinlai0215@realtek.com> <20240105113257.381090-1-justinlai0215@realtek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: RTEXH36506.realtek.com.tw (172.21.6.27) To RTEXDAG02.realtek.com.tw (172.21.6.101) X-KSE-ServerInfo: RTEXDAG02.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback Implement the pci_driver suspend function to enable the device to sleep, and implement the resume function to enable the device to resume operation. Signed-off-by: Justin Lai --- .../net/ethernet/realtek/rtase/rtase_main.c | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/drivers/net/ethernet/realtek/rtase/rtase_main.c b/drivers/net/ethernet/realtek/rtase/rtase_main.c index 16fe3d8e3987..b8e5ef489b0c 100644 --- a/drivers/net/ethernet/realtek/rtase/rtase_main.c +++ b/drivers/net/ethernet/realtek/rtase/rtase_main.c @@ -2148,12 +2148,63 @@ static void rtase_shutdown(struct pci_dev *pdev) rtase_reset_interrupt(pdev, tp); } +static int rtase_suspend(struct device *device) +{ + struct net_device *dev = dev_get_drvdata(device); + + if (netif_running(dev)) { + netif_device_detach(dev); + rtase_hw_reset(dev); + } + + return 0; +} + +static int rtase_resume(struct device *device) +{ + struct net_device *dev = dev_get_drvdata(device); + struct rtase_private *tp = netdev_priv(dev); + int ret; + + /* restore last modified mac address */ + rtase_rar_set(tp, dev->dev_addr); + + if (!netif_running(dev)) + goto out; + + rtase_wait_for_quiescence(dev); + + rtase_tx_clear(tp); + rtase_rx_clear(tp); + + ret = rtase_init_ring(dev); + if (ret) { + netdev_err(dev, "unable to init ring\n"); + rtase_free_desc(tp); + return -ENOMEM; + } + + rtase_hw_config(dev); + /* always link, so start to transmit & receive */ + rtase_hw_start(dev); + + netif_device_attach(dev); +out: + + return 0; +} + +static const struct dev_pm_ops rtase_pm_ops = { + SYSTEM_SLEEP_PM_OPS(rtase_suspend, rtase_resume) +}; + static struct pci_driver rtase_pci_driver = { .name = KBUILD_MODNAME, .id_table = rtase_pci_tbl, .probe = rtase_init_one, .remove = rtase_remove_one, .shutdown = rtase_shutdown, + .driver.pm = pm_ptr(&rtase_pm_ops), }; module_pci_driver(rtase_pci_driver); -- 2.34.1