Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4087259pxb; Mon, 1 Feb 2021 12:04:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJxq7ABcSrCeyEUUh7FI5sRP3EE8nP87TduwLGIJN4bcX0WBNhy9HRzkpokENxjfC9QJtOMr X-Received: by 2002:a50:cf02:: with SMTP id c2mr20516500edk.333.1612209879771; Mon, 01 Feb 2021 12:04:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612209879; cv=none; d=google.com; s=arc-20160816; b=dtQl8B/uT1LcP8KkFdXaPUP3ykWCyz5qsRPa0PHwLAk+4w4z3K0con65iySp6i3Jj3 w//zYruJuGLOlzf0wMf16XXy9fRg/ZUPZrnVU7CWwk/LQuiVY3CQylWjEtO17TzoQWqw dcL5EXR4IRq7YmFY4b9oPcczrbcgLzw3vDfGtWOTbPgN67BSj3qVdecMVzRbz6n2cty3 rsKyOuGDkfr0rCflCxBcRtZ6W4hfu0TzwChmbfuktzNoFMWxSQXebx86b104RRmcadx3 Ufr5ECfTQuqv3naXkY4b6CkhDfoOLxafEaRR76kxpK8TMhXHquOZnn8x6o7T0KURBdw2 Poag== 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=t1ZxRvI6L0aF9sPYQjzUUVghV7Bpq0aMFrquckHN9dQ=; b=d07oHF1vyvcR6ytMeiwm9hMQsv8vnbIfTvd5eqx2rFlswZ73/HPPiQiIXV/I4SemRW W64T62lCReJHg8+hTy5uSu0hEJBWvLTErk44AqqeGtzshJt1zUmfzdoSSSg/ywlXTtZl 3DY/S0zEu7vn4PFjG43w710PcfBQvumyxfrnQmDQWXmhvbRs7CpqVRY6sErkiP2PQssw BchMcYg0OO+Ke5YtKH3yWexbZsyQ2pTyvOyqVNU53w09kFsG+ue9QGwxLFVEsEymjz8L X3wzJ3Av+OvvVqkl5YNwrcZzBLpWozTULR0XQJ0Xj6h+sZofbIXgSaWL3BtlBqK6a+GC sqQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=ObDEHWSL; 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 d12si11643300ejb.358.2021.02.01.12.04.11; Mon, 01 Feb 2021 12:04:39 -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=ObDEHWSL; 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 S232927AbhBAUA6 (ORCPT + 99 others); Mon, 1 Feb 2021 15:00:58 -0500 Received: from fllv0016.ext.ti.com ([198.47.19.142]:41866 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232768AbhBAUAS (ORCPT ); Mon, 1 Feb 2021 15:00:18 -0500 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 111JxHFo023990; Mon, 1 Feb 2021 13:59:17 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1612209557; bh=t1ZxRvI6L0aF9sPYQjzUUVghV7Bpq0aMFrquckHN9dQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=ObDEHWSLIxwZIuQBd9wppDT22ssVFFmZ4IGvICfUBnxOYsh+HVwcxYYWo7n5b/t/O hm64iMrsDbQt7miKUGAPzw84ES2rqFTjzh2nj+hrGhBrb+Ge/AYqHNGkktMS7czTzV 3M+wkXVGWhPe7v7S16TVmVbmtdBCUFy5iUuPfekw= Received: from DLEE100.ent.ti.com (dlee100.ent.ti.com [157.170.170.30]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 111JxHH8101829 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 1 Feb 2021 13:59:17 -0600 Received: from DLEE103.ent.ti.com (157.170.170.33) by DLEE100.ent.ti.com (157.170.170.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Mon, 1 Feb 2021 13:59:16 -0600 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE103.ent.ti.com (157.170.170.33) 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; Mon, 1 Feb 2021 13:59:16 -0600 Received: from a0393678-ssd.dal.design.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 111JwAQi085814; Mon, 1 Feb 2021 13:59:11 -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 v11 11/17] PCI: cadence: Implement ->msi_map_irq() ops Date: Tue, 2 Feb 2021 01:28:03 +0530 Message-ID: <20210201195809.7342-12-kishon@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210201195809.7342-1-kishon@ti.com> References: <20210201195809.7342-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 Reviewed-by: Tom Joseph --- .../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 9e2b024d32f2..dc88078194cb 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