Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4667973pxk; Wed, 30 Sep 2020 08:41:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzR/07XjqmffPNYUWMu3ftZG8QCEygLN1q7ihFIFxfA6XY65Co87ijVoFE8IfRsL4DDe6qU X-Received: by 2002:a17:906:5488:: with SMTP id r8mr3338638ejo.483.1601480491393; Wed, 30 Sep 2020 08:41:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601480491; cv=none; d=google.com; s=arc-20160816; b=NsuzVTW9NJJQkDWRxLFx9cqvCGcKDFHVK7q/da8NgCqUs3eCGASG87liGN6R/MV3cb rqwZZqZXSsbzBZxL0XV4T1qQy7wqiayGM2eK0FYbiDyWogljes3KcbOG3LDl6AsIPyM9 4ZVcbS7n9JfIxFf8eLgoq+3xuuBezcG+EKEgMxnyxZiEDsrp+yo4xu+z93UqYtA8GelO 77oq2bGXZQ0K0LAnQIbKbbwOV2ti+jkTBAlZOU47SRSw+a1hKl4reFUjkzMQVIdb9vLb WlMiYRs9fm5Lb4hdlRiOvKuXn2U+ccye4lHFSKQbiUTxWrz4j3KDE0bm0mXsA/htVDiK 0nww== 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=1Ii+sodm1kJBqDIewPjIsrGNN7Eqm55YjonNoKE1M6Q=; b=Cq1beQ97DzYy46WQWwqnErbXp30ajL3ME7+wqsdE6+XX3wrdOBpGVHPqKGQUI+jjtI Jufpir9+tGGBus6r+KQiAc8k8Yhnz/pVSvO3Xsw5flJ04DZJqZ0uo+9Mx66FSggGmCpJ 7W4vGa3orFaBg1GaF6ob+9j9Ua4FNcLWeN2TpORoHX4vbKQnF+hUYRFnPzV+2NcTouVJ +NEgvR/JEdN+Dih1L3A6lpmMq7TUoAhuSiFd/U/9Wqp+/iv9uhIdE2TxEDKkcATzwOY8 MiykICYgDSRs2xCL20BYgUW0VstpEJVeeCwpreRIgKee0eBRnhKud+BtUzwmLWNnDPe/ 7a/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=Md94JFk7; 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 r19si1431912ejr.560.2020.09.30.08.41.08; Wed, 30 Sep 2020 08:41:31 -0700 (PDT) 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=Md94JFk7; 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 S1731130AbgI3Phh (ORCPT + 99 others); Wed, 30 Sep 2020 11:37:37 -0400 Received: from fllv0015.ext.ti.com ([198.47.19.141]:57342 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728819AbgI3Phh (ORCPT ); Wed, 30 Sep 2020 11:37:37 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 08UFbPNf044103; Wed, 30 Sep 2020 10:37:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1601480245; bh=1Ii+sodm1kJBqDIewPjIsrGNN7Eqm55YjonNoKE1M6Q=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=Md94JFk7t98hcR86Cq9CXZR6Qu1te3WnxHJaJAB9Dp7H5Zyi1nlKADKYkx7GeKgQ8 ZHQe+LHTAQHL7TsdBJp9poPkMB2a1QGD2Tp3Vj2mMoYl9Zt4iTyR6rkT5hvbBzrZrT jRDIK8r4hFGceHAp79UWItxUZQ4rgJ+XQiINhpjM= Received: from DFLE103.ent.ti.com (dfle103.ent.ti.com [10.64.6.24]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 08UFbPGN026755 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 30 Sep 2020 10:37:25 -0500 Received: from DFLE104.ent.ti.com (10.64.6.25) 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, 30 Sep 2020 10:37:25 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE104.ent.ti.com (10.64.6.25) 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, 30 Sep 2020 10:37:25 -0500 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 08UFZLZa033254; Wed, 30 Sep 2020 10:36:34 -0500 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 v7 11/18] PCI: cadence: Implement ->msi_map_irq() ops Date: Wed, 30 Sep 2020 21:05:12 +0530 Message-ID: <20200930153519.7282-12-kishon@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200930153519.7282-1-kishon@ti.com> References: <20200930153519.7282-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 254a3e1eff50..5df492a12042 100644 --- a/drivers/pci/controller/cadence/pcie-cadence-ep.c +++ b/drivers/pci/controller/cadence/pcie-cadence-ep.c @@ -383,6 +383,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) { @@ -482,6 +533,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* @@ -501,6 +553,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