From patchwork Wed Apr 29 09:28:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Igal.Liberman" X-Patchwork-Id: 466052 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D871F14032B for ; Wed, 29 Apr 2015 23:44:46 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id BE4C11A2AE9 for ; Wed, 29 Apr 2015 23:44:46 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from na01-by2-obe.outbound.protection.outlook.com (mail-by2on0129.outbound.protection.outlook.com [207.46.100.129]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 95A2E1A0D0F for ; Wed, 29 Apr 2015 23:35:34 +1000 (AEST) Received: from BLUPR0301CA0018.namprd03.prod.outlook.com (25.162.113.156) by BL2PR03MB547.namprd03.prod.outlook.com (10.141.90.20) with Microsoft SMTP Server (TLS) id 15.1.125.19; Wed, 29 Apr 2015 13:35:28 +0000 Received: from BN1BFFO11FD016.protection.gbl (2a01:111:f400:7c10::1:107) by BLUPR0301CA0018.outlook.office365.com (2a01:111:e400:5259::28) with Microsoft SMTP Server (TLS) id 15.1.130.23 via Frontend Transport; Wed, 29 Apr 2015 13:35:27 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BN1BFFO11FD016.mail.protection.outlook.com (10.58.144.79) with Microsoft SMTP Server (TLS) id 15.1.160.8 via Frontend Transport; Wed, 29 Apr 2015 13:35:26 +0000 Received: from b31950-Sun-Ultra-20-Workstation.fil.ea.freescale.net ([10.96.120.115]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id t3TDZNb8008796; Wed, 29 Apr 2015 06:35:24 -0700 From: Igal.Liberman To: Subject: [RFC,v3,07/12] fsl/fman: Add FMan MURAM support Date: Wed, 29 Apr 2015 12:28:13 +0300 Message-ID: <1430299693-29263-1-git-send-email-igal.liberman@freescale.com> X-Mailer: git-send-email 1.7.9.5 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; BMV:1; SFV:NSPM; SFS:(10019020)(6009001)(339900001)(189002)(199003)(86362001)(104016003)(575784001)(229853001)(77156002)(110136001)(92566002)(2351001)(77096005)(105606002)(106466001)(47776003)(50466002)(50986999)(33646002)(19580395003)(46102003)(50226001)(19580405001)(87936001)(62966003)(48376002)(36756003)(6806004)(85426001)(142933001)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:BL2PR03MB547; H:az84smr01.freescale.net; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB547; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5002010)(5005006); SRVR:BL2PR03MB547; BCL:0; PCL:0; RULEID:; SRVR:BL2PR03MB547; X-Forefront-PRVS: 05610E64EE X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2015 13:35:26.6044 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR03MB547 Cc: Igal Liberman , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, madalin.bucur@freescale.com X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Igal Liberman Add Frame Manager Multi-User RAM support. Signed-off-by: Igal Liberman --- drivers/net/ethernet/freescale/fman/Kconfig | 1 + drivers/net/ethernet/freescale/fman/Makefile | 6 +- drivers/net/ethernet/freescale/fman/fm_muram.c | 114 ++++++++++++++++++++ .../net/ethernet/freescale/fman/inc/fm_muram_ext.h | 89 +++++++++++++++ 4 files changed, 208 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ethernet/freescale/fman/fm_muram.c create mode 100644 drivers/net/ethernet/freescale/fman/inc/fm_muram_ext.h diff --git a/drivers/net/ethernet/freescale/fman/Kconfig b/drivers/net/ethernet/freescale/fman/Kconfig index af42c3a..825a0d5 100644 --- a/drivers/net/ethernet/freescale/fman/Kconfig +++ b/drivers/net/ethernet/freescale/fman/Kconfig @@ -1,6 +1,7 @@ config FSL_FMAN bool "FMan support" depends on FSL_SOC || COMPILE_TEST + select GENERIC_ALLOCATOR default n help Freescale Data-Path Acceleration Architecture Frame Manager diff --git a/drivers/net/ethernet/freescale/fman/Makefile b/drivers/net/ethernet/freescale/fman/Makefile index 534d1ed..55c91bd 100644 --- a/drivers/net/ethernet/freescale/fman/Makefile +++ b/drivers/net/ethernet/freescale/fman/Makefile @@ -1,8 +1,10 @@ -subdir-ccflags-y += -I$(srctree)/drivers/net/ethernet/freescale/fman/flib +subdir-ccflags-y += -I$(srctree)/drivers/net/ethernet/freescale/fman/flib \ + -I$(srctree)/drivers/net/ethernet/freescale/fman/inc \ + -I$(srctree)/drivers/net/ethernet/freescale/fman obj-y += fsl_fman.o -fsl_fman-objs := fman.o +fsl_fman-objs := fman.o fm_muram.o obj-y += port/ obj-y += mac/ diff --git a/drivers/net/ethernet/freescale/fman/fm_muram.c b/drivers/net/ethernet/freescale/fman/fm_muram.c new file mode 100644 index 0000000..2bca725 --- /dev/null +++ b/drivers/net/ethernet/freescale/fman/fm_muram.c @@ -0,0 +1,114 @@ +/* + * Copyright 2008-2015 Freescale Semiconductor Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Freescale Semiconductor nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* FM MURAM ... */ +#include "fm_muram_ext.h" + +#include +#include +#include +#include + +struct muram_info { + struct gen_pool *pool; + void __iomem *vbase; + uint64_t size; + phys_addr_t pbase; +}; + +struct muram_info *fm_muram_init(phys_addr_t base, uint64_t size) +{ + struct muram_info *p_muram; + void __iomem *vaddr; + int ret; + + p_muram = kzalloc(sizeof(*p_muram), GFP_KERNEL); + if (!p_muram) + return NULL; + + p_muram->pool = gen_pool_create(ilog2(64), -1); + if (!p_muram->pool) { + pr_err("%s(): MURAM pool create failed\n", __func__); + return NULL; + } + + vaddr = ioremap(base, size); + if (!vaddr) { + pr_err("%s(): MURAM ioremap failed\n", __func__); + return NULL; + } + + ret = gen_pool_add_virt(p_muram->pool, (unsigned long)vaddr, + base, size, -1); + if (ret < 0) { + pr_err("%s(): MURAM pool add failed\n", __func__); + iounmap(vaddr); + return NULL; + } + + p_muram->vbase = vaddr; + p_muram->pbase = base; + return p_muram; +} + +void fm_muram_free(struct muram_info *p_muram) +{ + /* Destroy pool */ + gen_pool_destroy(p_muram->pool); + /* Unmap memory */ + iounmap(p_muram->vbase); + /* Free pointer */ + kfree(p_muram); +} + +void fm_muram_clear(struct muram_info *p_muram) +{ + memset_io(p_muram->vbase, 0, p_muram->size); +} + +unsigned long fm_muram_alloc(struct muram_info *p_muram, uint32_t size) +{ + unsigned long vaddr; + + vaddr = gen_pool_alloc(p_muram->pool, size); + if (!vaddr) + return 0; + + return vaddr; +} + +void fm_muram_free_mem(struct muram_info *p_muram, unsigned long addr, + uint32_t size) +{ + gen_pool_free(p_muram->pool, addr, size); +} + diff --git a/drivers/net/ethernet/freescale/fman/inc/fm_muram_ext.h b/drivers/net/ethernet/freescale/fman/inc/fm_muram_ext.h new file mode 100644 index 0000000..48c066a --- /dev/null +++ b/drivers/net/ethernet/freescale/fman/inc/fm_muram_ext.h @@ -0,0 +1,89 @@ +/* + * Copyright 2008-2015 Freescale Semiconductor Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Freescale Semiconductor nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * + * ALTERNATIVELY, this software may be distributed under the terms of the + * GNU General Public License ("GPL") as published by the Free Software + * Foundation, either version 2 of that License or (at your option) any + * later version. + * + * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* File fm_muram_ext.h + * Description FM MURAM Application Programming Interface. + */ +#ifndef __FM_MURAM_EXT +#define __FM_MURAM_EXT + +#include "linux/types.h" + +/* Structure for FM MURAM information */ +struct muram_info; + +/* FM MURAM initialization API functions, definitions and enums */ + +/* Function fm_muram_init + * Description Creates partition in the MURAM. + * The routine returns a pointer to the MURAM partition. + * This pointer must be passed as first parameter to all other + * FM-MURAM function calls. + * No actual initialization or configuration of FM_MURAM hardware + * is done by this routine. + * Param[in] base - Pointer to base of memory mapped FM-MURAM. + * Param[in] size - Size of the FM-MURAM partition. + * Return pointer to FM-MURAM object, or NULL for Failure. + */ +struct muram_info *fm_muram_init(phys_addr_t base, uint64_t size); + +/* Function fm_muram_free + * Description Frees all resources that were assigned to FM-MURAM module. + * Calling this routine invalidates the pointer. + * Param[in] p_muram - FM-MURAM module pointer. + */ +void fm_muram_free(struct muram_info *p_muram); + +/* Function fm_muram_clear + * Description Set zeros to MURAM memory + * Param[in] p_muram - FM-MURAM module pointer. + */ +void fm_muram_clear(struct muram_info *p_muram); + +/* Function fm_muram_alloc + * Description Allocate some memory from FM-MURAM partition. + * Param[in] p_muram - FM-MURAM module pointer. + * Param[in] size - size of the memory to be allocated. + * Return address of the allocated memory; NULL otherwise. + */ +unsigned long fm_muram_alloc(struct muram_info *p_muram, uint32_t size); + +/* Function fm_muram_free_mem + * Description Free an allocated memory from FM-MURAM partition. + * Param[in] p_muram - FM-MURAM module pointer. + * Param[in] addr - address to be freed. + * Param[in] size - size of the memory to be freed. + */ +void fm_muram_free_mem(struct muram_info *p_muram, unsigned long addr, + uint32_t size); + +#endif /* __FM_MURAM_EXT */