1
2
3
4
5
6
7#ifndef __FSL_MC_CMD_H
8#define __FSL_MC_CMD_H
9
10#include <stdint.h>
11
12#include <rte_byteorder.h>
13#include <rte_compat.h>
14
15#define MC_CMD_NUM_OF_PARAMS 7
16
17#define phys_addr_t uint64_t
18
19#define u64 uint64_t
20#define u32 uint32_t
21#define u16 uint16_t
22#define u8 uint8_t
23
24#define cpu_to_le64 rte_cpu_to_le_64
25#define cpu_to_le32 rte_cpu_to_le_32
26#define cpu_to_le16 rte_cpu_to_le_16
27
28#define le64_to_cpu rte_le_to_cpu_64
29#define le32_to_cpu rte_le_to_cpu_32
30#define le16_to_cpu rte_le_to_cpu_16
31
32#define BITS_PER_LONG (__SIZEOF_LONG__ * 8)
33#define GENMASK(h, l) \
34 (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
35
36struct mc_cmd_header {
37 union {
38 struct {
39 uint8_t src_id;
40 uint8_t flags_hw;
41 uint8_t status;
42 uint8_t flags_sw;
43 uint16_t token;
44 uint16_t cmd_id;
45 };
46 uint32_t word[2];
47 };
48};
49
50struct mc_command {
51 uint64_t header;
52 uint64_t params[MC_CMD_NUM_OF_PARAMS];
53};
54
55struct mc_rsp_create {
56 uint32_t object_id;
57};
58
59enum mc_cmd_status {
60 MC_CMD_STATUS_OK = 0x0,
61 MC_CMD_STATUS_READY = 0x1,
62 MC_CMD_STATUS_AUTH_ERR = 0x3,
63 MC_CMD_STATUS_NO_PRIVILEGE = 0x4,
64 MC_CMD_STATUS_DMA_ERR = 0x5,
65 MC_CMD_STATUS_CONFIG_ERR = 0x6,
66 MC_CMD_STATUS_TIMEOUT = 0x7,
67 MC_CMD_STATUS_NO_RESOURCE = 0x8,
68 MC_CMD_STATUS_NO_MEMORY = 0x9,
69 MC_CMD_STATUS_BUSY = 0xA,
70 MC_CMD_STATUS_UNSUPPORTED_OP = 0xB,
71 MC_CMD_STATUS_INVALID_STATE = 0xC
72};
73
74
75
76
77
78
79#define MC_CMD_FLAG_PRI 0x80
80
81#define MC_CMD_FLAG_INTR_DIS 0x01
82
83#define MC_CMD_HDR_FLAGS_MASK 0xFF00FF00
84
85__rte_internal
86int mc_send_command(struct fsl_mc_io *mc_io, struct mc_command *cmd);
87
88static inline uint64_t mc_encode_cmd_header(uint16_t cmd_id,
89 uint32_t cmd_flags,
90 uint16_t token)
91{
92 uint64_t header = 0;
93 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&header;
94
95 hdr->cmd_id = cpu_to_le16(cmd_id);
96 hdr->token = cpu_to_le16(token);
97 hdr->status = MC_CMD_STATUS_READY;
98 hdr->word[0] |= cpu_to_le32(cmd_flags & MC_CMD_HDR_FLAGS_MASK);
99
100 return header;
101}
102
103static inline uint16_t mc_cmd_hdr_read_token(struct mc_command *cmd)
104{
105 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header;
106 uint16_t token = le16_to_cpu(hdr->token);
107
108 return token;
109}
110
111static inline uint32_t mc_cmd_read_object_id(struct mc_command *cmd)
112{
113 struct mc_rsp_create *rsp_params;
114
115 rsp_params = (struct mc_rsp_create *)cmd->params;
116 return le32_to_cpu(rsp_params->object_id);
117}
118
119static inline enum mc_cmd_status mc_cmd_read_status(struct mc_command *cmd)
120{
121 struct mc_cmd_header *hdr = (struct mc_cmd_header *)&cmd->header;
122 uint8_t status = hdr->status;
123
124 return (enum mc_cmd_status)status;
125}
126
127
128
129
130
131
132
133static inline void mc_write_command(struct mc_command __iomem *portal,
134 struct mc_command *cmd)
135{
136 struct mc_cmd_header *cmd_header = (struct mc_cmd_header *)&cmd->header;
137 char *header = (char *)&portal->header;
138 int i;
139
140
141 for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++)
142 iowrite64(cmd->params[i], &portal->params[i]);
143
144
145 iowrite32(le32_to_cpu(cmd_header->word[1]), (((uint32_t *)header) + 1));
146 iowrite32(le32_to_cpu(cmd_header->word[0]), (uint32_t *)header);
147}
148
149
150
151
152
153
154
155
156
157
158static inline enum mc_cmd_status mc_read_response(
159 struct mc_command __iomem *portal,
160 struct mc_command *resp)
161{
162 int i;
163 enum mc_cmd_status status;
164
165
166 resp->header = ioread64(&portal->header);
167 status = mc_cmd_read_status(resp);
168 if (status != MC_CMD_STATUS_OK)
169 return status;
170
171
172 for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++)
173 resp->params[i] = ioread64(&portal->params[i]);
174
175 return status;
176}
177
178#endif
179