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