Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp449469pxb; Wed, 11 Nov 2020 07:40:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJyC99lRAov6kAzbcyat+GNRZmxNYDrmrSeq/jNxPZhdYrd0VQN8Lo7wuZ4NhRzt4vOvABRv X-Received: by 2002:a17:906:4e41:: with SMTP id g1mr26805785ejw.47.1605109226465; Wed, 11 Nov 2020 07:40:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605109226; cv=none; d=google.com; s=arc-20160816; b=PMj8sNNihVpkeRwNmL8rzPb7dLlNHz5QhkSGFf2JXMXMqZ8QOOnUPcqokzeyT5s5No 7p+UrU9shkGzRga0ZUXoN9JfFanqYhwYgm6AKOrxph9DELKQVIVcOwcD78s5yBHjL56a 9KloEY68gsCQmytR4M9BLZmi2PD+zNOhX0AHL9n7hkd9zWaO+iJCgDh9BMMZwywzfSfC /kxIfY/fAUUtnM1nIZZ/S6wY9JfGghEA09TM7sf0gJ5jidgKOfodHO5GI+2Fq891w3j+ MmAl1PQQcV8yFgusMflOisoN6Huu5fIzQUvYIw85KU9+pzPcKNfsezRP9eaYlcZ2bIQd 7Thw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=VzV9VPA4110CrBdUFVUBl6JM+bYUMares6sd3wLMFxM=; b=t9BwpmxpVz6KyAy5ASQX5TJ2xe5hIh66X28/nBdSjaBfQgTLgXbBhmtchwKQQnFbd5 5iCCmgG14TdZE9vTMpwe6qTfnh1ZZRmC3Z3KDkQcj3NluYvKtAIOnhcP/imFi7IyhOCx ILOxVuUygLVdF4QQkP5cgUXM/Or1YMbwHVchfaKWuMLOKGYFlwrE0cltkr/RRp5W7IlG /fT1whyIc7GOdQ2R28ox/tzuprjKe9wM550zdRXwrDxTDfLakC4rTChJgxZN5q3ZVMOn UjSH/Bu6AsJUeeyyUZttFK/e1jJj7Vuxq9oN1/YpWGnx+DKkSvL3I150YDoVeBqoifNq U8Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=eWQZGCx0; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 18si1490914ejv.717.2020.11.11.07.40.03; Wed, 11 Nov 2020 07:40:26 -0800 (PST) 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; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=eWQZGCx0; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727571AbgKKPh7 (ORCPT + 99 others); Wed, 11 Nov 2020 10:37:59 -0500 Received: from fllv0016.ext.ti.com ([198.47.19.142]:38270 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726220AbgKKPh5 (ORCPT ); Wed, 11 Nov 2020 10:37:57 -0500 Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 0ABFbifP097892; Wed, 11 Nov 2020 09:37:44 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1605109064; bh=VzV9VPA4110CrBdUFVUBl6JM+bYUMares6sd3wLMFxM=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=eWQZGCx0zpRUh2KSlM4z7ZcpI3hesdNn23VzAnPZEYU3vGczKN9CSqfaUN2FCrRHH JIr4pHDnWjplsYcPUBpNFSmy6OGUA38jSI/GMMUHU6z4B/XaUhT6FODms/Sy7N4XsI byMPlbTerhtqLB8F9SfqpAXPo/7qD1kHyGiPWbE0= Received: from DFLE103.ent.ti.com (dfle103.ent.ti.com [10.64.6.24]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 0ABFbi27114361 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 11 Nov 2020 09:37:44 -0600 Received: from DFLE105.ent.ti.com (10.64.6.26) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Wed, 11 Nov 2020 09:37:43 -0600 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Wed, 11 Nov 2020 09:37:43 -0600 Received: from a0393678-ssd.dal.design.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 0ABFa042042109; Wed, 11 Nov 2020 09:37:39 -0600 From: Kishon Vijay Abraham I To: Bjorn Helgaas , Jonathan Corbet , Kishon Vijay Abraham I , Lorenzo Pieralisi , Arnd Bergmann , Jon Mason , Dave Jiang , Allen Hubbe , Tom Joseph , Rob Herring CC: Greg Kroah-Hartman , , , , Subject: [PATCH v8 11/18] PCI: cadence: Implement ->msi_map_irq() ops Date: Wed, 11 Nov 2020 21:05:52 +0530 Message-ID: <20201111153559.19050-12-kishon@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201111153559.19050-1-kishon@ti.com> References: <20201111153559.19050-1-kishon@ti.com> MIME-Version: 1.0 Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement ->msi_map_irq() ops in order to map physical address to MSI address and return MSI data. Signed-off-by: Kishon Vijay Abraham I --- .../pci/controller/cadence/pcie-cadence-ep.c | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/pci/controller/cadence/pcie-cadence-ep.c b/drivers/pci/controller/cadence/pcie-cadence-ep.c index 84cc58dc8512..1fe6b8baca97 100644 --- a/drivers/pci/controller/cadence/pcie-cadence-ep.c +++ b/drivers/pci/controller/cadence/pcie-cadence-ep.c @@ -382,6 +382,57 @@ static int cdns_pcie_ep_send_msi_irq(struct cdns_pcie_ep *ep, u8 fn, return 0; } +static int cdns_pcie_ep_map_msi_irq(struct pci_epc *epc, u8 fn, + phys_addr_t addr, u8 interrupt_num, + u32 entry_size, u32 *msi_data, + u32 *msi_addr_offset) +{ + struct cdns_pcie_ep *ep = epc_get_drvdata(epc); + u32 cap = CDNS_PCIE_EP_FUNC_MSI_CAP_OFFSET; + struct cdns_pcie *pcie = &ep->pcie; + u64 pci_addr, pci_addr_mask = 0xff; + u16 flags, mme, data, data_mask; + u8 msi_count; + int ret; + int i; + + /* Check whether the MSI feature has been enabled by the PCI host. */ + flags = cdns_pcie_ep_fn_readw(pcie, fn, cap + PCI_MSI_FLAGS); + if (!(flags & PCI_MSI_FLAGS_ENABLE)) + return -EINVAL; + + /* Get the number of enabled MSIs */ + mme = (flags & PCI_MSI_FLAGS_QSIZE) >> 4; + msi_count = 1 << mme; + if (!interrupt_num || interrupt_num > msi_count) + return -EINVAL; + + /* Compute the data value to be written. */ + data_mask = msi_count - 1; + data = cdns_pcie_ep_fn_readw(pcie, fn, cap + PCI_MSI_DATA_64); + data = data & ~data_mask; + + /* Get the PCI address where to write the data into. */ + pci_addr = cdns_pcie_ep_fn_readl(pcie, fn, cap + PCI_MSI_ADDRESS_HI); + pci_addr <<= 32; + pci_addr |= cdns_pcie_ep_fn_readl(pcie, fn, cap + PCI_MSI_ADDRESS_LO); + pci_addr &= GENMASK_ULL(63, 2); + + for (i = 0; i < interrupt_num; i++) { + ret = cdns_pcie_ep_map_addr(epc, fn, addr, + pci_addr & ~pci_addr_mask, + entry_size); + if (ret) + return ret; + addr = addr + entry_size; + } + + *msi_data = data; + *msi_addr_offset = pci_addr & pci_addr_mask; + + return 0; +} + static int cdns_pcie_ep_send_msix_irq(struct cdns_pcie_ep *ep, u8 fn, u16 interrupt_num) { @@ -481,6 +532,7 @@ static const struct pci_epc_features cdns_pcie_epc_features = { .linkup_notifier = false, .msi_capable = true, .msix_capable = true, + .align = 256, }; static const struct pci_epc_features* @@ -500,6 +552,7 @@ static const struct pci_epc_ops cdns_pcie_epc_ops = { .set_msix = cdns_pcie_ep_set_msix, .get_msix = cdns_pcie_ep_get_msix, .raise_irq = cdns_pcie_ep_raise_irq, + .map_msi_irq = cdns_pcie_ep_map_msi_irq, .start = cdns_pcie_ep_start, .get_features = cdns_pcie_ep_get_features, }; -- 2.17.1