2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright 2013-2016 Freescale Semiconductor Inc.
8 * Copyright 2016-2017 NXP.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * * Neither the name of the above-listed copyright holders nor the
18 * names of any contributors may be used to endorse or promote products
19 * derived from this software without specific prior written permission.
23 * ALTERNATIVELY, this software may be distributed under the terms of the
24 * GNU General Public License ("GPL") as published by the Free Software
25 * Foundation, either version 2 of that License or (at your option) any
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
32 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
40 #ifndef __FSL_MC_CMD_H
41 #define __FSL_MC_CMD_H
43 #include <rte_byteorder.h>
46 #define MC_CMD_NUM_OF_PARAMS 7
48 #define phys_addr_t uint64_t
55 #define cpu_to_le64 rte_cpu_to_le_64
56 #define cpu_to_le32 rte_cpu_to_le_32
57 #define cpu_to_le16 rte_cpu_to_le_16
59 #define le64_to_cpu rte_le_to_cpu_64
60 #define le32_to_cpu rte_le_to_cpu_32
61 #define le16_to_cpu rte_le_to_cpu_16
63 #define BITS_PER_LONG 64
64 #define GENMASK(h, l) \
65 (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
67 struct mc_cmd_header {
83 uint64_t params[MC_CMD_NUM_OF_PARAMS];
86 struct mc_rsp_create {
91 MC_CMD_STATUS_OK = 0x0, /* Completed successfully */
92 MC_CMD_STATUS_READY = 0x1, /* Ready to be processed */
93 MC_CMD_STATUS_AUTH_ERR = 0x3, /* Authentication error */
94 MC_CMD_STATUS_NO_PRIVILEGE = 0x4, /* No privilege */
95 MC_CMD_STATUS_DMA_ERR = 0x5, /* DMA or I/O error */
96 MC_CMD_STATUS_CONFIG_ERR = 0x6, /* Configuration error */
97 MC_CMD_STATUS_TIMEOUT = 0x7, /* Operation timed out */
98 MC_CMD_STATUS_NO_RESOURCE = 0x8, /* No resources */
99 MC_CMD_STATUS_NO_MEMORY = 0x9, /* No memory available */
100 MC_CMD_STATUS_BUSY = 0xA, /* Device is busy */
101 MC_CMD_STATUS_UNSUPPORTED_OP = 0xB, /* Unsupported operation */
102 MC_CMD_STATUS_INVALID_STATE = 0xC /* Invalid state */
109 /* High priority flag */
110 #define MC_CMD_FLAG_PRI 0x80
111 /* Command completion flag */
112 #define MC_CMD_FLAG_INTR_DIS 0x01
114 #define MC_CMD_HDR_FLAGS_MASK 0xFF00FF00
116 int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd);
118 static inline uint64_t mc_encode_cmd_header(uint16_t cmd_id,
123 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&header;
125 hdr->cmd_id = cpu_to_le16(cmd_id);
126 hdr->token = cpu_to_le16(token);
127 hdr->status = MC_CMD_STATUS_READY;
128 hdr->word[0] |= cpu_to_le32(cmd_flags & MC_CMD_HDR_FLAGS_MASK);
133 static inline uint16_t mc_cmd_hdr_read_token(struct mc_command *cmd)
135 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header;
136 uint16_t token = le16_to_cpu(hdr->token);
141 static inline uint32_t mc_cmd_read_object_id(struct mc_command *cmd)
143 struct mc_rsp_create *rsp_params;
145 rsp_params = (struct mc_rsp_create *)cmd->params;
146 return le32_to_cpu(rsp_params->object_id);
149 static inline enum mc_cmd_status mc_cmd_read_status(struct mc_command *cmd)
151 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header;
152 uint8_t status = hdr->status;
154 return (enum mc_cmd_status)status;
158 * mc_write_command - writes a command to a Management Complex (MC) portal
160 * @portal: pointer to an MC portal
161 * @cmd: pointer to a filled command
163 static inline void mc_write_command(struct mc_command __iomem *portal,
164 struct mc_command *cmd)
166 struct mc_cmd_header *cmd_header = (struct mc_cmd_header *)&cmd->header;
167 char *header = (char *)&portal->header;
170 /* copy command parameters into the portal */
171 for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++)
172 iowrite64(cmd->params[i], &portal->params[i]);
174 /* submit the command by writing the header */
175 iowrite32(le32_to_cpu(cmd_header->word[1]), (((uint32_t *)header) + 1));
176 iowrite32(le32_to_cpu(cmd_header->word[0]), (uint32_t *)header);
180 * mc_read_response - reads the response for the last MC command from a
181 * Management Complex (MC) portal
183 * @portal: pointer to an MC portal
184 * @resp: pointer to command response buffer
186 * Returns MC_CMD_STATUS_OK on Success; Error code otherwise.
188 static inline enum mc_cmd_status mc_read_response(
189 struct mc_command __iomem *portal,
190 struct mc_command *resp)
193 enum mc_cmd_status status;
195 /* Copy command response header from MC portal: */
196 resp->header = ioread64(&portal->header);
197 status = mc_cmd_read_status(resp);
198 if (status != MC_CMD_STATUS_OK)
201 /* Copy command response data from MC portal: */
202 for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++)
203 resp->params[i] = ioread64(&portal->params[i]);
208 #endif /* __FSL_MC_CMD_H */