From patchwork Mon Mar 24 11:34:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Lee X-Patchwork-Id: 3882491 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AFC939F2B6 for ; Mon, 24 Mar 2014 11:35:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CF716201F4 for ; Mon, 24 Mar 2014 11:35:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C665A201C8 for ; Mon, 24 Mar 2014 11:35:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752952AbaCXLfJ (ORCPT ); Mon, 24 Mar 2014 07:35:09 -0400 Received: from mail-pd0-f174.google.com ([209.85.192.174]:41861 "EHLO mail-pd0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752881AbaCXLfB (ORCPT ); Mon, 24 Mar 2014 07:35:01 -0400 Received: by mail-pd0-f174.google.com with SMTP id y13so5181336pdi.19 for ; Mon, 24 Mar 2014 04:35:00 -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=Zciuyp2r7ufgUtMSlNm6VIddMGN1vK5V9q0YaugChao=; b=WbNyZY7TsZST8BJTiGn6HzgUNCZmk5hsSheDlg0UahOZhIbtQD0CpwI72WQE27R9L5 mhz0KjSO7o8f95xwb5aV5oct9o0IZLFHTcbJehU1FRAEwxlXd+mufNBPjcf2CAG2RXw7 h6L+HbJicbALcL9zOjvEy9GlWNlFz/4ziLw6LAscVbPfunEmFAu5jyQ9k2jzYTN2YwhB cj+XLF6ejhMAIhuTb9HlDkRR3+hPWoCeLVZfImaRctCY4/kGsmwePKCevO6FOkOF3H2j YRObWnePAt25SJNRGfvo1XSi2Hzm/+g/afwGU4n2dqRNiCSdQdkYXm+Aae5ExZHVlShR zs1A== X-Gm-Message-State: ALoCoQl/86iAirDi4N/3AsxtATH2sE/cKW4Us9iR/l1594BRLDJU28aM2UP/0OgyGw3qfjzUkbf1 X-Received: by 10.66.119.172 with SMTP id kv12mr71046614pab.34.1395660900420; Mon, 24 Mar 2014 04:35:00 -0700 (PDT) Received: from localhost ([202.108.52.204]) by mx.google.com with ESMTPSA id st4sm58463440pab.34.2014.03.24.04.34.55 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 24 Mar 2014 04:34:59 -0700 (PDT) From: Adam Lee To: linux-wireless@vger.kernel.org Cc: netdev@vger.kernel.org, Larry Finger , stable@kernel.org, "John W. Linville" , Chaoming Li Subject: [PATCH] rtlwifi: add MSI interrupts support Date: Mon, 24 Mar 2014 19:34:44 +0800 Message-Id: <1395660884-15042-1-git-send-email-adam.lee@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1395640841-14477-1-git-send-email-adam.lee@canonical.com> References: <1395640841-14477-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.4 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 support, enable it when msi_support flag is true, also could fallback to pin-based interrupts mode if MSI mode fails. Signed-off-by: Adam Lee --- drivers/net/wireless/rtlwifi/pci.c | 63 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/rtlwifi/pci.c b/drivers/net/wireless/rtlwifi/pci.c index f26f4ff..dd8497a 100644 --- a/drivers/net/wireless/rtlwifi/pci.c +++ b/drivers/net/wireless/rtlwifi/pci.c @@ -1853,6 +1853,63 @@ 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 == true) { + 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 +2052,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 +2120,9 @@ void rtl_pci_disconnect(struct pci_dev *pdev) rtlpci->irq_alloc = 0; } + if (rtlpci->using_msi == true) + 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);