From patchwork Fri May 8 08:58:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Govind Singh X-Patchwork-Id: 11536039 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A098C139F for ; Fri, 8 May 2020 08:59:21 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7E1B720731 for ; Fri, 8 May 2020 08:59:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="J5igcEd3"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=mg.codeaurora.org header.i=@mg.codeaurora.org header.b="h2Avb0yL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7E1B720731 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=ath11k-bounces+patchwork-ath11k=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=feuAOg0v4+eOnkQuDczQH3SxgWCQb1qvAV2QJjb06pY=; b=J5igcEd3qY4f6b 7brrceHr5xHw5ohBUIPs+Lfmcx0uBwTZTx1v6kAOi0x+emZo2kaDqxN5rAaULDJjUzRDGIyv1JMa6 Bt2OTcvHJjTDxl5Gy9Cb6kvwHOYuwW+nK1ux4Es3LYcAxSzEXQrwT009e5+9vFB+onii5oSQEQ/P0 VRo6UZWvz2KxJco/lOFUF9xT51I5tORQhGIHITFXUAzjmH0lKHrLZNpuGQ/FuZv5a95oKpkWUJt4i Esi4EUmMBZeyayJGKSza9wj5Banb7sxqgCrTbYqCS1ROhbbYPvhnbuQqoJcBfDJs6Mcl2ux6aAMjX ppUiGRsNxJeLizS56o8w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jWyql-0008Qq-CT; Fri, 08 May 2020 08:59:19 +0000 Received: from mail27.static.mailgun.info ([104.130.122.27]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jWyqg-0008DR-Pl for ath11k@lists.infradead.org; Fri, 08 May 2020 08:59:18 +0000 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1588928356; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=cbAfdFtdw68iyKQIFwQsTXIlSXeN1lbfLBBAPZDF5KQ=; b=h2Avb0yLD5F1n2Nzk5Z/w36O5g0tbDiGbR7ShAXF5U0sbhxkXiDNJzcL+2SmjVdcKwYbGGsQ 6mc3rtB+/UQ7z8p+PjZ7PTOlEAIPSUc+X6IG2+L9+JFY5RCTv8wV0CWv9Ra077/UGr55N+00 Q9wr7q0FT0N37UZpaoclwJi4Ixc= X-Mailgun-Sending-Ip: 104.130.122.27 X-Mailgun-Sid: WyJmOGQ2ZiIsICJhdGgxMWtAbGlzdHMuaW5mcmFkZWFkLm9yZyIsICJiZTllNGEiXQ== Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by mxa.mailgun.org with ESMTP id 5eb51f55.7f7e4b68b650-smtp-out-n03; Fri, 08 May 2020 08:59:01 -0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 142A5C433D2; Fri, 8 May 2020 08:59:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=2.0 tests=ALL_TRUSTED,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.0 Received: from govinds-linux.qualcomm.com (blr-c-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: govinds) by smtp.codeaurora.org (Postfix) with ESMTPSA id EE706C433F2; Fri, 8 May 2020 08:58:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org EE706C433F2 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=none smtp.mailfrom=govinds@codeaurora.org From: Govind Singh To: ath11k@lists.infradead.org Subject: [PATCH 2/4] ath11k: setup pci resource for QCA6390 target Date: Fri, 8 May 2020 14:28:48 +0530 Message-Id: <20200508085850.23363-3-govinds@codeaurora.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200508085850.23363-1-govinds@codeaurora.org> References: <20200508085850.23363-1-govinds@codeaurora.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200508_015916_581104_FAD551FF X-CRM114-Status: GOOD ( 15.88 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 RCVD_IN_MSPIKE_H4 RBL: Very Good reputation (+4) [104.130.122.27 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [104.130.122.27 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: ath11k@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Govind Singh , linux-wireless@vger.kernel.org Sender: "ath11k" Errors-To: ath11k-bounces+patchwork-ath11k=patchwork.kernel.org@lists.infradead.org Add support for setting up pci region and dma mask for QCA6390 target. Signed-off-by: Govind Singh --- drivers/net/wireless/ath/ath11k/core.c | 1 + drivers/net/wireless/ath/ath11k/pci.c | 109 ++++++++++++++++++++++++- drivers/net/wireless/ath/ath11k/pci.h | 12 +++ 3 files changed, 121 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath11k/core.c b/drivers/net/wireless/ath/ath11k/core.c index 8d07a2bb31bb..4c3f5a9d0d8a 100644 --- a/drivers/net/wireless/ath/ath11k/core.c +++ b/drivers/net/wireless/ath/ath11k/core.c @@ -14,6 +14,7 @@ #include "hif.h" unsigned int ath11k_debug_mask; +EXPORT_SYMBOL(ath11k_debug_mask); module_param_named(debug_mask, ath11k_debug_mask, uint, 0644); MODULE_PARM_DESC(debug_mask, "Debugging mask"); diff --git a/drivers/net/wireless/ath/ath11k/pci.c b/drivers/net/wireless/ath/ath11k/pci.c index 582e7cd3c56e..6ab9e25c4ff9 100644 --- a/drivers/net/wireless/ath/ath11k/pci.c +++ b/drivers/net/wireless/ath/ath11k/pci.c @@ -6,6 +6,7 @@ #include #include +#include "ahb.h" #include "core.h" #include "pci.h" #include "debug.h" @@ -18,10 +19,98 @@ static const struct pci_device_id ath11k_pci_id_table[] = { MODULE_DEVICE_TABLE(pci, ath11k_pci_id_table); +static inline struct ath11k_pci *ath11k_pci_priv(struct ath11k_base *ab) +{ + return (struct ath11k_pci *)ab->drv_priv; +} + +static int ath11k_pci_claim(struct ath11k_pci *ab_pci, struct pci_dev *pdev) +{ + u32 pci_dma_mask = PCI_DMA_MASK_32_BIT; + struct ath11k_base *ab = ab_pci->ab; + u16 device_id; + int ret = 0; + + pci_read_config_word(pdev, PCI_DEVICE_ID, &device_id); + if (device_id != ab_pci->dev_id) { + ath11k_err(ab, "pci device id mismatch, config ID: 0x%x, probe ID: 0x%x\n", + device_id, ab_pci->dev_id); + ret = -EIO; + goto out; + } + + ret = pci_assign_resource(pdev, PCI_BAR_NUM); + if (ret) { + ath11k_err(ab, "failed to assign pci resource, err = %d\n", ret); + goto out; + } + + ret = pci_enable_device(pdev); + if (ret) { + ath11k_err(ab, "failed to enable pci device, err = %d\n", ret); + goto out; + } + + ret = pci_request_region(pdev, PCI_BAR_NUM, "ath11k_pci"); + if (ret) { + ath11k_err(ab, "failed to request pci region, err = %d\n", ret); + goto disable_device; + } + + ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(pci_dma_mask)); + if (ret) { + ath11k_err(ab, "failed to set pci dma mask (%d), err = %d\n", + ret, pci_dma_mask); + goto release_region; + } + + ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(pci_dma_mask)); + if (ret) { + ath11k_err(ab, "failed to set pci consistent dma mask (%d), err = %d\n", + ret, pci_dma_mask); + goto release_region; + } + + pci_set_master(pdev); + + ab_pci->mem_len = pci_resource_len(pdev, PCI_BAR_NUM); + ab_pci->mem = pci_iomap(pdev, PCI_BAR_NUM, 0); + if (!ab_pci->mem) { + ath11k_err(ab, "failed to map pci bar, bar = %d\n", PCI_BAR_NUM); + ret = -EIO; + goto clear_master; + } + + ath11k_dbg(ab, ATH11K_DBG_BOOT, "boot pci_mem 0x%pK\n", ab_pci->mem); + return 0; + +clear_master: + pci_clear_master(pdev); +release_region: + pci_release_region(pdev, PCI_BAR_NUM); +disable_device: + pci_disable_device(pdev); +out: + return ret; +} + +static void ath11k_pci_free_region(struct ath11k_pci *ab_pci) +{ + struct pci_dev *pci_dev = ab_pci->pdev; + + pci_iounmap(pci_dev, ab_pci->mem); + ab_pci->mem = NULL; + pci_clear_master(pci_dev); + pci_release_region(pci_dev, PCI_BAR_NUM); + if (pci_is_enabled(pci_dev)) + pci_disable_device(pci_dev); +} + static int ath11k_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pci_dev) { struct ath11k_base *ab; + struct ath11k_pci *ab_pci; enum ath11k_hw_rev hw_rev; int ret; @@ -38,24 +127,42 @@ static int ath11k_pci_probe(struct pci_dev *pdev, return -ENOTSUPP; } - ab = ath11k_core_alloc(&pdev->dev, 0, ATH11K_BUS_PCI); + ab = ath11k_core_alloc(&pdev->dev, sizeof(*ab_pci), ATH11K_BUS_PCI); if (!ab) { dev_err(&pdev->dev, "failed to allocate ath11k base\n"); return -ENOMEM; } + ab->dev = &pdev->dev; + ab->hw_rev = hw_rev; + pci_set_drvdata(pdev, ab); + ab_pci = ath11k_pci_priv(ab); + ab_pci->dev_id = pci_dev->device; + ab_pci->ab = ab; ab->dev = &pdev->dev; ab->hw_rev = hw_rev; pci_set_drvdata(pdev, ab); + ret = ath11k_pci_claim(ab_pci, pdev); + if (ret) { + ath11k_err(ab, "failed to claim device: %d\n", ret); + goto err_free_core; + } + + return 0; + +err_free_core: + ath11k_core_free(ab); return ret; } static void ath11k_pci_remove(struct pci_dev *pdev) { struct ath11k_base *ab = pci_get_drvdata(pdev); + struct ath11k_pci *ab_pci = ath11k_pci_priv(ab); set_bit(ATH11K_FLAG_UNREGISTERING, &ab->dev_flags); + ath11k_pci_free_region(ab_pci); ath11k_core_free(ab); } diff --git a/drivers/net/wireless/ath/ath11k/pci.h b/drivers/net/wireless/ath/ath11k/pci.h index 790b8993d225..5e6f2b5059a8 100644 --- a/drivers/net/wireless/ath/ath11k/pci.h +++ b/drivers/net/wireless/ath/ath11k/pci.h @@ -7,4 +7,16 @@ #define QCA6290_DEVICE_ID 0x1100 #define QCA6390_VENDOR_ID 0x17CB #define QCA6390_DEVICE_ID 0x1101 +#define PCI_BAR_NUM 0 +#define PCI_DMA_MASK_64_BIT 64 +#define PCI_DMA_MASK_32_BIT 32 +struct ath11k_pci { + struct pci_dev *pdev; + struct device *dev; + struct ath11k_base *ab; + void __iomem *mem; + size_t mem_len; + u16 dev_id; + u32 chip_id; +};