Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753759AbdHXUiJ (ORCPT ); Thu, 24 Aug 2017 16:38:09 -0400 Received: from mail-by2nam03on0045.outbound.protection.outlook.com ([104.47.42.45]:45712 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753362AbdHXUiD (ORCPT ); Thu, 24 Aug 2017 16:38:03 -0400 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; From: Roy Pledge To: , , , CC: , , , , , , Roy Pledge Subject: [v4 02/11] soc/fsl/qbman: Use shared-dma-pool for QMan private memory allocations Date: Thu, 24 Aug 2017 16:37:46 -0400 Message-ID: <1503607075-28970-3-git-send-email-roy.pledge@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503607075-28970-1-git-send-email-roy.pledge@nxp.com> References: <1503607075-28970-1-git-send-email-roy.pledge@nxp.com> Reply-To: X-EOPAttributedMessage: 0 X-Matching-Connectors: 131480806809772596;(91ab9b29-cfa4-454e-5278-08d120cd25b8);() X-Forefront-Antispam-Report: CIP:192.88.168.50;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(336005)(39860400002)(39380400002)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(85426001)(53936002)(8936002)(4326008)(86362001)(36756003)(54906002)(8656003)(8676002)(2950100002)(2201001)(43066003)(81156014)(50986999)(76176999)(3450700001)(7416002)(498600001)(2906002)(6666003)(81166006)(68736007)(33646002)(105606002)(106466001)(48376002)(50466002)(5660300001)(97736004)(47776003)(77096006)(356003)(50226002)(5003940100001)(305945005)(104016004)(626005)(230783001)(189998001)(2101003);DIR:OUT;SFP:1101;SCL:1;SRVR:BN6PR03MB3316;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BY2FFO11FD009;1:Sh7WnTGjJ+C8IgiJ1hQLkiRtoNy2V99GxSWIhYvVDZ4QgwfKFlHxvyfQDU8c1dTlpu4B32V6tUrtt8wH9rMzEv3DjMoQ8piopfHeSu3sY8RZXT3rPGKh0oDIxOxCfvL4 MIME-Version: 1.0 Content-Type: text/plain X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 58b98571-4caa-4521-40d3-08d4eb300322 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(300000503095)(300135400095)(2017052603199)(201703131430075)(201703131517081)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:BN6PR03MB3316; X-Microsoft-Exchange-Diagnostics: 1;BN6PR03MB3316;3:5kAd5GFjPMxuDUIK7FY+8ONO2LlYEAXe/LS9B9mjtVo96vTkfB4mtK8IuShWDMM0aSu2T7mYmBm11eCVwFCYd2I34PSf8GWQxHHmRN3dQlp+eGr1m3OHCs0GLsU0OkVagj8l9lhTdXH/6zxf35sueExCGZIkZPMto/pG1D9Xs4E+3BrhWsbvAc1QxPJY6/iU5IOr9a3x4ic7t5kkZ4GRg35co941CtTGllRLaFf+g/W2ObOyBwlwmawm5H/d7G/HSA7OmtkG4UOqrmQJCaVFP+oOPWmkHebHGS0gH7ljrGiOMTVSz8ZN6jgMn2ugdw0X5EmWA4y1UYve4RAhBEDniX53xrVQD/VQVlyMAwOjPik=;25:E+waf1UtbXci7vIVjN1zYC54qh5wHi/bui5YQf7jfl1H+MSMrirvLMkE/rSvKwyQ434NRKpvyinevKIHlmVqwbOzoHoCXhdJs/LR9M7H8382EPsovTTGukF3QQHEAMdAI7DMxFcjoJnwPKuLBNMqKxIJxcWUKkUAG6dWU1EACU6Yro0/z7MQbGwdDey9dp3GfctJ26DqUfUqlbDgKMmtH3NquLuDNS7/tM2vTeeYqYIP4IYTk3YNwY0UIfHOiZde0FMhMhbHcA5/GyV93ZLnFUsz4PCNXzWIFs4B0mNG9lgNiPd3l5jgV6+JKvcKB2CCBTFEHTlA1E6U9Mi8IKRt1g== X-MS-TrafficTypeDiagnostic: BN6PR03MB3316: X-Microsoft-Exchange-Diagnostics: 1;BN6PR03MB3316;31:jCXCNqk8VwguJjyACBHAswaybYSy3sNJlXfZGa303binImerg5wr/AdGChIDm63qYS2TzLhu1J8AYS6ti4uOv3XgiwqwDyDSi1vG775tB3ZSXpllmxuaINYpWU4uJo7KVlaNQyyC49DJcRvacwM4SGm2+EEenVkJBa/NosGsPhSyb4lDRGaTqf1CGvIFSiH3aM/jl+YOGg4KbIue0hDLaQ+sTH5qRPGIh3wMLVMesDM=;4:5jKCi7kG2rx1bDRk4JeDPvjopBxivvn9ycdDPjNY/ANYMQs3uffot8MI8jshs+0sqXuu6vsol9O36YoXHoDV0meBDtlC/FbAw2mkvVtVV9FCFFIUZRumpHERKUbzBJxQmi0LuRt11ESUqR9XzRUZL6kkm893yoCPamqJn3058wuO/tOwaHnuCjIOY6oCBJDFSyaFbHIby8XuILlJsGxMetDvSHocLaWGO7eeR6hhDZRmzbCfkxY6hLfVG3t4CopIg9Pg0aEl5xJ1N/+meazS+lv7kFLzoy6w30ZekKzeucQ= X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6095135)(601004)(2401047)(13016025)(8121501046)(13018025)(5005006)(3002001)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(6055026)(6096035)(20161123559100)(20161123561025)(20161123563025)(20161123565025)(201703131430075)(201703131433075)(201703131441075)(201703131448075)(201703161259150)(20161123556025)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:BN6PR03MB3316;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(400006)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:BN6PR03MB3316; X-Forefront-PRVS: 04097B7F7F X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BN6PR03MB3316;23:5wqs5ccO04FUHgtU+QQ2vh40/SGwZ3Gngt+Upq4WT?= =?us-ascii?Q?fvh3FsgyfPFRBjshW9cQ6yTkY8p2kGqBtpYUFLqx2d86vYn/8M5AvlFqDeFl?= =?us-ascii?Q?/FMoHuU+6HQjUfU9hOmvp/LxEHFK9cDfvNvfrz8VJhuhvUUGqdy4WCvu8svz?= =?us-ascii?Q?R84yhEf6ZEbka6+3OM1VcJ6wPsOrO5Uy4Tf1I+ij1A+RyMeO5uwgr2tBNL15?= =?us-ascii?Q?lIQLW8mweTbUDCTRfQwqHSlhhGe0dUy5dJozK7mNA4Al2Jw+KjzZeBcMPCSq?= =?us-ascii?Q?whilz9dT2ufWzjUG4aJPnviggXHzW2A3cEtoDxMyTkz2W9VgPXqUhwWZ767g?= =?us-ascii?Q?XLcRWVpDz0VE9LRFh24JQg3ewfddkDHZjVK+MXsARkeITQ5lHjaBw4cIi/E8?= =?us-ascii?Q?LDZFFuig3UVf3UFQxB/adB13bnebMROJLl8V+OlJ7gNU9foXLND18Cvt8PJH?= =?us-ascii?Q?YdquRy3e0s448cEcvfGsHZfQxoCLT21g5IomwAoHNbLvEKfoS1GIvi+uF/Ce?= =?us-ascii?Q?6jXWjZIAJmBCEf8TRIrdQy/4OG+R8roJ6wKVHoj3fARkUg4fLYHzkdF1M9I9?= =?us-ascii?Q?hfrNoH4PdqVakrsSrh9fHkhdanqe0/Ffdb6Pn/vWgRz2uQ9lC0L2PMBuYaFl?= =?us-ascii?Q?FBSyGuGSEdDg4JQbxi0Taei5VpONQTdNerrun7USoz9fMrMM0yaoMonKVxLm?= =?us-ascii?Q?3QEpp26p2v5rwjDc2ujNqClN/VZ3JhU38OAyFXRswZi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//+oaGjAQUe+XvjpxGr7JQ4YXyRT2VqD/DD4MD/ApPmDUsDODaQ==;24:9dDeoIbxyy517zWTUUKPlx56FCaKFm7FKVQBO/1TfsxbjlTFasZH+KOGt75teDm/AeWoO9xSKTVXITpkKX2wGb8FePKhTYj5jXTiaYO7PfY=;7:qGZqZNGUDgJAf26TdTuS/9Z8XAGw0He/C/7oLLGDrTB/to/AtfI9zp6Omun5pzl1iE/WkA1urZ6UchLwJCSbq44PVeNTZadqpyk1rlNqXHaQWxTsgknrfExVVbH6uGB8eF3Sz6FBbaM1mAO0O3IwytfIXZo6WyERoEIQT5/jM+Q6OF0CcaJ2i6ZigMcPxH2PbHkJub/1vUsLJ8GfxPA+l2fxq9fEWj0GAZC8cT2qlT8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Aug 2017 20:38:00.7744 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e;Ip=[192.88.168.50];Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR03MB3316 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6837 Lines: 233 Use the shared-memory-pool mechanism for frame queue descriptor and packed frame descriptor record area allocations. Signed-off-by: Roy Pledge --- drivers/soc/fsl/qbman/qman_ccsr.c | 138 +++++++++++++++++++++++++++++--------- drivers/soc/fsl/qbman/qman_priv.h | 4 +- drivers/soc/fsl/qbman/qman_test.h | 2 - 3 files changed, 109 insertions(+), 35 deletions(-) diff --git a/drivers/soc/fsl/qbman/qman_ccsr.c b/drivers/soc/fsl/qbman/qman_ccsr.c index 835ce94..20a1ebd 100644 --- a/drivers/soc/fsl/qbman/qman_ccsr.c +++ b/drivers/soc/fsl/qbman/qman_ccsr.c @@ -401,21 +401,42 @@ static int qm_init_pfdr(struct device *dev, u32 pfdr_start, u32 num) } /* - * Ideally we would use the DMA API to turn rmem->base into a DMA address - * (especially if iommu translations ever get involved). Unfortunately, the - * DMA API currently does not allow mapping anything that is not backed with - * a struct page. + * QMan needs two global memory areas initialized at boot time: + * 1) FQD: Frame Queue Descriptors used to manage frame queues + * 2) PFDR: Packed Frame Queue Descriptor Records used to store frames + * Both areas are reserved using the device tree reserved memory framework + * and the addresses and sizes are initialized when the QMan device is probed */ static dma_addr_t fqd_a, pfdr_a; static size_t fqd_sz, pfdr_sz; +#ifdef CONFIG_PPC +/* + * Support for PPC Device Tree backward compatibility when compatible + * string is set to fsl-qman-fqd and fsl-qman-pfdr + */ +static int zero_priv_mem(phys_addr_t addr, size_t sz) +{ + /* map as cacheable, non-guarded */ + void __iomem *tmpp = ioremap_prot(addr, sz, 0); + + if (!tmpp) + return -ENOMEM; + + memset_io(tmpp, 0, sz); + flush_dcache_range((unsigned long)tmpp, + (unsigned long)tmpp + sz); + iounmap(tmpp); + + return 0; +} + static int qman_fqd(struct reserved_mem *rmem) { fqd_a = rmem->base; fqd_sz = rmem->size; WARN_ON(!(fqd_a && fqd_sz)); - return 0; } RESERVEDMEM_OF_DECLARE(qman_fqd, "fsl,qman-fqd", qman_fqd); @@ -431,32 +452,13 @@ static int qman_pfdr(struct reserved_mem *rmem) } RESERVEDMEM_OF_DECLARE(qman_pfdr, "fsl,qman-pfdr", qman_pfdr); +#endif + static unsigned int qm_get_fqid_maxcnt(void) { return fqd_sz / 64; } -/* - * Flush this memory range from data cache so that QMAN originated - * transactions for this memory region could be marked non-coherent. - */ -static int zero_priv_mem(struct device *dev, struct device_node *node, - phys_addr_t addr, size_t sz) -{ - /* map as cacheable, non-guarded */ - void __iomem *tmpp = ioremap_prot(addr, sz, 0); - - if (!tmpp) - return -ENOMEM; - - memset_io(tmpp, 0, sz); - flush_dcache_range((unsigned long)tmpp, - (unsigned long)tmpp + sz); - iounmap(tmpp); - - return 0; -} - static void log_edata_bits(struct device *dev, u32 bit_count) { u32 i, j, mask = 0xffffffff; @@ -687,11 +689,12 @@ static int qman_resource_init(struct device *dev) static int fsl_qman_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; - struct device_node *node = dev->of_node; + struct device_node *mem_node, *node = dev->of_node; struct resource *res; int ret, err_irq; u16 id; u8 major, minor; + u64 size; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { @@ -727,10 +730,83 @@ static int fsl_qman_probe(struct platform_device *pdev) qm_channel_caam = QMAN_CHANNEL_CAAM_REV3; } - ret = zero_priv_mem(dev, node, fqd_a, fqd_sz); - WARN_ON(ret); - if (ret) - return -ENODEV; + if (fqd_a) { +#ifdef CONFIG_PPC + /* + * For PPC backward DT compatibility + * FQD memory MUST be zero'd by software + */ + zero_priv_mem(fqd_a, fqd_sz); +#else + WARN(1, "Unexpected archiceture using non shared-dma-mem reservations"); +#endif + } else { + /* + * Order of memory regions is assumed as FQD followed by PFDR + * in order to ensure allocations from the correct regions the + * driver initializes then allocates each piece in order + */ + ret = of_reserved_mem_device_init_by_idx(dev, dev->of_node, 0); + if (ret) { + dev_err(dev, "of_reserved_mem_device_init_by_idx(0) failed 0x%x\n", + ret); + return -ENODEV; + } + mem_node = of_parse_phandle(dev->of_node, "memory-region", 0); + if (mem_node) { + ret = of_property_read_u64(mem_node, "size", &size); + if (ret) { + dev_err(dev, "FQD: of_address_to_resource fails 0x%x\n", + ret); + return -ENODEV; + } + fqd_sz = size; + } else { + dev_err(dev, "No memory-region found for FQD\n"); + return -ENODEV; + } + if (!dma_zalloc_coherent(dev, fqd_sz, &fqd_a, 0)) { + dev_err(dev, "Alloc FQD memory failed\n"); + return -ENODEV; + } + + /* + * Disassociate the FQD reserved memory area from the device + * because a device can only have one DMA memory area. This + * should be fine since the memory is allocated and initialized + * and only ever accessed by the QMan device from now on + */ + of_reserved_mem_device_release(dev); + } + dev_dbg(dev, "Allocated FQD 0x%llx 0x%zx\n", fqd_a, fqd_sz); + + if (!pfdr_a) { + /* Setup PFDR memory */ + ret = of_reserved_mem_device_init_by_idx(dev, dev->of_node, 1); + if (ret) { + dev_err(dev, "of_reserved_mem_device_init(1) failed 0x%x\n", + ret); + return -ENODEV; + } + mem_node = of_parse_phandle(dev->of_node, "memory-region", 1); + if (mem_node) { + ret = of_property_read_u64(mem_node, "size", &size); + if (ret) { + dev_err(dev, "PFDR: of_address_to_resource fails 0x%x\n", + ret); + return -ENODEV; + } + pfdr_sz = size; + } else { + dev_err(dev, "No memory-region found for PFDR\n"); + return -ENODEV; + } + if (!dma_zalloc_coherent(dev, pfdr_sz, &pfdr_a, 0)) { + dev_err(dev, "Alloc PFDR Failed size 0x%zx\n", pfdr_sz); + return -ENODEV; + } + } + dev_info(dev, "Allocated PFDR 0x%llx 0x%zx\n", pfdr_a, pfdr_sz); ret = qman_init_ccsr(dev); if (ret) { diff --git a/drivers/soc/fsl/qbman/qman_priv.h b/drivers/soc/fsl/qbman/qman_priv.h index 5fe9faf..957ef54 100644 --- a/drivers/soc/fsl/qbman/qman_priv.h +++ b/drivers/soc/fsl/qbman/qman_priv.h @@ -28,13 +28,13 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - #include "dpaa_sys.h" #include #include #include +#include +#include #if defined(CONFIG_FSL_PAMU) #include diff --git a/drivers/soc/fsl/qbman/qman_test.h b/drivers/soc/fsl/qbman/qman_test.h index d5f8cb2..41bdbc48 100644 --- a/drivers/soc/fsl/qbman/qman_test.h +++ b/drivers/soc/fsl/qbman/qman_test.h @@ -30,7 +30,5 @@ #include "qman_priv.h" -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - int qman_test_stash(void); int qman_test_api(void); -- 2.7.4