1
2
3
4
5#ifndef __FSL_MC_CMD_H
6#define __FSL_MC_CMD_H
7
8#define MC_CMD_NUM_OF_PARAMS 7
9
10#define MAKE_UMASK64(_width) \
11 ((uint64_t)((_width) < 64 ? ((uint64_t)1 << (_width)) - 1 : -1))
12
13static inline uint64_t mc_enc(int lsoffset, int width, uint64_t val)
14{
15 return (uint64_t)(((uint64_t)val & MAKE_UMASK64(width)) << lsoffset);
16}
17static inline uint64_t mc_dec(uint64_t val, int lsoffset, int width)
18{
19 return (uint64_t)((val >> lsoffset) & MAKE_UMASK64(width));
20}
21
22struct mc_command {
23 uint64_t header;
24 uint64_t params[MC_CMD_NUM_OF_PARAMS];
25};
26
27struct mc_rsp_create {
28 __le32 object_id;
29};
30
31struct mc_rsp_api_ver {
32 __le16 major_ver;
33 __le16 minor_ver;
34};
35
36enum mc_cmd_status {
37 MC_CMD_STATUS_OK = 0x0,
38 MC_CMD_STATUS_READY = 0x1,
39 MC_CMD_STATUS_AUTH_ERR = 0x3,
40 MC_CMD_STATUS_NO_PRIVILEGE = 0x4,
41 MC_CMD_STATUS_DMA_ERR = 0x5,
42 MC_CMD_STATUS_CONFIG_ERR = 0x6,
43 MC_CMD_STATUS_TIMEOUT = 0x7,
44 MC_CMD_STATUS_NO_RESOURCE = 0x8,
45 MC_CMD_STATUS_NO_MEMORY = 0x9,
46 MC_CMD_STATUS_BUSY = 0xA,
47 MC_CMD_STATUS_UNSUPPORTED_OP = 0xB,
48 MC_CMD_STATUS_INVALID_STATE = 0xC
49};
50
51
52
53
54
55
56#define MC_CMD_FLAG_PRI 0x00008000
57
58#define MC_CMD_NO_FLAGS 0x00000000
59
60#define MC_CMD_FLAG_INTR_DIS 0x01000000
61
62
63#define MC_CMD_HDR_CMDID_O 48
64#define MC_CMD_HDR_CMDID_S 16
65#define MC_CMD_HDR_STATUS_O 16
66#define MC_CMD_HDR_TOKEN_O 32
67#define MC_CMD_HDR_TOKEN_S 16
68#define MC_CMD_HDR_STATUS_S 8
69#define MC_CMD_HDR_FLAGS_O 0
70#define MC_CMD_HDR_FLAGS_S 32
71#define MC_CMD_HDR_FLAGS_MASK 0x0000FFFF
72
73#define MC_CMD_HDR_READ_STATUS(_hdr) \
74 ((enum mc_cmd_status)mc_dec((_hdr), \
75 MC_CMD_HDR_STATUS_O, MC_CMD_HDR_STATUS_S))
76
77#define MC_CMD_HDR_READ_TOKEN(_hdr) \
78 ((uint16_t)mc_dec((_hdr), MC_CMD_HDR_TOKEN_O, MC_CMD_HDR_TOKEN_S))
79
80#define MC_PREP_OP(_ext, _param, _offset, _width, _type, _arg) \
81 ((_ext)[_param] |= cpu_to_le64(mc_enc((_offset), (_width), _arg)))
82
83#define MC_EXT_OP(_ext, _param, _offset, _width, _type, _arg) \
84 (_arg = (_type)mc_dec(cpu_to_le64(_ext[_param]), (_offset), (_width)))
85
86#define MC_CMD_OP(_cmd, _param, _offset, _width, _type, _arg) \
87 ((_cmd).params[_param] |= mc_enc((_offset), (_width), _arg))
88
89#define MC_RSP_OP(_cmd, _param, _offset, _width, _type, _arg) \
90 (_arg = (_type)mc_dec(_cmd.params[_param], (_offset), (_width)))
91
92
93#define MC_CMD_READ_OBJ_ID(cmd, obj_id) \
94 MC_RSP_OP(cmd, 0, 0, 32, uint32_t, obj_id)
95
96
97#define CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd, object_id) \
98 MC_CMD_OP(cmd, 0, 0, 32, uint32_t, object_id)
99
100static inline uint64_t mc_encode_cmd_header(uint16_t cmd_id,
101 uint32_t cmd_flags,
102 uint16_t token)
103{
104 uint64_t hdr = 0;
105
106 hdr = mc_enc(MC_CMD_HDR_CMDID_O, MC_CMD_HDR_CMDID_S, cmd_id);
107 hdr |= mc_enc(MC_CMD_HDR_FLAGS_O, MC_CMD_HDR_FLAGS_S,
108 (cmd_flags & MC_CMD_HDR_FLAGS_MASK));
109 hdr |= mc_enc(MC_CMD_HDR_TOKEN_O, MC_CMD_HDR_TOKEN_S, token);
110 hdr |= mc_enc(MC_CMD_HDR_STATUS_O, MC_CMD_HDR_STATUS_S,
111 MC_CMD_STATUS_READY);
112
113 return hdr;
114}
115
116
117
118
119
120
121
122static inline void mc_write_command(struct mc_command __iomem *portal,
123 struct mc_command *cmd)
124{
125 int i;
126
127
128 for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++)
129 writeq(cmd->params[i], &portal->params[i]);
130
131
132 writeq(cmd->header, &portal->header);
133}
134
135
136
137
138
139
140
141
142
143
144static inline enum mc_cmd_status mc_read_response(
145 struct mc_command __iomem *portal,
146 struct mc_command *resp)
147{
148 int i;
149 enum mc_cmd_status status;
150
151
152 resp->header = readq(&portal->header);
153 status = MC_CMD_HDR_READ_STATUS(resp->header);
154 if (status != MC_CMD_STATUS_OK)
155 return status;
156
157
158 for (i = 0; i < MC_CMD_NUM_OF_PARAMS; i++)
159 resp->params[i] = readq(&portal->params[i]);
160
161 return status;
162}
163
164
165
166
167
168
169
170
171static inline void mc_cmd_read_api_version(struct mc_command *cmd,
172 u16 *major_ver,
173 u16 *minor_ver)
174{
175 struct mc_rsp_api_ver *rsp_params;
176
177 rsp_params = (struct mc_rsp_api_ver *)cmd->params;
178 *major_ver = le16_to_cpu(rsp_params->major_ver);
179 *minor_ver = le16_to_cpu(rsp_params->minor_ver);
180}
181
182#endif
183