1
2
3
4
5
6
7#include <fsl-mc/fsl_mc_sys.h>
8#include <fsl-mc/fsl_mc_cmd.h>
9#include <fsl-mc/fsl_dpni.h>
10
11int dpni_prepare_cfg(const struct dpni_cfg *cfg,
12 uint8_t *cfg_buf)
13{
14 uint64_t *params = (uint64_t *)cfg_buf;
15
16 DPNI_PREP_CFG(params, cfg);
17
18 return 0;
19}
20
21int dpni_extract_cfg(struct dpni_cfg *cfg,
22 const uint8_t *cfg_buf)
23{
24 uint64_t *params = (uint64_t *)cfg_buf;
25
26 DPNI_EXT_CFG(params, cfg);
27
28 return 0;
29}
30
31int dpni_open(struct fsl_mc_io *mc_io,
32 uint32_t cmd_flags,
33 int dpni_id,
34 uint16_t *token)
35{
36 struct mc_command cmd = { 0 };
37 int err;
38
39
40 cmd.header = mc_encode_cmd_header(DPNI_CMDID_OPEN,
41 cmd_flags,
42 0);
43 DPNI_CMD_OPEN(cmd, dpni_id);
44
45
46 err = mc_send_command(mc_io, &cmd);
47 if (err)
48 return err;
49
50
51 *token = MC_CMD_HDR_READ_TOKEN(cmd.header);
52
53 return 0;
54}
55
56int dpni_close(struct fsl_mc_io *mc_io,
57 uint32_t cmd_flags,
58 uint16_t token)
59{
60 struct mc_command cmd = { 0 };
61
62
63 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLOSE,
64 cmd_flags,
65 token);
66
67
68 return mc_send_command(mc_io, &cmd);
69}
70
71int dpni_create(struct fsl_mc_io *mc_io,
72 uint16_t dprc_token,
73 uint32_t cmd_flags,
74 const struct dpni_cfg *cfg,
75 uint32_t *obj_id)
76{
77 struct mc_command cmd = { 0 };
78 int err;
79
80
81 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CREATE,
82 cmd_flags,
83 dprc_token);
84 DPNI_CMD_CREATE(cmd, cfg);
85
86
87 err = mc_send_command(mc_io, &cmd);
88 if (err)
89 return err;
90
91
92 MC_CMD_READ_OBJ_ID(cmd, *obj_id);
93
94 return 0;
95}
96
97int dpni_destroy(struct fsl_mc_io *mc_io,
98 uint16_t dprc_token,
99 uint32_t cmd_flags,
100 uint32_t obj_id)
101{
102 struct mc_command cmd = { 0 };
103
104
105 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DESTROY,
106 cmd_flags,
107 dprc_token);
108
109
110 CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd, obj_id);
111
112
113 return mc_send_command(mc_io, &cmd);
114}
115
116int dpni_set_pools(struct fsl_mc_io *mc_io,
117 uint32_t cmd_flags,
118 uint16_t token,
119 const struct dpni_pools_cfg *cfg)
120{
121 struct mc_command cmd = { 0 };
122
123
124 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
125 cmd_flags,
126 token);
127 DPNI_CMD_SET_POOLS(cmd, cfg);
128
129
130 return mc_send_command(mc_io, &cmd);
131}
132
133int dpni_enable(struct fsl_mc_io *mc_io,
134 uint32_t cmd_flags,
135 uint16_t token)
136{
137 struct mc_command cmd = { 0 };
138
139
140 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
141 cmd_flags,
142 token);
143
144
145 return mc_send_command(mc_io, &cmd);
146}
147
148int dpni_disable(struct fsl_mc_io *mc_io,
149 uint32_t cmd_flags,
150 uint16_t token)
151{
152 struct mc_command cmd = { 0 };
153
154
155 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
156 cmd_flags,
157 token);
158
159
160 return mc_send_command(mc_io, &cmd);
161}
162
163int dpni_reset(struct fsl_mc_io *mc_io,
164 uint32_t cmd_flags,
165 uint16_t token)
166{
167 struct mc_command cmd = { 0 };
168
169
170 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
171 cmd_flags,
172 token);
173
174
175 return mc_send_command(mc_io, &cmd);
176}
177
178int dpni_get_attributes(struct fsl_mc_io *mc_io,
179 uint32_t cmd_flags,
180 uint16_t token,
181 struct dpni_attr *attr)
182{
183 struct mc_command cmd = { 0 };
184 int err;
185
186
187 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
188 cmd_flags,
189 token);
190
191 err = mc_send_command(mc_io, &cmd);
192 if (err)
193 return err;
194
195
196 DPNI_RSP_GET_ATTR(cmd, attr);
197
198 return 0;
199}
200
201int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
202 uint32_t cmd_flags,
203 uint16_t token,
204 struct dpni_error_cfg *cfg)
205{
206 struct mc_command cmd = { 0 };
207
208
209 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR,
210 cmd_flags,
211 token);
212 DPNI_CMD_SET_ERRORS_BEHAVIOR(cmd, cfg);
213
214
215 return mc_send_command(mc_io, &cmd);
216}
217
218int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
219 uint32_t cmd_flags,
220 uint16_t token,
221 const struct dpni_buffer_layout *layout,
222 enum dpni_queue_type type)
223{
224 struct mc_command cmd = { 0 };
225
226
227 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT,
228 cmd_flags,
229 token);
230 DPNI_CMD_SET_BUFFER_LAYOUT(cmd, layout, type);
231
232
233 return mc_send_command(mc_io, &cmd);
234}
235
236int dpni_get_qdid(struct fsl_mc_io *mc_io,
237 uint32_t cmd_flags,
238 uint16_t token,
239 uint16_t *qdid)
240{
241 struct mc_command cmd = { 0 };
242 int err;
243
244
245 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
246 cmd_flags,
247 token);
248
249
250 err = mc_send_command(mc_io, &cmd);
251 if (err)
252 return err;
253
254
255 DPNI_RSP_GET_QDID(cmd, *qdid);
256
257 return 0;
258}
259
260int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
261 uint32_t cmd_flags,
262 uint16_t token,
263 uint16_t *data_offset)
264{
265 struct mc_command cmd = { 0 };
266 int err;
267
268
269 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
270 cmd_flags,
271 token);
272
273
274 err = mc_send_command(mc_io, &cmd);
275 if (err)
276 return err;
277
278
279 DPNI_RSP_GET_TX_DATA_OFFSET(cmd, *data_offset);
280
281 return 0;
282}
283
284int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
285 uint32_t cmd_flags,
286 uint16_t token,
287 const struct dpni_link_cfg *cfg)
288{
289 struct mc_command cmd = { 0 };
290
291
292 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
293 cmd_flags,
294 token);
295 DPNI_CMD_SET_LINK_CFG(cmd, cfg);
296
297
298 return mc_send_command(mc_io, &cmd);
299}
300
301int dpni_get_link_state(struct fsl_mc_io *mc_io,
302 uint32_t cmd_flags,
303 uint16_t token,
304 struct dpni_link_state *state)
305{
306 struct mc_command cmd = { 0 };
307 int err;
308
309
310 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
311 cmd_flags,
312 token);
313
314
315 err = mc_send_command(mc_io, &cmd);
316 if (err)
317 return err;
318
319
320 DPNI_RSP_GET_LINK_STATE(cmd, state);
321
322 return 0;
323}
324
325
326int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
327 uint32_t cmd_flags,
328 uint16_t token,
329 const uint8_t mac_addr[6])
330{
331 struct mc_command cmd = { 0 };
332
333
334 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
335 cmd_flags,
336 token);
337 DPNI_CMD_SET_PRIMARY_MAC_ADDR(cmd, mac_addr);
338
339
340 return mc_send_command(mc_io, &cmd);
341}
342
343int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
344 uint32_t cmd_flags,
345 uint16_t token,
346 uint8_t mac_addr[6])
347{
348 struct mc_command cmd = { 0 };
349 int err;
350
351
352 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
353 cmd_flags,
354 token);
355
356
357 err = mc_send_command(mc_io, &cmd);
358 if (err)
359 return err;
360
361
362 DPNI_RSP_GET_PRIMARY_MAC_ADDR(cmd, mac_addr);
363
364 return 0;
365}
366
367int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
368 uint32_t cmd_flags,
369 uint16_t token,
370 const uint8_t mac_addr[6])
371{
372 struct mc_command cmd = { 0 };
373
374
375 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
376 cmd_flags,
377 token);
378 DPNI_CMD_ADD_MAC_ADDR(cmd, mac_addr);
379
380
381 return mc_send_command(mc_io, &cmd);
382}
383
384int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
385 uint32_t cmd_flags,
386 uint16_t token,
387 const uint8_t mac_addr[6])
388{
389 struct mc_command cmd = { 0 };
390
391
392 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
393 cmd_flags,
394 token);
395 DPNI_CMD_REMOVE_MAC_ADDR(cmd, mac_addr);
396
397
398 return mc_send_command(mc_io, &cmd);
399}
400
401int dpni_get_api_version(struct fsl_mc_io *mc_io,
402 u32 cmd_flags,
403 u16 *major_ver,
404 u16 *minor_ver)
405{
406 struct mc_command cmd = { 0 };
407 int err;
408
409
410 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
411 cmd_flags, 0);
412
413
414 err = mc_send_command(mc_io, &cmd);
415 if (err)
416 return err;
417
418
419 mc_cmd_read_api_version(&cmd, major_ver, minor_ver);
420
421 return 0;
422}
423
424int dpni_set_queue(struct fsl_mc_io *mc_io,
425 uint32_t cmd_flags,
426 uint16_t token,
427 enum dpni_queue_type type,
428 uint8_t tc,
429 uint8_t index,
430 const struct dpni_queue *queue)
431{
432 struct mc_command cmd = { 0 };
433
434 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
435 cmd_flags,
436 token);
437 DPNI_CMD_SET_QUEUE(cmd, type, tc, index, queue);
438
439
440 return mc_send_command(mc_io, &cmd);
441}
442
443int dpni_get_queue(struct fsl_mc_io *mc_io,
444 uint32_t cmd_flags,
445 uint16_t token,
446 enum dpni_queue_type type,
447 uint8_t tc,
448 uint8_t index,
449 struct dpni_queue *queue)
450{
451 struct mc_command cmd = { 0 };
452 int err;
453
454
455 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
456 cmd_flags,
457 token);
458 DPNI_CMD_GET_QUEUE(cmd, type, tc, index);
459
460
461 err = mc_send_command(mc_io, &cmd);
462 if (err)
463 return err;
464
465
466 DPNI_RSP_GET_QUEUE(cmd, queue);
467 return 0;
468}
469
470int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io,
471 uint32_t cmd_flags,
472 uint16_t token,
473 enum dpni_confirmation_mode mode)
474{
475 struct dpni_tx_confirmation_mode *cmd_params;
476 struct mc_command cmd = { 0 };
477
478
479 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONFIRMATION_MODE,
480 cmd_flags,
481 token);
482
483 cmd_params = (struct dpni_tx_confirmation_mode *)cmd.params;
484 cmd_params->confirmation_mode = mode;
485
486
487 return mc_send_command(mc_io, &cmd);
488}
489
490int dpni_get_statistics(struct fsl_mc_io *mc_io,
491 uint32_t cmd_flags,
492 uint16_t token,
493 uint8_t page,
494 struct dpni_statistics *stat)
495{
496 struct mc_command cmd = { 0 };
497 int err;
498
499
500 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
501 cmd_flags, token);
502 DPNI_CMD_GET_STATISTICS(cmd, page);
503
504
505 err = mc_send_command(mc_io, &cmd);
506 if (err)
507 return err;
508
509
510 DPNI_RSP_GET_STATISTICS(cmd, stat);
511
512 return 0;
513}
514
515int dpni_reset_statistics(struct fsl_mc_io *mc_io,
516 uint32_t cmd_flags,
517 uint16_t token)
518{
519 struct mc_command cmd = { 0 };
520
521
522 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS,
523 cmd_flags, token);
524
525
526 return mc_send_command(mc_io, &cmd);
527}
528
529