Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1062624pxj; Wed, 2 Jun 2021 19:55:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzcOODkICBPliL4Qj0qTCW7S0WayUSBI5BE9aZHU6Cm8Et81ujIxfwo9iMDMZwIYe/hnzT X-Received: by 2002:a17:906:76c6:: with SMTP id q6mr37162614ejn.387.1622688935374; Wed, 02 Jun 2021 19:55:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622688935; cv=none; d=google.com; s=arc-20160816; b=zqF4+i5Fw3dPDlbea5aS/009spHuK+wEW8d88NmLudSyKU33dI2sx2VyJMrNDZlI4g EjAK+6faRdxN5s7Yn5YkPWzqWJVYa3tFZKN5AKDrvPp+Cg/gcvEQgFvJ9NLQ8l31VPMI ESRcit1ap8jUJL3rRoB7aEevd+r2JfFa+6bbMZgtEZT3P6cd1lSL/y4lVtWLn3VK4c/n PMHB5OTeWLUDxSfxMl4YyRrOfhMFm9EciR4/iKB1X58RDdQDz+NXj+dJkzKX1GOJHQPZ fUaqXFKqQkKBFXAHi/PaEVCMRft6zS46/eIY71r9c7xzpSGnVmzTD/26OxUC/EvDTFK8 GF5Q== 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 :message-id:date:subject:to:from; bh=Mw+siqoTUjrd2Ed54WevdVgzIPvaVKMKX23ULyv1JWs=; b=YH2we3lxWXBEVDKq9q1Pc5qskgmJlypuxJBNJmwea1g/NcXa4d5W/+g75Vkz4/Z91s McOI3JPIMh1hEu4oVySaHmZ4TjYry5ZqYCV70UlVqEdQCEJ3IWaJCUr7juJqRqWOkaHN 7FlT6+ll1rrkF4icc3plRtjTyw8JWJIXay+c9bDdmoiy1WQ0s7y0VfhMk1ztF9QDdNNE EOhVsUCcJVrMSrodPj1dLRspFbGPBHXx5GBED9ppb65v3L08CEGCOLblz2tfiGEZBQWx 7MeEDh/wt/j6Cx/OKm/fjxV92d0QO+LDrtE68eWAiPDRzQqGycx8J4veng1XtedzkDrr xNBQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t14si1227126ejb.624.2021.06.02.19.55.12; Wed, 02 Jun 2021 19:55:35 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229719AbhFCC4D (ORCPT + 99 others); Wed, 2 Jun 2021 22:56:03 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:49582 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229541AbhFCC4D (ORCPT ); Wed, 2 Jun 2021 22:56:03 -0400 Received: from mail-pl1-f197.google.com ([209.85.214.197]) by youngberry.canonical.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1lodUw-0004Up-Dk for linux-kernel@vger.kernel.org; Thu, 03 Jun 2021 02:54:18 +0000 Received: by mail-pl1-f197.google.com with SMTP id 37-20020a1709020328b02900f916f1d504so1987488pld.1 for ; Wed, 02 Jun 2021 19:54:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=Mw+siqoTUjrd2Ed54WevdVgzIPvaVKMKX23ULyv1JWs=; b=iOE0mAcj9KtRMUK6xx15VayvsZFNjfhyNsveFNKf7ExmrOgckf/nqs/cZdRWzg1HFT thic+RbKaADcMnzDB53Xrx3YO2zx+WcvYjtCo4r7kCTU/dZ5xqMQMUYdH9vQxgGHLKRG FjHgq0zH8v7bsyVpgPcGIQXRranbW2P6rSrRkFKEvh7vBz+RFR9GYE2s47WrlJOBXyxA inMI5ezQJw9ZWHBOb/m2znzgTmfl5t14FY46hE2IX6tcKdPxR4sodERSYJozkzrQ5k/X 7/Jjz7WvV5dzrAAAHFTwXAyROIwhQs5NwoGo5fRHbNpsoNSMzbZ8K4BYSgtlICnCPUpp ye+Q== X-Gm-Message-State: AOAM532bX7C77AOlzZz1TVZKcUQ5vOIAbTKlVrRZyNfQVnK/WpbKNCat a/7qd4UhFA99CT3BDOLm/2pU69+uZAtpviQOfPfoWPU3Mi8nzCBuAfJGcMxgB/rZJHbkAdqIcpc gTh5pH95OM4+EyP+NJSgpOAOxPJVdrgYBbF64L2YQDA== X-Received: by 2002:a17:90b:3587:: with SMTP id mm7mr32577906pjb.71.1622688856955; Wed, 02 Jun 2021 19:54:16 -0700 (PDT) X-Received: by 2002:a17:90b:3587:: with SMTP id mm7mr32577880pjb.71.1622688856593; Wed, 02 Jun 2021 19:54:16 -0700 (PDT) Received: from canonical.com (61-220-137-34.HINET-IP.hinet.net. [61.220.137.34]) by smtp.gmail.com with ESMTPSA id o24sm942570pgl.55.2021.06.02.19.54.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jun 2021 19:54:16 -0700 (PDT) From: Koba Ko To: "David S. Miller" , Jakub Kicinski , Heiner Kallweit , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] r8169: introduce polling method for link change Date: Thu, 3 Jun 2021 10:54:14 +0800 Message-Id: <20210603025414.226526-1-koba.ko@canonical.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For RTL8106E, it's a Fast-ethernet chip. If ASPM is enabled, the link chang interrupt wouldn't be triggered immediately and must wait a very long time to get link change interrupt. Even the link change interrupt isn't triggered, the phy link is already established. Introduce a polling method to watch the status of phy link and disable the link change interrupt. Also add a quirk for those realtek devices have the same issue. Signed-off-by: Koba Ko --- drivers/net/ethernet/realtek/r8169.h | 2 + drivers/net/ethernet/realtek/r8169_main.c | 112 ++++++++++++++++++---- 2 files changed, 98 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/realtek/r8169.h b/drivers/net/ethernet/realtek/r8169.h index 2728df46ec41..a8c71adb1b57 100644 --- a/drivers/net/ethernet/realtek/r8169.h +++ b/drivers/net/ethernet/realtek/r8169.h @@ -11,6 +11,8 @@ #include #include +#define RTL8169_LINK_TIMEOUT (1 * HZ) + enum mac_version { /* support for ancient RTL_GIGA_MAC_VER_01 has been removed */ RTL_GIGA_MAC_VER_02, diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c index 2c89cde7da1e..70aacc83d641 100644 --- a/drivers/net/ethernet/realtek/r8169_main.c +++ b/drivers/net/ethernet/realtek/r8169_main.c @@ -178,6 +178,11 @@ static const struct pci_device_id rtl8169_pci_tbl[] = { MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl); +static const struct pci_device_id rtl8169_linkChg_polling_enabled[] = { + { PCI_VDEVICE(REALTEK, 0x8136), RTL_CFG_NO_GBIT }, + { 0 } +}; + enum rtl_registers { MAC0 = 0, /* Ethernet hardware address. */ MAC4 = 4, @@ -618,6 +623,7 @@ struct rtl8169_private { u16 cp_cmd; u32 irq_mask; struct clk *clk; + struct timer_list link_timer; struct { DECLARE_BITMAP(flags, RTL_FLAG_MAX); @@ -1179,6 +1185,16 @@ static void rtl8168ep_stop_cmac(struct rtl8169_private *tp) RTL_W8(tp, IBCR0, RTL_R8(tp, IBCR0) & ~0x01); } +static int rtl_link_chng_polling_quirk(struct rtl8169_private *tp) +{ + struct pci_dev *pdev = tp->pci_dev; + + if (pdev->vendor == 0x10ec && pdev->device == 0x8136 && !tp->supports_gmii) + return 1; + + return 0; +} + static void rtl8168dp_driver_start(struct rtl8169_private *tp) { r8168dp_oob_notify(tp, OOB_CMD_DRIVER_START); @@ -4608,6 +4624,75 @@ static void rtl_task(struct work_struct *work) rtnl_unlock(); } +static void r8169_phylink_handler(struct net_device *ndev) +{ + struct rtl8169_private *tp = netdev_priv(ndev); + + if (netif_carrier_ok(ndev)) { + rtl_link_chg_patch(tp); + pm_request_resume(&tp->pci_dev->dev); + } else { + pm_runtime_idle(&tp->pci_dev->dev); + } + + if (net_ratelimit()) + phy_print_status(tp->phydev); +} + +static unsigned int +rtl8169_xmii_link_ok(struct net_device *dev) +{ + struct rtl8169_private *tp = netdev_priv(dev); + unsigned int retval; + + retval = (RTL_R8(tp, PHYstatus) & LinkStatus) ? 1 : 0; + + return retval; +} + +static void +rtl8169_check_link_status(struct net_device *dev) +{ + struct rtl8169_private *tp = netdev_priv(dev); + int link_status_on; + + link_status_on = rtl8169_xmii_link_ok(dev); + + if (netif_carrier_ok(dev) == link_status_on) + return; + + phy_mac_interrupt(tp->phydev); + + r8169_phylink_handler (dev); +} + +static void rtl8169_link_timer(struct timer_list *t) +{ + struct rtl8169_private *tp = from_timer(tp, t, link_timer); + struct net_device *dev = tp->dev; + struct timer_list *timer = t; + unsigned long flags; + + rtl8169_check_link_status(dev); + + if (timer_pending(&tp->link_timer)) + return; + + mod_timer(timer, jiffies + RTL8169_LINK_TIMEOUT); +} + +static inline void rtl8169_delete_link_timer(struct net_device *dev, struct timer_list *timer) +{ + del_timer_sync(timer); +} + +static inline void rtl8169_request_link_timer(struct net_device *dev) +{ + struct rtl8169_private *tp = netdev_priv(dev); + + timer_setup(&tp->link_timer, rtl8169_link_timer, TIMER_INIT_FLAGS); +} + static int rtl8169_poll(struct napi_struct *napi, int budget) { struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); @@ -4624,21 +4709,6 @@ static int rtl8169_poll(struct napi_struct *napi, int budget) return work_done; } -static void r8169_phylink_handler(struct net_device *ndev) -{ - struct rtl8169_private *tp = netdev_priv(ndev); - - if (netif_carrier_ok(ndev)) { - rtl_link_chg_patch(tp); - pm_request_resume(&tp->pci_dev->dev); - } else { - pm_runtime_idle(&tp->pci_dev->dev); - } - - if (net_ratelimit()) - phy_print_status(tp->phydev); -} - static int r8169_phy_connect(struct rtl8169_private *tp) { struct phy_device *phydev = tp->phydev; @@ -4769,6 +4839,10 @@ static int rtl_open(struct net_device *dev) goto err_free_irq; rtl8169_up(tp); + + if (rtl_link_chng_polling_quirk(tp)) + mod_timer(&tp->link_timer, jiffies + RTL8169_LINK_TIMEOUT); + rtl8169_init_counter_offsets(tp); netif_start_queue(dev); out: @@ -4991,7 +5065,10 @@ static const struct net_device_ops rtl_netdev_ops = { static void rtl_set_irq_mask(struct rtl8169_private *tp) { - tp->irq_mask = RxOK | RxErr | TxOK | TxErr | LinkChg; + tp->irq_mask = RxOK | RxErr | TxOK | TxErr; + + if (!rtl_link_chng_polling_quirk(tp)) + tp->irq_mask |= LinkChg; if (tp->mac_version <= RTL_GIGA_MAC_VER_06) tp->irq_mask |= SYSErr | RxOverflow | RxFIFOOver; @@ -5436,6 +5513,9 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) if (pci_dev_run_wake(pdev)) pm_runtime_put_sync(&pdev->dev); + if (rtl_link_chng_polling_quirk(tp)) + rtl8169_request_link_timer(dev); + return 0; } -- 2.25.1