From patchwork Wed Jun 10 08:03:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Igal.Liberman" X-Patchwork-Id: 482628 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 84682140297 for ; Wed, 10 Jun 2015 22:22:24 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4AAF11A2C5F for ; Wed, 10 Jun 2015 22:22:24 +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-by2on0127.outbound.protection.outlook.com [207.46.100.127]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 771D51A0F0D for ; Wed, 10 Jun 2015 22:10:24 +1000 (AEST) Received: from BY2PR03CA052.namprd03.prod.outlook.com (10.141.249.25) by BY2PR03MB380.namprd03.prod.outlook.com (10.242.237.23) with Microsoft SMTP Server (TLS) id 15.1.184.10; Wed, 10 Jun 2015 12:10:16 +0000 Received: from BL2FFO11FD028.protection.gbl (2a01:111:f400:7c09::107) by BY2PR03CA052.outlook.office365.com (2a01:111:e400:2c5d::25) with Microsoft SMTP Server (TLS) id 15.1.190.14 via Frontend Transport; Wed, 10 Jun 2015 12:10:09 +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 BL2FFO11FD028.mail.protection.outlook.com (10.173.161.107) with Microsoft SMTP Server (TLS) id 15.1.190.9 via Frontend Transport; Wed, 10 Jun 2015 12:10:07 +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 t5ACA4dd016915; Wed, 10 Jun 2015 05:10:04 -0700 From: Igal.Liberman To: Subject: [PATCH 07/12] fsl/fman: Add FMan MURAM support Date: Wed, 10 Jun 2015 11:03:05 +0300 Message-ID: <1433923385-22480-1-git-send-email-igal.liberman@freescale.com> X-Mailer: git-send-email 1.7.9.5 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD028; 1:Teiw7nIBIEbYzW/3SDGjWGfzi0u8MKfbvyCQasRjGX0t4OXhGEKm+vKKV8pqKRlKWeHTm8GYTx5ve7Ytr9jPgRld7mB76/tuKPIkxknMp8m5C6e50w4VL2Y4kbp8k7oBx3os57IynhuYaQPIcWUafZXKo+rDYTYqtCkpcWxVIdtJO9rIGXkwWDc8BpUOZKNvxSYyLRYGzDVh906MsBg/nGhnKb2x2evGR9IBy6tvX3FrJZ8BFDKTNjolYdpZUOjEvWB+H0+pseSm0OIIeedViOFKPKYnCVjVA4hYtPJSzqxPYiWzeE8fQGdaHT7YJuj+3CXIAmMqO+iLikcZ5wKQLw== X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(339900001)(189002)(199003)(189998001)(87936001)(575784001)(62966003)(50986999)(2351001)(50466002)(107886002)(5001960100002)(77096005)(19580405001)(86362001)(229853001)(50226001)(47776003)(48376002)(46102003)(105606002)(36756003)(104016003)(33646002)(106466001)(53806999)(5001920100001)(6806004)(110136002)(85426001)(77156002)(43066003)(4001430100001); DIR:OUT; SFP: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vIoyLlVXXXnmo/tcPfdtwaiFAQ7GyuqJENbqStKv21lIyu/6IUe X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB380; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(520003)(3002001); SRVR:BY2PR03MB380; BCL:0; PCL:0; RULEID:; SRVR:BY2PR03MB380; X-Forefront-PRVS: 06036BD506 X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB380; 9:0fA7QZAjxOK8g8PBxDlifgGyyGDfiQkew438dShbd4c1QMtB5npGoAdFtCRRaz194j0nkz/HIJrqzOHFY3q1XD2kA8GK3D1E4jbWaa9Mxo34ww24Q32nN7fpSN3oYDlbedCmqFaniuU7qIFxi8OyGSyfweeriYaJgpnzl7h2lP10YGETPKQd72/vfZVtZN4BhBsNswxoFYDkxT9ICEsBda7ANoy1Ykx4iURdCLJ4Nhr3M3Z0Q6f8dnIOKVt0S0rNmHLVkN1dxpChNMjCtVvAsxxjZlhHvApzQboPnswJy1vVyW17f+Lb65JVTChhKmZjYsKlqZbEdCkWaI1tmyCUipdjmv5Ix3XTQOk+UTLHhhfj32UAh/l/sVaWzKq/o4ji92DvCYy3+eqbtLwuE/bf/MJoQR7FbdlMH4BbBHaYLoYN9zXe7S0RBwaGHWe+BjCf7HkX99OjeSYKfNcXm6tAhrbNS66Tn+RWUZdiuYKm5hma4wfah+uBHI9v7zX0F2xAPZRgyT+FaUE3oNKh5iwFqBEESKBm9T+19AV/Wqoe86aig8krSa3CkjrvejO/MW859clIpkeumUyTco/yHPfftV0XVnyFICZ07Rpc1DJvV9e6fHTYpUO+I/x97orWqyWhg10Cx5zVh2lpdJ/6MyVVMnkOZZ8l6gm9rd/twHR/x1lkYwVnww46v0EPiCfosed9ElDm30K1cUMwIuyocLFy5ZD1px7LxTpLrKQvnEKYElMytal5vpnnfT6lAM0cKfHUlZPikYW5ol/ZBHHcozMFovdAUb2SgGOw0deA/kzrnSUt20T98FM2QxJ+qLyj+vWMSjnb45O5En4Zs55RPUMooBKT5vl+5UW1VNselr8YR/Fj8gY3ocGzmh06APWlXXTyUCWvfKCkeJQS8ArJvcrjDg== X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB380; 3:ZFcmwEVadcjPKxIogH698NaY2DTix3gDSqZc6jfZstas55U6QCs4Si9/tHuAjBwmtvYwZlKc6MRh5o/zg8sHw9K7XNmcd0xIWBRUOqmJeTZQI+oCs9YkKUN7PRph5MV4TCthKRbBCb70LsDpL+gYOg==; 10:fYXCawxpiw452us1OfKUlJT12VAq6HSW5GS6GsPXwb7XtSlzmMKdVOYmtVyAeRu6Uf/fvhukhIr4FtOQLG6HgkAOETCmQv/zBvCgbgQ2FRI=; 6:Ijxxylq8YXl9sIPEdaVv+kCvNinW+7r2rjipxPKnp/aPtrsUr1zfNhvgj82vAdEi X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2015 12:10:07.4080 (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: BY2PR03MB380 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: igal.liberman@freescale.com Cc: scottwood@freescale.com, Igal Liberman , linuxppc-dev@lists.ozlabs.org, madalin.bucur@freescale.com 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 | 127 ++++++++++++++++++++ .../net/ethernet/freescale/fman/inc/fm_muram_ext.h | 103 ++++++++++++++++ 4 files changed, 235 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 1841b03..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..f62042a --- /dev/null +++ b/drivers/net/ethernet/freescale/fman/fm_muram.c @@ -0,0 +1,127 @@ +/* + * 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; + } + + memset_io(vaddr, 0, (int)size); + + 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); +} + +unsigned long fm_muram_vbase_to_offset(struct muram_info *p_muram, + unsigned long vaddr) +{ + return vaddr - (unsigned long)p_muram->vbase; +} + +unsigned long fm_muram_offset_to_vbase(struct muram_info *p_muram, + unsigned long offset) +{ + return offset + (unsigned long)p_muram->vbase; +} + +int 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 -ENOMEM; + + memset_io((void __iomem *)vaddr, 0, (int)size); + + return fm_muram_vbase_to_offset(p_muram, vaddr); +} + +void fm_muram_free_mem(struct muram_info *p_muram, uint32_t offset, + uint32_t size) +{ + unsigned long addr = fm_muram_offset_to_vbase(p_muram, offset); + + 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..bc25764 --- /dev/null +++ b/drivers/net/ethernet/freescale/fman/inc/fm_muram_ext.h @@ -0,0 +1,103 @@ +/* + * 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" + +#define FM_MURAM_INVALID_ALLOCATION -1 + +/* 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_vbase_to_offset + * Description gives the offset of the memory region in the MURAM + * Param[in] p_muram - FM-MURAM module pointer. + * Param[in] vaddr - the virtual address of the memoru block + * Return the offset of the memory block + */ +unsigned long fm_muram_vbase_to_offset(struct muram_info *p_muram, + unsigned long vaddr); + +/* Function fm_muram_vbase_to_offset + * Description gives the address of the memory region from specific oddset + * Param[in] p_muram - FM-MURAM module pointer. + * Param[in] offset - the offset of the memory block + * Return the address of the memory blocl + */ +unsigned long fm_muram_offset_to_vbase(struct muram_info *p_muram, + unsigned long offset); + +/* 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. + */ +int 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] offset - offset of the memory region to be freed. + * Param[in] size - size of the memory to be freed. + */ +void fm_muram_free_mem(struct muram_info *p_muram, uint32_t offset, + uint32_t size); + +#endif /* __FM_MURAM_EXT */