From patchwork Fri Mar 28 03:36:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Lee X-Patchwork-Id: 3900671 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id F1E98BF540 for ; Fri, 28 Mar 2014 03:36:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0C5DB202EC for ; Fri, 28 Mar 2014 03:36:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0F129202F8 for ; Fri, 28 Mar 2014 03:36:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757399AbaC1Dgd (ORCPT ); Thu, 27 Mar 2014 23:36:33 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:60526 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757056AbaC1Dgb (ORCPT ); Thu, 27 Mar 2014 23:36:31 -0400 Received: by mail-pa0-f47.google.com with SMTP id lj1so4388363pab.34 for ; Thu, 27 Mar 2014 20:36:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1DmvY7kEXqr6aXDmrZq5RN6xBy/OqzPVIqXXxjUAyuM=; b=gv1uzu4BLSYcv1PMjJwZ5e8AbtG6B+VVEUJokdPOR856RS6T5E24FogBAKHdE9OAkk CYBLdnNWijBG93T4cyjBQQXtwCCha2VLQtZ+b2jtkWhTJSZKIZfaBk0wWjanYwspKTLI /2/vmW/95MSMhkLgPp7XZIWiGnL0XzvXSGDRJS6VxSx3ll7hRohc1LzPbNmGyxFWLEPw UHfe5QUG1OFunHDWy9O/odCgp0euYscYmEo0Xbw+v2G5Ynx/YTv8fTsRtXbDNFonSYor 3BvbaOZ2utrPGfw/hcbRSaqmQAoWVw/loD53iyYES7eqY2oMPz0EMOyyIwzt6Ogd8p5L CO2g== X-Gm-Message-State: ALoCoQne8emehAiBqpM9zSvAil45++LxuwkP1zfd4vJCfL7bzgqW1X+5IcIoUyzz2orpZSa+jEHF X-Received: by 10.68.224.195 with SMTP id re3mr5765230pbc.93.1395977791394; Thu, 27 Mar 2014 20:36:31 -0700 (PDT) Received: from localhost ([116.213.97.190]) by mx.google.com with ESMTPSA id pe3sm16468597pbc.23.2014.03.27.20.36.28 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 27 Mar 2014 20:36:30 -0700 (PDT) From: Adam Lee To: linux-wireless@vger.kernel.org Cc: netdev@vger.kernel.org, Larry Finger , "John W. Linville" Subject: [PATCH v3 1/2] rtlwifi: add MSI interrupts mode support Date: Fri, 28 Mar 2014 11:36:18 +0800 Message-Id: <1395977779-16093-1-git-send-email-adam.lee@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1395715732-9545-1-git-send-email-adam.lee@canonical.com> References: <1395715732-9545-1-git-send-email-adam.lee@canonical.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add MSI interrupts mode support, enable it when submodules' msi_support flag is true, also could fallback to pin-based interrupts mode if MSI interrupts mode fails. RealTek's policy(on modules which work well with MSI interrupts mode) is: > If the platform supports both MSI and pin-based, use MSI. > If the platform supports MSI only, use MSI. > If the platform supports pin-based only, use pin-based. Also as RealTek's testing results, RTL8188EE and RTL8723BE work well with both MSI mode and pin-based mode fallback. Signed-off-by: Adam Lee --- drivers/net/wireless/rtlwifi/pci.c | 65 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/rtlwifi/pci.c b/drivers/net/wireless/rtlwifi/pci.c index 7d71170..dae5525 100644 --- a/drivers/net/wireless/rtlwifi/pci.c +++ b/drivers/net/wireless/rtlwifi/pci.c @@ -1853,6 +1853,65 @@ static bool _rtl_pci_find_adapter(struct pci_dev *pdev, return true; } +static int rtl_pci_intr_mode_msi(struct ieee80211_hw *hw) +{ + struct rtl_priv *rtlpriv = rtl_priv(hw); + struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); + struct rtl_pci *rtlpci = rtl_pcidev(pcipriv); + int ret; + + ret = pci_enable_msi(rtlpci->pdev); + if (ret < 0) + return ret; + + ret = request_irq(rtlpci->pdev->irq, &_rtl_pci_interrupt, + IRQF_SHARED, KBUILD_MODNAME, hw); + if (ret < 0) { + pci_disable_msi(rtlpci->pdev); + return ret; + } + + rtlpci->using_msi = true; + + RT_TRACE(rtlpriv, COMP_INIT|COMP_INTR, DBG_DMESG, + "MSI Interrupt Mode!\n"); + return 0; +} + +static int rtl_pci_intr_mode_legacy(struct ieee80211_hw *hw) +{ + struct rtl_priv *rtlpriv = rtl_priv(hw); + struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); + struct rtl_pci *rtlpci = rtl_pcidev(pcipriv); + int ret; + + ret = request_irq(rtlpci->pdev->irq, &_rtl_pci_interrupt, + IRQF_SHARED, KBUILD_MODNAME, hw); + if (ret < 0) + return ret; + + rtlpci->using_msi = false; + RT_TRACE(rtlpriv, COMP_INIT|COMP_INTR, DBG_DMESG, + "Pin-based Interrupt Mode!\n"); + return 0; +} + +static int rtl_pci_intr_mode_decide(struct ieee80211_hw *hw) +{ + struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); + struct rtl_pci *rtlpci = rtl_pcidev(pcipriv); + int ret; + + if (rtlpci->msi_support) { + ret = rtl_pci_intr_mode_msi(hw); + if (ret < 0) + ret = rtl_pci_intr_mode_legacy(hw); + } else { + ret = rtl_pci_intr_mode_legacy(hw); + } + return ret; +} + int rtl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) { @@ -1995,8 +2054,7 @@ int rtl_pci_probe(struct pci_dev *pdev, } rtlpci = rtl_pcidev(pcipriv); - err = request_irq(rtlpci->pdev->irq, &_rtl_pci_interrupt, - IRQF_SHARED, KBUILD_MODNAME, hw); + err = rtl_pci_intr_mode_decide(hw); if (err) { RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "%s: failed to register IRQ handler\n", @@ -2064,6 +2122,9 @@ void rtl_pci_disconnect(struct pci_dev *pdev) rtlpci->irq_alloc = 0; } + if (rtlpci->using_msi) + pci_disable_msi(rtlpci->pdev); + list_del(&rtlpriv->list); if (rtlpriv->io.pci_mem_start != 0) { pci_iounmap(pdev, (void __iomem *)rtlpriv->io.pci_mem_start);