From patchwork Sat Feb 24 15:53:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 877434 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="AfIkaduL"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zpXgh2Wsqz9ry1 for ; Sun, 25 Feb 2018 02:53:36 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751426AbeBXPxd (ORCPT ); Sat, 24 Feb 2018 10:53:33 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:41572 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751364AbeBXPxb (ORCPT ); Sat, 24 Feb 2018 10:53:31 -0500 Received: by mail-wr0-f196.google.com with SMTP id f14so16935365wre.8 for ; Sat, 24 Feb 2018 07:53:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=6LrOAKS7qRBqv+UELxCAjAC8vHKTqv1S3NGS1MXJsDc=; b=AfIkaduL/WysIrYHyd6s1nDHyzFwkUJlwBDaz9GygEWfY2ICk94C5+KL1t52C6h9lL zFxlsCqJCKS2vE70WRJbCn/pIpx0kz/FdznsOZ9A63cBSK2/3VOt+QqzNHlkApeMlKTY uydX+B+lgKthmZU6aQGs52VSwTJpygOZesy/YJ+ZelgD2ecQtpUnAUuwiJA/73Szt+qc dMIo8mkvVlzx5qxFhhpkeJ4PmPb5j3voRIxoYOQq8Q8ze//S6zOpQcAIFAkxLBC+EdU/ ULdnb1wiCPn/l7M13O8OEsvGAjMXmwW313DeATOsiEorPzWdFSfJZmsWI4MwQgqTmXcl q5DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=6LrOAKS7qRBqv+UELxCAjAC8vHKTqv1S3NGS1MXJsDc=; b=RVRBlpUaY5jRjKYJlzt1Qm0I+jUi+Kbil06KCSX+afZuqHKZYp1lePFUcelWgVot3o 6f30id4RYWzXZrQTwGwmNfRsQ6WzHQxN3QpoJpEEor9QRgux8u3j6Oqz/tok0cZhGPHk 1I4OtMLld7nQv/rzJzyN2f8qj4D1rpNlwGIcKq1gl/MxCiIIBw9fc8nMURFMsYVN58LD 9eQjmhezOqMYmSCI9sN6PEB+yZKX9Z04DEMCBIVmchNpH7hcnks0DV5V9dlnpg2SuUV0 T0wYv0yfeM6PFGCMdvBnf2h0rgOjFWn+/OxZPqL00Vuc1uIXTyrwNIcnd+KhzqiIOCWH dGKA== X-Gm-Message-State: APf1xPBFL46BCMnLj81K41XpKVBoPJohcc3kf3asLHWYiX4fL4HcwI5z X7QUlQdCepVs1BE0Ly2k+fpgBQ== X-Google-Smtp-Source: AH8x2249iTq0hg1RAYRtD6GAWjAXNxLYj+BOOfsnlzBfgoD6/CQ00CXoZeRkthuZXEixIkPGwL23sA== X-Received: by 10.223.145.67 with SMTP id j61mr5000486wrj.152.1519487610344; Sat, 24 Feb 2018 07:53:30 -0800 (PST) Received: from ?IPv6:2003:ea:8bcd:3800:7150:4627:358f:aad0? (p200300EA8BCD380071504627358FAAD0.dip0.t-ipconnect.de. [2003:ea:8bcd:3800:7150:4627:358f:aad0]) by smtp.googlemail.com with ESMTPSA id w31sm5971382wrc.49.2018.02.24.07.53.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 24 Feb 2018 07:53:29 -0800 (PST) From: Heiner Kallweit Subject: [PATCH net-next v2] r8169: improve interrupt handling To: Realtek linux nic maintainers , David Miller , Francois Romieu Cc: "netdev@vger.kernel.org" Message-ID: <7f1cbc71-9d2d-627f-9e0e-b7e7b1f6ce9b@gmail.com> Date: Sat, 24 Feb 2018 16:53:23 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch improves few aspects of interrupt handling: - update to current interrupt allocation API (use pci_alloc_irq_vectors() instead of deprecated pci_enable_msi()) - this implicitly will allocate a MSI-X interrupt if available - get rid of flag RTL_FEATURE_MSI - remove some dead code, intentionally disabling (unreliable) MSI being partially available on old PCI chips. The patch works fine on a RTL8168evl (chip version 34) and on a RTL8169SB (chip version 04). Signed-off-by: Heiner Kallweit --- v2: - disable MSI on old PCI chips even if they partially support it - improve error handling --- drivers/net/ethernet/realtek/r8169.c | 48 ++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c index 96db3283e..cc51286ee 100644 --- a/drivers/net/ethernet/realtek/r8169.c +++ b/drivers/net/ethernet/realtek/r8169.c @@ -736,8 +736,7 @@ struct ring_info { }; enum features { - RTL_FEATURE_MSI = (1 << 0), - RTL_FEATURE_GMII = (1 << 1), + RTL_FEATURE_GMII = (1 << 0), }; struct rtl8169_counters { @@ -7847,7 +7846,7 @@ static int rtl8169_close(struct net_device *dev) cancel_work_sync(&tp->wk.work); - free_irq(pdev->irq, dev); + pci_free_irq(pdev, 0, dev); dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, tp->RxPhyAddr); @@ -7903,9 +7902,8 @@ static int rtl_open(struct net_device *dev) rtl_request_firmware(tp); - retval = request_irq(pdev->irq, rtl8169_interrupt, - (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED, - dev->name, dev); + retval = pci_request_irq(pdev, 0, rtl8169_interrupt, NULL, dev, + dev->name); if (retval < 0) goto err_release_fw_2; @@ -8253,7 +8251,7 @@ static const struct rtl_cfg_info { .region = 2, .align = 8, .event_slow = SYSErr | LinkChg | RxOverflow, - .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI, + .features = RTL_FEATURE_GMII, .coalesce_info = rtl_coalesce_info_8168_8136, .default_ver = RTL_GIGA_MAC_VER_11, }, @@ -8263,32 +8261,26 @@ static const struct rtl_cfg_info { .align = 8, .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver | PCSTimeout, - .features = RTL_FEATURE_MSI, .coalesce_info = rtl_coalesce_info_8168_8136, .default_ver = RTL_GIGA_MAC_VER_13, } }; -/* Cfg9346_Unlock assumed. */ -static unsigned rtl_try_msi(struct rtl8169_private *tp, - const struct rtl_cfg_info *cfg) +static int rtl_alloc_irq(struct rtl8169_private *tp) { void __iomem *ioaddr = tp->mmio_addr; - unsigned msi = 0; - u8 cfg2; + unsigned int flags; - cfg2 = RTL_R8(Config2) & ~MSIEnable; - if (cfg->features & RTL_FEATURE_MSI) { - if (pci_enable_msi(tp->pci_dev)) { - netif_info(tp, hw, tp->dev, "no MSI. Back to INTx.\n"); - } else { - cfg2 |= MSIEnable; - msi = RTL_FEATURE_MSI; - } + if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { + RTL_W8(Cfg9346, Cfg9346_Unlock); + RTL_W8(Config2, RTL_R8(Config2) & ~MSIEnable); + RTL_W8(Cfg9346, Cfg9346_Lock); + flags = PCI_IRQ_LEGACY; + } else { + flags = PCI_IRQ_ALL_TYPES; } - if (tp->mac_version <= RTL_GIGA_MAC_VER_06) - RTL_W8(Config2, cfg2); - return msi; + + return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags); } DECLARE_RTL_COND(rtl_link_list_ready_cond) @@ -8497,9 +8489,11 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) chipset = tp->mac_version; tp->txd_version = rtl_chip_infos[chipset].txd_version; - RTL_W8(Cfg9346, Cfg9346_Unlock); - tp->features |= rtl_try_msi(tp, cfg); - RTL_W8(Cfg9346, Cfg9346_Lock); + rc = rtl_alloc_irq(tp); + if (rc < 0) { + netif_err(tp, probe, dev, "Can't allocate interrupt\n"); + return rc; + } /* override BIOS settings, use userspace tools to enable WOL */ __rtl8169_set_wol(tp, 0);