1
2
3
4#include <linux/module.h>
5#include <linux/types.h>
6#include <linux/io.h>
7#include <linux/fsl/mc.h>
8#include "dpdmai.h"
9
10struct dpdmai_rsp_get_attributes {
11 __le32 id;
12 u8 num_of_priorities;
13 u8 pad0[3];
14 __le16 major;
15 __le16 minor;
16};
17
18struct dpdmai_cmd_queue {
19 __le32 dest_id;
20 u8 priority;
21 u8 queue;
22 u8 dest_type;
23 u8 pad;
24 __le64 user_ctx;
25 union {
26 __le32 options;
27 __le32 fqid;
28 };
29};
30
31struct dpdmai_rsp_get_tx_queue {
32 __le64 pad;
33 __le32 fqid;
34};
35
36#define MC_CMD_OP(_cmd, _param, _offset, _width, _type, _arg) \
37 ((_cmd).params[_param] |= mc_enc((_offset), (_width), _arg))
38
39
40#define DPDMAI_CMD_CREATE(cmd, cfg) \
41do { \
42 MC_CMD_OP(cmd, 0, 8, 8, u8, (cfg)->priorities[0]);\
43 MC_CMD_OP(cmd, 0, 16, 8, u8, (cfg)->priorities[1]);\
44} while (0)
45
46static inline u64 mc_enc(int lsoffset, int width, u64 val)
47{
48 return (val & MAKE_UMASK64(width)) << lsoffset;
49}
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68int dpdmai_open(struct fsl_mc_io *mc_io, u32 cmd_flags,
69 int dpdmai_id, u16 *token)
70{
71 struct fsl_mc_command cmd = { 0 };
72 __le64 *cmd_dpdmai_id;
73 int err;
74
75
76 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_OPEN,
77 cmd_flags, 0);
78
79 cmd_dpdmai_id = cmd.params;
80 *cmd_dpdmai_id = cpu_to_le32(dpdmai_id);
81
82
83 err = mc_send_command(mc_io, &cmd);
84 if (err)
85 return err;
86
87
88 *token = mc_cmd_hdr_read_token(&cmd);
89
90 return 0;
91}
92EXPORT_SYMBOL_GPL(dpdmai_open);
93
94
95
96
97
98
99
100
101
102
103
104
105int dpdmai_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
106{
107 struct fsl_mc_command cmd = { 0 };
108
109
110 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_CLOSE,
111 cmd_flags, token);
112
113
114 return mc_send_command(mc_io, &cmd);
115}
116EXPORT_SYMBOL_GPL(dpdmai_close);
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140int dpdmai_create(struct fsl_mc_io *mc_io, u32 cmd_flags,
141 const struct dpdmai_cfg *cfg, u16 *token)
142{
143 struct fsl_mc_command cmd = { 0 };
144 int err;
145
146
147 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_CREATE,
148 cmd_flags, 0);
149 DPDMAI_CMD_CREATE(cmd, cfg);
150
151
152 err = mc_send_command(mc_io, &cmd);
153 if (err)
154 return err;
155
156
157 *token = mc_cmd_hdr_read_token(&cmd);
158
159 return 0;
160}
161
162
163
164
165
166
167
168
169
170int dpdmai_destroy(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
171{
172 struct fsl_mc_command cmd = { 0 };
173
174
175 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_DESTROY,
176 cmd_flags, token);
177
178
179 return mc_send_command(mc_io, &cmd);
180}
181EXPORT_SYMBOL_GPL(dpdmai_destroy);
182
183
184
185
186
187
188
189
190
191int dpdmai_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
192{
193 struct fsl_mc_command cmd = { 0 };
194
195
196 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_ENABLE,
197 cmd_flags, token);
198
199
200 return mc_send_command(mc_io, &cmd);
201}
202EXPORT_SYMBOL_GPL(dpdmai_enable);
203
204
205
206
207
208
209
210
211
212int dpdmai_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
213{
214 struct fsl_mc_command cmd = { 0 };
215
216
217 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_DISABLE,
218 cmd_flags, token);
219
220
221 return mc_send_command(mc_io, &cmd);
222}
223EXPORT_SYMBOL_GPL(dpdmai_disable);
224
225
226
227
228
229
230
231
232
233int dpdmai_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
234{
235 struct fsl_mc_command cmd = { 0 };
236
237
238 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_RESET,
239 cmd_flags, token);
240
241
242 return mc_send_command(mc_io, &cmd);
243}
244EXPORT_SYMBOL_GPL(dpdmai_reset);
245
246
247
248
249
250
251
252
253
254
255int dpdmai_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags,
256 u16 token, struct dpdmai_attr *attr)
257{
258 struct dpdmai_rsp_get_attributes *rsp_params;
259 struct fsl_mc_command cmd = { 0 };
260 int err;
261
262
263 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_ATTR,
264 cmd_flags, token);
265
266
267 err = mc_send_command(mc_io, &cmd);
268 if (err)
269 return err;
270
271
272 rsp_params = (struct dpdmai_rsp_get_attributes *)cmd.params;
273 attr->id = le32_to_cpu(rsp_params->id);
274 attr->version.major = le16_to_cpu(rsp_params->major);
275 attr->version.minor = le16_to_cpu(rsp_params->minor);
276 attr->num_of_priorities = rsp_params->num_of_priorities;
277
278 return 0;
279}
280EXPORT_SYMBOL_GPL(dpdmai_get_attributes);
281
282
283
284
285
286
287
288
289
290
291
292
293int dpdmai_set_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
294 u8 priority, const struct dpdmai_rx_queue_cfg *cfg)
295{
296 struct dpdmai_cmd_queue *cmd_params;
297 struct fsl_mc_command cmd = { 0 };
298
299
300 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_SET_RX_QUEUE,
301 cmd_flags, token);
302
303 cmd_params = (struct dpdmai_cmd_queue *)cmd.params;
304 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
305 cmd_params->priority = cfg->dest_cfg.priority;
306 cmd_params->queue = priority;
307 cmd_params->dest_type = cfg->dest_cfg.dest_type;
308 cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
309 cmd_params->options = cpu_to_le32(cfg->options);
310
311
312 return mc_send_command(mc_io, &cmd);
313}
314EXPORT_SYMBOL_GPL(dpdmai_set_rx_queue);
315
316
317
318
319
320
321
322
323
324
325
326
327int dpdmai_get_rx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
328 u8 priority, struct dpdmai_rx_queue_attr *attr)
329{
330 struct dpdmai_cmd_queue *cmd_params;
331 struct fsl_mc_command cmd = { 0 };
332 int err;
333
334
335 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_RX_QUEUE,
336 cmd_flags, token);
337
338 cmd_params = (struct dpdmai_cmd_queue *)cmd.params;
339 cmd_params->queue = priority;
340
341
342 err = mc_send_command(mc_io, &cmd);
343 if (err)
344 return err;
345
346
347 attr->dest_cfg.dest_id = le32_to_cpu(cmd_params->dest_id);
348 attr->dest_cfg.priority = cmd_params->priority;
349 attr->dest_cfg.dest_type = cmd_params->dest_type;
350 attr->user_ctx = le64_to_cpu(cmd_params->user_ctx);
351 attr->fqid = le32_to_cpu(cmd_params->fqid);
352
353 return 0;
354}
355EXPORT_SYMBOL_GPL(dpdmai_get_rx_queue);
356
357
358
359
360
361
362
363
364
365
366
367
368int dpdmai_get_tx_queue(struct fsl_mc_io *mc_io, u32 cmd_flags,
369 u16 token, u8 priority, u32 *fqid)
370{
371 struct dpdmai_rsp_get_tx_queue *rsp_params;
372 struct dpdmai_cmd_queue *cmd_params;
373 struct fsl_mc_command cmd = { 0 };
374 int err;
375
376
377 cmd.header = mc_encode_cmd_header(DPDMAI_CMDID_GET_TX_QUEUE,
378 cmd_flags, token);
379
380 cmd_params = (struct dpdmai_cmd_queue *)cmd.params;
381 cmd_params->queue = priority;
382
383
384 err = mc_send_command(mc_io, &cmd);
385 if (err)
386 return err;
387
388
389
390 rsp_params = (struct dpdmai_rsp_get_tx_queue *)cmd.params;
391 *fqid = le32_to_cpu(rsp_params->fqid);
392
393 return 0;
394}
395EXPORT_SYMBOL_GPL(dpdmai_get_tx_queue);
396
397MODULE_LICENSE("GPL v2");
398