X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=drivers%2Fbus%2Ffslmc%2Fmc%2Ffsl_mc_cmd.h;h=a3c3e7985b420b249688275b428da9d5836cd985;hb=ca33590b6af032bff57d9cc70455660466a654b2;hp=0ca4345c6a8c3748f7a6c4c6f9862a193167c8ea;hpb=f239aed5e674965691846e8ce3f187dd47523689;p=deb_dpdk.git diff --git a/drivers/bus/fslmc/mc/fsl_mc_cmd.h b/drivers/bus/fslmc/mc/fsl_mc_cmd.h index 0ca4345c..a3c3e798 100644 --- a/drivers/bus/fslmc/mc/fsl_mc_cmd.h +++ b/drivers/bus/fslmc/mc/fsl_mc_cmd.h @@ -1,185 +1,124 @@ -/*- - * This file is provided under a dual BSD/GPLv2 license. When using or - * redistributing this file, you may do so under either license. - * - * BSD LICENSE +/* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0) * * Copyright 2013-2016 Freescale Semiconductor Inc. - * Copyright 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. - * - * GPL LICENSE SUMMARY - * - * 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. + * Copyright 2016-2017 NXP * - * 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)) +#include +#include -static inline uint64_t mc_enc(int lsoffset, int width, uint64_t val) -{ - return (uint64_t)(((uint64_t)val & MAKE_UMASK64(width)) << lsoffset); -} +#define MC_CMD_NUM_OF_PARAMS 7 -static inline uint64_t mc_dec(uint64_t val, int lsoffset, int width) -{ - return (uint64_t)((val >> lsoffset) & MAKE_UMASK64(width)); -} +#define phys_addr_t uint64_t + +#define u64 uint64_t +#define u32 uint32_t +#define u16 uint16_t +#define u8 uint8_t + +#define cpu_to_le64 rte_cpu_to_le_64 +#define cpu_to_le32 rte_cpu_to_le_32 +#define cpu_to_le16 rte_cpu_to_le_16 + +#define le64_to_cpu rte_le_to_cpu_64 +#define le32_to_cpu rte_le_to_cpu_32 +#define le16_to_cpu rte_le_to_cpu_16 + +#define BITS_PER_LONG 64 +#define GENMASK(h, l) \ + (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) + +struct mc_cmd_header { + union { + struct { + uint8_t src_id; + uint8_t flags_hw; + uint8_t status; + uint8_t flags_sw; + uint16_t token; + uint16_t cmd_id; + }; + uint32_t word[2]; + }; +}; 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 +struct mc_rsp_create { + uint32_t object_id; }; -/* MC command flags */ +enum mc_cmd_status { + MC_CMD_STATUS_OK = 0x0, /* Completed successfully */ + MC_CMD_STATUS_READY = 0x1, /* Ready to be processed */ + MC_CMD_STATUS_AUTH_ERR = 0x3, /* Authentication error */ + MC_CMD_STATUS_NO_PRIVILEGE = 0x4, /* No privilege */ + MC_CMD_STATUS_DMA_ERR = 0x5, /* DMA or I/O error */ + MC_CMD_STATUS_CONFIG_ERR = 0x6, /* Configuration error */ + MC_CMD_STATUS_TIMEOUT = 0x7, /* Operation timed out */ + MC_CMD_STATUS_NO_RESOURCE = 0x8, /* No resources */ + MC_CMD_STATUS_NO_MEMORY = 0x9, /* No memory available */ + MC_CMD_STATUS_BUSY = 0xA, /* Device is busy */ + MC_CMD_STATUS_UNSUPPORTED_OP = 0xB, /* Unsupported operation */ + MC_CMD_STATUS_INVALID_STATE = 0xC /* Invalid state */ +}; -/** - * High priority flag +/* + * MC command flags */ -#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 - */ +/* High priority flag */ +#define MC_CMD_FLAG_PRI 0x80 +/* Command completion flag */ +#define MC_CMD_FLAG_INTR_DIS 0x01 + #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)) +int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd); -#define MC_CMD_HDR_READ_TOKEN(_hdr) \ - ((uint16_t)mc_dec((_hdr), MC_CMD_HDR_TOKEN_O, MC_CMD_HDR_TOKEN_S)) +static inline uint64_t mc_encode_cmd_header(uint16_t cmd_id, + uint32_t cmd_flags, + uint16_t token) +{ + uint64_t header = 0; + struct mc_cmd_header *hdr = (struct mc_cmd_header *)&header; -#define MC_PREP_OP(_ext, _param, _offset, _width, _type, _arg) \ - ((_ext)[_param] |= cpu_to_le64(mc_enc((_offset), (_width), _arg))) + hdr->cmd_id = cpu_to_le16(cmd_id); + hdr->token = cpu_to_le16(token); + hdr->status = MC_CMD_STATUS_READY; + hdr->word[0] |= cpu_to_le32(cmd_flags & MC_CMD_HDR_FLAGS_MASK); -#define MC_EXT_OP(_ext, _param, _offset, _width, _type, _arg) \ - (_arg = (_type)mc_dec(cpu_to_le64(_ext[_param]), (_offset), (_width))) + return header; +} -#define MC_CMD_OP(_cmd, _param, _offset, _width, _type, _arg) \ - ((_cmd).params[_param] |= mc_enc((_offset), (_width), _arg)) +static inline uint16_t mc_cmd_hdr_read_token(struct mc_command *cmd) +{ + struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header; + uint16_t token = le16_to_cpu(hdr->token); -#define MC_RSP_OP(_cmd, _param, _offset, _width, _type, _arg) \ - (_arg = (_type)mc_dec(_cmd.params[_param], (_offset), (_width))) + return token; +} -/* 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) +static inline uint32_t mc_cmd_read_object_id(struct mc_command *cmd) +{ + struct mc_rsp_create *rsp_params; -/* 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) + rsp_params = (struct mc_rsp_create *)cmd->params; + return le32_to_cpu(rsp_params->object_id); +} -static inline uint64_t mc_encode_cmd_header(uint16_t cmd_id, - uint32_t cmd_flags, - uint16_t token) +static inline enum mc_cmd_status mc_cmd_read_status(struct mc_command *cmd) { - 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); + struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header; + uint8_t status = hdr->status; - return hdr; + return (enum mc_cmd_status)status; } /** @@ -191,20 +130,17 @@ static inline uint64_t mc_encode_cmd_header(uint16_t cmd_id, static inline void mc_write_command(struct mc_command __iomem *portal, struct mc_command *cmd) { - int i; - uint32_t word; + struct mc_cmd_header *cmd_header = (struct mc_cmd_header *)&cmd->header; char *header = (char *)&portal->header; + int i; /* 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 *)header) + 1)); - - word = (uint32_t)mc_dec(cmd->header, 0, 32); - iowrite32(word, (uint32_t *)header); + iowrite32(le32_to_cpu(cmd_header->word[1]), (((uint32_t *)header) + 1)); + iowrite32(le32_to_cpu(cmd_header->word[0]), (uint32_t *)header); } /** @@ -225,7 +161,7 @@ static inline enum mc_cmd_status mc_read_response( /* Copy command response header from MC portal: */ resp->header = ioread64(&portal->header); - status = MC_CMD_HDR_READ_STATUS(resp->header); + status = mc_cmd_read_status(resp); if (status != MC_CMD_STATUS_OK) return status;