From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ferruh Yigit Subject: Re: [PATCH 02/32] drivers/common: introducing dpaa2 mc driver Date: Tue, 6 Dec 2016 19:48:43 +0000 Message-ID: References: <1480875447-23680-1-git-send-email-hemant.agrawal@nxp.com> <1480875447-23680-3-git-send-email-hemant.agrawal@nxp.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Cc: thomas.monjalon@6wind.com, bruce.richardson@intel.com, shreyansh.jain@nxp.com, Cristian Sovaiala To: Hemant Agrawal , dev@dpdk.org Return-path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 7C9242BF6 for ; Tue, 6 Dec 2016 20:48:49 +0100 (CET) In-Reply-To: <1480875447-23680-3-git-send-email-hemant.agrawal@nxp.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On 12/4/2016 6:16 PM, Hemant Agrawal wrote: > This patch intoduces the DPAA2 MC(Management complex Driver) > > This driver is common to be used by various DPAA2 net, crypto > and other drivers > > Signed-off-by: Cristian Sovaiala > [Hemant:rebase and conversion to library for DPDK] Is this note about how work share done? Do we need this in the history? > Signed-off-by: Hemant Agrawal > --- > config/defconfig_arm64-dpaa2-linuxapp-gcc | 7 +- > drivers/Makefile | 1 + > drivers/common/Makefile | 36 +++++ > drivers/common/dpaa2/Makefile | 36 +++++ > drivers/common/dpaa2/mc/Makefile | 53 ++++++ > drivers/common/dpaa2/mc/dpaa2_mc_version.map | 4 + > drivers/common/dpaa2/mc/fsl_mc_cmd.h | 231 +++++++++++++++++++++++++++ > drivers/common/dpaa2/mc/fsl_mc_sys.h | 98 ++++++++++++ > drivers/common/dpaa2/mc/mc_sys.c | 126 +++++++++++++++ Are drivers/common/dpaa2/* files are shared code or implemented for DPDK, I can see Linux version is different. If these are re-implemented for DPDK, let's follow DPDK coding rules for a clean start, what do you think? > 9 files changed, 591 insertions(+), 1 deletion(-) > create mode 100644 drivers/common/Makefile > create mode 100644 drivers/common/dpaa2/Makefile > create mode 100644 drivers/common/dpaa2/mc/Makefile > create mode 100644 drivers/common/dpaa2/mc/dpaa2_mc_version.map > create mode 100644 drivers/common/dpaa2/mc/fsl_mc_cmd.h > create mode 100644 drivers/common/dpaa2/mc/fsl_mc_sys.h > create mode 100644 drivers/common/dpaa2/mc/mc_sys.c > > diff --git a/config/defconfig_arm64-dpaa2-linuxapp-gcc b/config/defconfig_arm64-dpaa2-linuxapp-gcc > index 66df54c..00f207e 100644 > --- a/config/defconfig_arm64-dpaa2-linuxapp-gcc > +++ b/config/defconfig_arm64-dpaa2-linuxapp-gcc > @@ -1,6 +1,7 @@ > # BSD LICENSE > # > -# Copyright(c) 2016 Freescale Semiconductor, Inc. All rights reserved. > +# Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved. > +# Copyright (c) 2016 NXP. All rights reserved. > # > # Redistribution and use in source and binary forms, with or without > # modification, are permitted provided that the following conditions > @@ -40,3 +41,7 @@ CONFIG_RTE_ARCH_ARM_TUNE="cortex-a57+fp+simd" > # > CONFIG_RTE_MAX_LCORE=8 > CONFIG_RTE_MAX_NUMA_NODES=1 > + > +# Compile software PMD backed by NXP DPAA2 files > +# > +CONFIG_RTE_LIBRTE_DPAA2_PMD=y Currently how it works is, default value of the config in "common_base" and it is overwritten in specific config files. So this config option also should go to "common_base" as disabled by default. And the other config option too, mentioned in the documentation. > diff --git a/drivers/Makefile b/drivers/Makefile > index 81c03a8..d5580f6 100644 > --- a/drivers/Makefile > +++ b/drivers/Makefile > @@ -31,6 +31,7 @@ > > include $(RTE_SDK)/mk/rte.vars.mk > > +DIRS-y += common > DIRS-y += net > DIRS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += crypto > > diff --git a/drivers/common/Makefile b/drivers/common/Makefile > new file mode 100644 > index 0000000..0c3f35f > --- /dev/null > +++ b/drivers/common/Makefile > @@ -0,0 +1,36 @@ > +# BSD LICENSE > +# > +# Copyright(c) 2016 NXP. All rights reserved. > +# All rights reserved. > +# > +# 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 NXP nor the names of its > +# contributors may be used to endorse or promote products derived > +# from this software without specific prior written permission. > +# > +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > +# "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 THE COPYRIGHT > +# OWNER OR CONTRIBUTORS 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. > + > +include $(RTE_SDK)/mk/rte.vars.mk > + > +DIRS-$(CONFIG_RTE_LIBRTE_DPAA2_PMD) += dpaa2 > + > +include $(RTE_SDK)/mk/rte.subdir.mk > diff --git a/drivers/common/dpaa2/Makefile b/drivers/common/dpaa2/Makefile > new file mode 100644 > index 0000000..a4f80c1 > --- /dev/null > +++ b/drivers/common/dpaa2/Makefile > @@ -0,0 +1,36 @@ > +# BSD LICENSE > +# > +# Copyright(c) 2016 NXP. All rights reserved. > +# All rights reserved. > +# > +# 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 NXP nor the names of its > +# contributors may be used to endorse or promote products derived > +# from this software without specific prior written permission. > +# > +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > +# "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 THE COPYRIGHT > +# OWNER OR CONTRIBUTORS 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. > + > +include $(RTE_SDK)/mk/rte.vars.mk > + > +DIRS-$(CONFIG_RTE_LIBRTE_DPAA2_PMD) += mc > + > +include $(RTE_SDK)/mk/rte.subdir.mk > diff --git a/drivers/common/dpaa2/mc/Makefile b/drivers/common/dpaa2/mc/Makefile > new file mode 100644 > index 0000000..9632168 > --- /dev/null > +++ b/drivers/common/dpaa2/mc/Makefile > @@ -0,0 +1,53 @@ > +# BSD LICENSE > +# > +# Copyright(c) 2016 NXP. All rights reserved. > +# All rights reserved. > +# > +# 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 NXP nor the names of its > +# contributors may be used to endorse or promote products derived > +# from this software without specific prior written permission. > +# > +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > +# "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 THE COPYRIGHT > +# OWNER OR CONTRIBUTORS 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. > + > +include $(RTE_SDK)/mk/rte.vars.mk > +RTE_SDK_MC=$(RTE_SDK)/drivers/common/dpaa2 > + > +# > +# library name > +# > +LIB = libdpaa2_mc.a Not sure about this name, what do you think sticking the name used for pmd, like: librte_pmd_dpaa2_mc.a ? > + > +CFLAGS += -O3 > +CFLAGS += $(WERROR_FLAGS) > +CFLAGS +=-Wno-strict-aliasing > + > +CFLAGS += -I$(RTE_SDK_MC)/mc > +EXPORT_MAP := dpaa2_mc_version.map Same comment for version file naming, rte_pmd_dpaa2_mc_version.map ? > + > +LIBABIVER := 1 > + > +SRCS-y += \ > + mc_sys.c Also this is fine, since this folder included only if CONFIG_RTE_LIBRTE_DPAA2_PMD=y, to be consistent for rest of the Makefiles: SRCS-$(CONFIG_RTE_LIBRTE_DPAA2_PMD) += mc_sys.c > + > + > +include $(RTE_SDK)/mk/rte.lib.mk > diff --git a/drivers/common/dpaa2/mc/dpaa2_mc_version.map b/drivers/common/dpaa2/mc/dpaa2_mc_version.map > new file mode 100644 > index 0000000..31eca32 > --- /dev/null > +++ b/drivers/common/dpaa2/mc/dpaa2_mc_version.map > @@ -0,0 +1,4 @@ > +DPDK_17.02 { > + > + local: *; > +}; > diff --git a/drivers/common/dpaa2/mc/fsl_mc_cmd.h b/drivers/common/dpaa2/mc/fsl_mc_cmd.h > new file mode 100644 > index 0000000..cbd3995 > --- /dev/null > +++ b/drivers/common/dpaa2/mc/fsl_mc_cmd.h > @@ -0,0 +1,231 @@ > +/* Copyright 2013-2016 Freescale Semiconductor Inc. > + * Copyright (c) 2016 NXP. > + * > + * 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 the above-listed copyright holders nor the > + * names of any 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT HOLDERS OR CONTRIBUTORS 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. > + */ > +#ifndef __FSL_MC_CMD_H > +#define __FSL_MC_CMD_H > + > +#define MC_CMD_NUM_OF_PARAMS 7 > + > +#define MAKE_UMASK64(_width) \ > + ((uint64_t)((_width) < 64 ? ((uint64_t)1 << (_width)) - 1 : \ > + (uint64_t)-1)) > + > +static inline uint64_t mc_enc(int lsoffset, int width, uint64_t val) > +{ > + return (uint64_t)(((uint64_t)val & MAKE_UMASK64(width)) << lsoffset); > +} > + > +static inline uint64_t mc_dec(uint64_t val, int lsoffset, int width) > +{ > + return (uint64_t)((val >> lsoffset) & MAKE_UMASK64(width)); > +} > + > +struct mc_command { > + uint64_t header; > + uint64_t params[MC_CMD_NUM_OF_PARAMS]; > +}; > + > +/** > + * enum mc_cmd_status - indicates MC status at command response > + * @MC_CMD_STATUS_OK: Completed successfully > + * @MC_CMD_STATUS_READY: Ready to be processed > + * @MC_CMD_STATUS_AUTH_ERR: Authentication error > + * @MC_CMD_STATUS_NO_PRIVILEGE: No privilege > + * @MC_CMD_STATUS_DMA_ERR: DMA or I/O error > + * @MC_CMD_STATUS_CONFIG_ERR: Configuration error > + * @MC_CMD_STATUS_TIMEOUT: Operation timed out > + * @MC_CMD_STATUS_NO_RESOURCE: No resources > + * @MC_CMD_STATUS_NO_MEMORY: No memory available > + * @MC_CMD_STATUS_BUSY: Device is busy > + * @MC_CMD_STATUS_UNSUPPORTED_OP: Unsupported operation > + * @MC_CMD_STATUS_INVALID_STATE: Invalid state > + */ > +enum mc_cmd_status { > + MC_CMD_STATUS_OK = 0x0, > + MC_CMD_STATUS_READY = 0x1, > + MC_CMD_STATUS_AUTH_ERR = 0x3, > + MC_CMD_STATUS_NO_PRIVILEGE = 0x4, > + MC_CMD_STATUS_DMA_ERR = 0x5, > + MC_CMD_STATUS_CONFIG_ERR = 0x6, > + MC_CMD_STATUS_TIMEOUT = 0x7, > + MC_CMD_STATUS_NO_RESOURCE = 0x8, > + MC_CMD_STATUS_NO_MEMORY = 0x9, > + MC_CMD_STATUS_BUSY = 0xA, > + MC_CMD_STATUS_UNSUPPORTED_OP = 0xB, > + MC_CMD_STATUS_INVALID_STATE = 0xC > +}; > + > +/* MC command flags */ > + > +/** > + * High priority flag > + */ > +#define MC_CMD_FLAG_PRI 0x00008000 > +/** > + * Command completion flag > + */ > +#define MC_CMD_FLAG_INTR_DIS 0x01000000 > + > +/** > + * Command ID field offset > + */ > +#define MC_CMD_HDR_CMDID_O 48 > +/** > + * Command ID field size > + */ > +#define MC_CMD_HDR_CMDID_S 16 > +/** > + * Token field offset > + */ > +#define MC_CMD_HDR_TOKEN_O 32 > +/** > + * Token field size > + */ > +#define MC_CMD_HDR_TOKEN_S 16 > +/** > + * Status field offset > + */ > +#define MC_CMD_HDR_STATUS_O 16 > +/** > + * Status field size > + */ > +#define MC_CMD_HDR_STATUS_S 8 > +/** > + * Flags field offset > + */ > +#define MC_CMD_HDR_FLAGS_O 0 > +/** > + * Flags field size > + */ > +#define MC_CMD_HDR_FLAGS_S 32 > +/** > + * Command flags mask > + */ > +#define MC_CMD_HDR_FLAGS_MASK 0xFF00FF00 > + > +#define MC_CMD_HDR_READ_STATUS(_hdr) \ > + ((enum mc_cmd_status)mc_dec((_hdr), \ > + MC_CMD_HDR_STATUS_O, MC_CMD_HDR_STATUS_S)) > + > +#define MC_CMD_HDR_READ_TOKEN(_hdr) \ > + ((uint16_t)mc_dec((_hdr), MC_CMD_HDR_TOKEN_O, MC_CMD_HDR_TOKEN_S)) > + > +#define MC_PREP_OP(_ext, _param, _offset, _width, _type, _arg) \ > + ((_ext)[_param] |= cpu_to_le64(mc_enc((_offset), (_width), _arg))) > + > +#define MC_EXT_OP(_ext, _param, _offset, _width, _type, _arg) \ > + (_arg = (_type)mc_dec(cpu_to_le64(_ext[_param]), (_offset), (_width))) > + > +#define MC_CMD_OP(_cmd, _param, _offset, _width, _type, _arg) \ > + ((_cmd).params[_param] |= mc_enc((_offset), (_width), _arg)) > + > +#define MC_RSP_OP(_cmd, _param, _offset, _width, _type, _arg) \ > + (_arg = (_type)mc_dec(_cmd.params[_param], (_offset), (_width))) > + > +/* cmd, param, offset, width, type, arg_name */ > +#define CMD_CREATE_RSP_GET_OBJ_ID_PARAM0(cmd, object_id) \ > + MC_RSP_OP(cmd, 0, 0, 32, uint32_t, object_id) > + > +/* cmd, param, offset, width, type, arg_name */ > +#define CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd, object_id) \ > + MC_CMD_OP(cmd, 0, 0, 32, uint32_t, object_id) > + > +static inline uint64_t mc_encode_cmd_header(uint16_t cmd_id, > + uint32_t cmd_flags, > + uint16_t token) > +{ > + uint64_t hdr; > + > + hdr = mc_enc(MC_CMD_HDR_CMDID_O, MC_CMD_HDR_CMDID_S, cmd_id); > + hdr |= mc_enc(MC_CMD_HDR_FLAGS_O, MC_CMD_HDR_FLAGS_S, > + (cmd_flags & MC_CMD_HDR_FLAGS_MASK)); > + hdr |= mc_enc(MC_CMD_HDR_TOKEN_O, MC_CMD_HDR_TOKEN_S, token); > + hdr |= mc_enc(MC_CMD_HDR_STATUS_O, MC_CMD_HDR_STATUS_S, > + MC_CMD_STATUS_READY); > + > + return hdr; > +} > + > +/** > + * mc_write_command - writes a command to a Management Complex (MC) portal > + * > + * @portal: pointer to an MC portal > + * @cmd: pointer to a filled command > + */ > +static inline void mc_write_command(struct mc_command __iomem *portal, > + struct mc_command *cmd) > +{ > + int i; > + uint32_t word; > + > + /* copy command parameters into the portal */ > + for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++) > + iowrite64(cmd->params[i], &portal->params[i]); > + > + /* submit the command by writing the header */ > + word = (uint32_t)mc_dec(cmd->header, 32, 32); > + iowrite32(word, (((uint32_t *)&portal->header) + 1)); > + > + word = (uint32_t)mc_dec(cmd->header, 0, 32); > + iowrite32(word, (uint32_t *)&portal->header); > +} > + > +/** > + * mc_read_response - reads the response for the last MC command from a > + * Management Complex (MC) portal > + * > + * @portal: pointer to an MC portal > + * @resp: pointer to command response buffer > + * > + * Returns MC_CMD_STATUS_OK on Success; Error code otherwise. > + */ > +static inline enum mc_cmd_status mc_read_response( > + struct mc_command __iomem *portal, > + struct mc_command *resp) > +{ > + int i; > + enum mc_cmd_status status; > + > + /* Copy command response header from MC portal: */ > + resp->header = ioread64(&portal->header); > + status = MC_CMD_HDR_READ_STATUS(resp->header); > + if (status != MC_CMD_STATUS_OK) > + return status; > + > + /* Copy command response data from MC portal: */ > + for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++) > + resp->params[i] = ioread64(&portal->params[i]); > + > + return status; > +} > + > +#endif /* __FSL_MC_CMD_H */ > diff --git a/drivers/common/dpaa2/mc/fsl_mc_sys.h b/drivers/common/dpaa2/mc/fsl_mc_sys.h > new file mode 100644 > index 0000000..d9d43e5 > --- /dev/null > +++ b/drivers/common/dpaa2/mc/fsl_mc_sys.h > @@ -0,0 +1,98 @@ > +/* Copyright 2013-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 the above-listed copyright holders nor the > + * names of any 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT HOLDERS OR CONTRIBUTORS 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. > + */ > +#ifndef _FSL_MC_SYS_H > +#define _FSL_MC_SYS_H > + > +#ifdef __linux_driver__ > + > +#include > +#include > +#include > + > +struct fsl_mc_io { > + void *regs; > +}; > + > +#ifndef ENOTSUP > +#define ENOTSUP 95 > +#endif > + > +#define ioread64(_p) readq(_p) > +#define iowrite64(_v, _p) writeq(_v, _p) > + > +#else /* __linux_driver__ */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define cpu_to_le64(x) __cpu_to_le64(x) > +#ifndef dmb > +#define dmb() {__asm__ __volatile__("" : : : "memory"); } > +#endif > +#define __iormb() dmb() > +#define __iowmb() dmb() > +#define __arch_getq(a) (*(volatile unsigned long *)(a)) > +#define __arch_putq(v, a) (*(volatile unsigned long *)(a) = (v)) > +#define __arch_putq32(v, a) (*(volatile unsigned int *)(a) = (v)) > +#define readq(c) \ > + ({ uint64_t __v = __arch_getq(c); __iormb(); __v; }) > +#define writeq(v, c) \ > + ({ uint64_t __v = v; __iowmb(); __arch_putq(__v, c); __v; }) > +#define writeq32(v, c) \ > + ({ uint32_t __v = v; __iowmb(); __arch_putq32(__v, c); __v; }) > +#define ioread64(_p) readq(_p) > +#define iowrite64(_v, _p) writeq(_v, _p) > +#define iowrite32(_v, _p) writeq32(_v, _p) > +#define __iomem > + > +struct fsl_mc_io { > + void *regs; > +}; > + > +#ifndef ENOTSUP > +#define ENOTSUP 95 > +#endif > + > +/*GPP is supposed to use MC commands with low priority*/ > +#define CMD_PRI_LOW 0 /*!< Low Priority command indication */ > + > +struct mc_command; > + > +int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd); > + > +#endif /* __linux_driver__ */ > + > +#endif /* _FSL_MC_SYS_H */ > diff --git a/drivers/common/dpaa2/mc/mc_sys.c b/drivers/common/dpaa2/mc/mc_sys.c > new file mode 100644 > index 0000000..e12a18b > --- /dev/null > +++ b/drivers/common/dpaa2/mc/mc_sys.c > @@ -0,0 +1,126 @@ > +/* Copyright 2013-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 the above-listed copyright holders nor the > + * names of any 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 THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT HOLDERS OR CONTRIBUTORS 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. > + */ > +#include > +#include > + > +/** User space framework uses MC Portal in shared mode. Following change > +* introduces lock in MC FLIB > +*/ > + > +/** > +* The mc_spinlock_t type. > +*/ > +typedef struct { > + volatile int locked; /**< lock status 0 = unlocked, 1 = locked */ > +} mc_spinlock_t; > + > +/** > +* A static spinlock initializer. > +*/ > +static mc_spinlock_t mc_portal_lock = { 0 }; > + > +static inline void mc_pause(void) {} > + > +static inline void mc_spinlock_lock(mc_spinlock_t *sl) > +{ > + while (__sync_lock_test_and_set(&sl->locked, 1)) > + while (sl->locked) > + mc_pause(); > +} > + > +static inline void mc_spinlock_unlock(mc_spinlock_t *sl) > +{ > + __sync_lock_release(&sl->locked); > +} > + > +static int mc_status_to_error(enum mc_cmd_status status) > +{ > + switch (status) { > + case MC_CMD_STATUS_OK: > + return 0; > + case MC_CMD_STATUS_AUTH_ERR: > + return -EACCES; /* Token error */ > + case MC_CMD_STATUS_NO_PRIVILEGE: > + return -EPERM; /* Permission denied */ > + case MC_CMD_STATUS_DMA_ERR: > + return -EIO; /* Input/Output error */ > + case MC_CMD_STATUS_CONFIG_ERR: > + return -EINVAL; /* Device not configured */ > + case MC_CMD_STATUS_TIMEOUT: > + return -ETIMEDOUT; /* Operation timed out */ > + case MC_CMD_STATUS_NO_RESOURCE: > + return -ENAVAIL; /* Resource temporarily unavailable */ > + case MC_CMD_STATUS_NO_MEMORY: > + return -ENOMEM; /* Cannot allocate memory */ > + case MC_CMD_STATUS_BUSY: > + return -EBUSY; /* Device busy */ > + case MC_CMD_STATUS_UNSUPPORTED_OP: > + return -ENOTSUP; /* Operation not supported by device */ > + case MC_CMD_STATUS_INVALID_STATE: > + return -ENODEV; /* Invalid device state */ > + default: > + break; > + } > + > + /* Not expected to reach here */ > + return -EINVAL; > +} > + > +int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd) > +{ > + enum mc_cmd_status status; > + > + if (!mc_io || !mc_io->regs) > + return -EACCES; > + > + /* --- Call lock function here in case portal is shared --- */ > + mc_spinlock_lock(&mc_portal_lock); > + > + mc_write_command(mc_io->regs, cmd); > + > + /* Spin until status changes */ > + do { > + status = MC_CMD_HDR_READ_STATUS(ioread64(mc_io->regs)); > + > + /* --- Call wait function here to prevent blocking --- > + * Change the loop condition accordingly to exit on timeout. > + */ > + } while (status == MC_CMD_STATUS_READY); > + > + /* Read the response back into the command buffer */ > + mc_read_response(mc_io->regs, cmd); > + > + /* --- Call unlock function here in case portal is shared --- */ > + mc_spinlock_unlock(&mc_portal_lock); > + > + return mc_status_to_error(status); > +} >