Branch data Line data Source code
1 : : /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2 : : *
3 : : * Copyright 2013-2016 Freescale Semiconductor Inc.
4 : : * Copyright 2016-2022 NXP
5 : : *
6 : : */
7 : : #include <fsl_mc_sys.h>
8 : : #include <fsl_mc_cmd.h>
9 : : #include <fsl_dpni.h>
10 : : #include <fsl_dpni_cmd.h>
11 : :
12 : : /**
13 : : * dpni_open() - Open a control session for the specified object
14 : : * @mc_io: Pointer to MC portal's I/O object
15 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
16 : : * @dpni_id: DPNI unique ID
17 : : * @token: Returned token; use in subsequent API calls
18 : : *
19 : : * This function can be used to open a control session for an
20 : : * already created object; an object may have been declared in
21 : : * the DPL or by calling the dpni_create() function.
22 : : * This function returns a unique authentication token,
23 : : * associated with the specific object ID and the specific MC
24 : : * portal; this token must be used in all subsequent commands for
25 : : * this specific object.
26 : : *
27 : : * Return: '0' on Success; Error code otherwise.
28 : : */
29 : 0 : int dpni_open(struct fsl_mc_io *mc_io,
30 : : uint32_t cmd_flags,
31 : : int dpni_id,
32 : : uint16_t *token)
33 : : {
34 : 0 : struct mc_command cmd = { 0 };
35 : : struct dpni_cmd_open *cmd_params;
36 : :
37 : : int err;
38 : :
39 : : /* prepare command */
40 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_OPEN,
41 : : cmd_flags,
42 : : 0);
43 : : cmd_params = (struct dpni_cmd_open *)cmd.params;
44 : 0 : cmd_params->dpni_id = cpu_to_le32(dpni_id);
45 : :
46 : : /* send command to mc*/
47 : 0 : err = mc_send_command(mc_io, &cmd);
48 [ # # ]: 0 : if (err)
49 : : return err;
50 : :
51 : : /* retrieve response parameters */
52 : 0 : *token = mc_cmd_hdr_read_token(&cmd);
53 : :
54 : 0 : return 0;
55 : : }
56 : :
57 : : /**
58 : : * dpni_close() - Close the control session of the object
59 : : * @mc_io: Pointer to MC portal's I/O object
60 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
61 : : * @token: Token of DPNI object
62 : : *
63 : : * After this function is called, no further operations are
64 : : * allowed on the object without opening a new control session.
65 : : *
66 : : * Return: '0' on Success; Error code otherwise.
67 : : */
68 : 0 : int dpni_close(struct fsl_mc_io *mc_io,
69 : : uint32_t cmd_flags,
70 : : uint16_t token)
71 : : {
72 : 0 : struct mc_command cmd = { 0 };
73 : :
74 : : /* prepare command */
75 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLOSE,
76 : : cmd_flags,
77 : : token);
78 : :
79 : : /* send command to mc*/
80 : 0 : return mc_send_command(mc_io, &cmd);
81 : : }
82 : :
83 : : /**
84 : : * dpni_create() - Create the DPNI object
85 : : * @mc_io: Pointer to MC portal's I/O object
86 : : * @dprc_token: Parent container token; '0' for default container
87 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
88 : : * @cfg: Configuration structure
89 : : * @obj_id: Returned object id
90 : : *
91 : : * Create the DPNI object, allocate required resources and
92 : : * perform required initialization.
93 : : *
94 : : * The object can be created either by declaring it in the
95 : : * DPL file, or by calling this function.
96 : : *
97 : : * The function accepts an authentication token of a parent
98 : : * container that this object should be assigned to. The token
99 : : * can be '0' so the object will be assigned to the default container.
100 : : * The newly created object can be opened with the returned
101 : : * object id and using the container's associated tokens and MC portals.
102 : : *
103 : : * Return: '0' on Success; Error code otherwise.
104 : : */
105 : 0 : int dpni_create(struct fsl_mc_io *mc_io,
106 : : uint16_t dprc_token,
107 : : uint32_t cmd_flags,
108 : : const struct dpni_cfg *cfg,
109 : : uint32_t *obj_id)
110 : : {
111 : : struct dpni_cmd_create *cmd_params;
112 : 0 : struct mc_command cmd = { 0 };
113 : : int err;
114 : :
115 : : /* prepare command */
116 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_CREATE,
117 : : cmd_flags,
118 : : dprc_token);
119 : : cmd_params = (struct dpni_cmd_create *)cmd.params;
120 : 0 : cmd_params->options = cpu_to_le32(cfg->options);
121 : 0 : cmd_params->num_queues = cfg->num_queues;
122 : 0 : cmd_params->num_tcs = cfg->num_tcs;
123 : 0 : cmd_params->mac_filter_entries = cfg->mac_filter_entries;
124 : 0 : cmd_params->num_rx_tcs = cfg->num_rx_tcs;
125 : 0 : cmd_params->vlan_filter_entries = cfg->vlan_filter_entries;
126 : 0 : cmd_params->qos_entries = cfg->qos_entries;
127 : 0 : cmd_params->fs_entries = cpu_to_le16(cfg->fs_entries);
128 : 0 : cmd_params->num_cgs = cfg->num_cgs;
129 : 0 : cmd_params->num_opr = cfg->num_opr;
130 : 0 : cmd_params->dist_key_size = cfg->dist_key_size;
131 : 0 : cmd_params->num_channels = cfg->num_channels;
132 : :
133 : : /* send command to mc*/
134 : 0 : err = mc_send_command(mc_io, &cmd);
135 [ # # ]: 0 : if (err)
136 : : return err;
137 : :
138 : : /* retrieve response parameters */
139 : 0 : *obj_id = mc_cmd_read_object_id(&cmd);
140 : :
141 : 0 : return 0;
142 : : }
143 : :
144 : : /**
145 : : * dpni_destroy() - Destroy the DPNI object and release all its resources.
146 : : * @mc_io: Pointer to MC portal's I/O object
147 : : * @dprc_token: Parent container token; '0' for default container
148 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
149 : : * @object_id: The object id; it must be a valid id within the container that
150 : : * created this object;
151 : : *
152 : : * The function accepts the authentication token of the parent container that
153 : : * created the object (not the one that currently owns the object). The object
154 : : * is searched within parent using the provided 'object_id'.
155 : : * All tokens to the object must be closed before calling destroy.
156 : : *
157 : : * Return: '0' on Success; error code otherwise.
158 : : */
159 : 0 : int dpni_destroy(struct fsl_mc_io *mc_io,
160 : : uint16_t dprc_token,
161 : : uint32_t cmd_flags,
162 : : uint32_t object_id)
163 : : {
164 : : struct dpni_cmd_destroy *cmd_params;
165 : 0 : struct mc_command cmd = { 0 };
166 : :
167 : : /* prepare command */
168 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_DESTROY,
169 : : cmd_flags,
170 : : dprc_token);
171 : : /* set object id to destroy */
172 : : cmd_params = (struct dpni_cmd_destroy *)cmd.params;
173 : 0 : cmd_params->dpsw_id = cpu_to_le32(object_id);
174 : :
175 : : /* send command to mc*/
176 : 0 : return mc_send_command(mc_io, &cmd);
177 : : }
178 : :
179 : : /**
180 : : * dpni_set_pools() - Set buffer pools configuration
181 : : * @mc_io: Pointer to MC portal's I/O object
182 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
183 : : * @token: Token of DPNI object
184 : : * @cfg: Buffer pools configuration
185 : : *
186 : : * mandatory for DPNI operation
187 : : * warning:Allowed only when DPNI is disabled
188 : : *
189 : : * Return: '0' on Success; Error code otherwise.
190 : : */
191 : 0 : int dpni_set_pools(struct fsl_mc_io *mc_io,
192 : : uint32_t cmd_flags,
193 : : uint16_t token,
194 : : const struct dpni_pools_cfg *cfg)
195 : : {
196 : 0 : struct mc_command cmd = { 0 };
197 : : struct dpni_cmd_set_pools *cmd_params;
198 : : int i;
199 : :
200 : : /* prepare command */
201 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS,
202 : : cmd_flags,
203 : : token);
204 : : cmd_params = (struct dpni_cmd_set_pools *)cmd.params;
205 : 0 : cmd_params->num_dpbp = cfg->num_dpbp;
206 : 0 : cmd_params->pool_options = cfg->pool_options;
207 [ # # ]: 0 : for (i = 0; i < DPNI_MAX_DPBP; i++) {
208 : 0 : cmd_params->pool[i].dpbp_id =
209 : 0 : cpu_to_le16(cfg->pools[i].dpbp_id);
210 : 0 : cmd_params->pool[i].priority_mask =
211 : 0 : cfg->pools[i].priority_mask;
212 : 0 : cmd_params->buffer_size[i] =
213 : 0 : cpu_to_le16(cfg->pools[i].buffer_size);
214 : 0 : cmd_params->backup_pool_mask |=
215 : 0 : DPNI_BACKUP_POOL(cfg->pools[i].backup_pool, i);
216 : : }
217 : :
218 : : /* send command to mc*/
219 : 0 : return mc_send_command(mc_io, &cmd);
220 : : }
221 : :
222 : : /**
223 : : * dpni_enable() - Enable the DPNI, allow sending and receiving frames.
224 : : * @mc_io: Pointer to MC portal's I/O object
225 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
226 : : * @token: Token of DPNI object
227 : : *
228 : : * Return: '0' on Success; Error code otherwise.
229 : : */
230 : 0 : int dpni_enable(struct fsl_mc_io *mc_io,
231 : : uint32_t cmd_flags,
232 : : uint16_t token)
233 : : {
234 : 0 : struct mc_command cmd = { 0 };
235 : :
236 : : /* prepare command */
237 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE,
238 : : cmd_flags,
239 : : token);
240 : :
241 : : /* send command to mc*/
242 : 0 : return mc_send_command(mc_io, &cmd);
243 : : }
244 : :
245 : : /**
246 : : * dpni_disable() - Disable the DPNI, stop sending and receiving frames.
247 : : * @mc_io: Pointer to MC portal's I/O object
248 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
249 : : * @token: Token of DPNI object
250 : : *
251 : : * Return: '0' on Success; Error code otherwise.
252 : : */
253 : 0 : int dpni_disable(struct fsl_mc_io *mc_io,
254 : : uint32_t cmd_flags,
255 : : uint16_t token)
256 : : {
257 : 0 : struct mc_command cmd = { 0 };
258 : :
259 : : /* prepare command */
260 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE,
261 : : cmd_flags,
262 : : token);
263 : :
264 : : /* send command to mc*/
265 : 0 : return mc_send_command(mc_io, &cmd);
266 : : }
267 : :
268 : : /**
269 : : * dpni_is_enabled() - Check if the DPNI is enabled.
270 : : * @mc_io: Pointer to MC portal's I/O object
271 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
272 : : * @token: Token of DPNI object
273 : : * @en: Returns '1' if object is enabled; '0' otherwise
274 : : *
275 : : * Return: '0' on Success; Error code otherwise.
276 : : */
277 : 0 : int dpni_is_enabled(struct fsl_mc_io *mc_io,
278 : : uint32_t cmd_flags,
279 : : uint16_t token,
280 : : int *en)
281 : : {
282 : 0 : struct mc_command cmd = { 0 };
283 : : struct dpni_rsp_is_enabled *rsp_params;
284 : : int err;
285 : :
286 : : /* prepare command */
287 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_IS_ENABLED,
288 : : cmd_flags,
289 : : token);
290 : :
291 : : /* send command to mc*/
292 : 0 : err = mc_send_command(mc_io, &cmd);
293 [ # # ]: 0 : if (err)
294 : : return err;
295 : :
296 : : /* retrieve response parameters */
297 : : rsp_params = (struct dpni_rsp_is_enabled *)cmd.params;
298 : 0 : *en = dpni_get_field(rsp_params->enabled, ENABLE);
299 : :
300 : 0 : return 0;
301 : : }
302 : :
303 : : /**
304 : : * dpni_reset() - Reset the DPNI, returns the object to initial state.
305 : : * @mc_io: Pointer to MC portal's I/O object
306 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
307 : : * @token: Token of DPNI object
308 : : *
309 : : * Return: '0' on Success; Error code otherwise.
310 : : */
311 : 0 : int dpni_reset(struct fsl_mc_io *mc_io,
312 : : uint32_t cmd_flags,
313 : : uint16_t token)
314 : : {
315 : 0 : struct mc_command cmd = { 0 };
316 : :
317 : : /* prepare command */
318 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET,
319 : : cmd_flags,
320 : : token);
321 : :
322 : : /* send command to mc*/
323 : 0 : return mc_send_command(mc_io, &cmd);
324 : : }
325 : :
326 : : /**
327 : : * dpni_set_irq_enable() - Set overall interrupt state.
328 : : * @mc_io: Pointer to MC portal's I/O object
329 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
330 : : * @token: Token of DPNI object
331 : : * @irq_index: The interrupt index to configure
332 : : * @en: Interrupt state: - enable = 1, disable = 0
333 : : *
334 : : * Allows GPP software to control when interrupts are generated.
335 : : * Each interrupt can have up to 32 causes. The enable/disable control's the
336 : : * overall interrupt state. if the interrupt is disabled no causes will cause
337 : : * an interrupt.
338 : : *
339 : : * Return: '0' on Success; Error code otherwise.
340 : : */
341 : 0 : int dpni_set_irq_enable(struct fsl_mc_io *mc_io,
342 : : uint32_t cmd_flags,
343 : : uint16_t token,
344 : : uint8_t irq_index,
345 : : uint8_t en)
346 : : {
347 : 0 : struct mc_command cmd = { 0 };
348 : : struct dpni_cmd_set_irq_enable *cmd_params;
349 : :
350 : : /* prepare command */
351 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_ENABLE,
352 : : cmd_flags,
353 : : token);
354 : : cmd_params = (struct dpni_cmd_set_irq_enable *)cmd.params;
355 : 0 : dpni_set_field(cmd_params->enable, ENABLE, en);
356 : 0 : cmd_params->irq_index = irq_index;
357 : :
358 : : /* send command to mc*/
359 : 0 : return mc_send_command(mc_io, &cmd);
360 : : }
361 : :
362 : : /**
363 : : * dpni_get_irq_enable() - Get overall interrupt state
364 : : * @mc_io: Pointer to MC portal's I/O object
365 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
366 : : * @token: Token of DPNI object
367 : : * @irq_index: The interrupt index to configure
368 : : * @en: Returned interrupt state - enable = 1, disable = 0
369 : : *
370 : : * Return: '0' on Success; Error code otherwise.
371 : : */
372 : 0 : int dpni_get_irq_enable(struct fsl_mc_io *mc_io,
373 : : uint32_t cmd_flags,
374 : : uint16_t token,
375 : : uint8_t irq_index,
376 : : uint8_t *en)
377 : : {
378 : 0 : struct mc_command cmd = { 0 };
379 : : struct dpni_cmd_get_irq_enable *cmd_params;
380 : : struct dpni_rsp_get_irq_enable *rsp_params;
381 : :
382 : : int err;
383 : :
384 : : /* prepare command */
385 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_ENABLE,
386 : : cmd_flags,
387 : : token);
388 : : cmd_params = (struct dpni_cmd_get_irq_enable *)cmd.params;
389 : 0 : cmd_params->irq_index = irq_index;
390 : :
391 : : /* send command to mc*/
392 : 0 : err = mc_send_command(mc_io, &cmd);
393 [ # # ]: 0 : if (err)
394 : : return err;
395 : :
396 : : /* retrieve response parameters */
397 : : rsp_params = (struct dpni_rsp_get_irq_enable *)cmd.params;
398 : 0 : *en = dpni_get_field(rsp_params->enabled, ENABLE);
399 : :
400 : 0 : return 0;
401 : : }
402 : :
403 : : /**
404 : : * dpni_set_irq_mask() - Set interrupt mask.
405 : : * @mc_io: Pointer to MC portal's I/O object
406 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
407 : : * @token: Token of DPNI object
408 : : * @irq_index: The interrupt index to configure
409 : : * @mask: Event mask to trigger interrupt;
410 : : * each bit:
411 : : * 0 = ignore event
412 : : * 1 = consider event for asserting IRQ
413 : : *
414 : : * Every interrupt can have up to 32 causes and the interrupt model supports
415 : : * masking/unmasking each cause independently
416 : : *
417 : : * Return: '0' on Success; Error code otherwise.
418 : : */
419 : 0 : int dpni_set_irq_mask(struct fsl_mc_io *mc_io,
420 : : uint32_t cmd_flags,
421 : : uint16_t token,
422 : : uint8_t irq_index,
423 : : uint32_t mask)
424 : : {
425 : 0 : struct mc_command cmd = { 0 };
426 : : struct dpni_cmd_set_irq_mask *cmd_params;
427 : :
428 : : /* prepare command */
429 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_MASK,
430 : : cmd_flags,
431 : : token);
432 : : cmd_params = (struct dpni_cmd_set_irq_mask *)cmd.params;
433 : 0 : cmd_params->mask = cpu_to_le32(mask);
434 : 0 : cmd_params->irq_index = irq_index;
435 : :
436 : : /* send command to mc*/
437 : 0 : return mc_send_command(mc_io, &cmd);
438 : : }
439 : :
440 : : /**
441 : : * dpni_get_irq_mask() - Get interrupt mask.
442 : : * @mc_io: Pointer to MC portal's I/O object
443 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
444 : : * @token: Token of DPNI object
445 : : * @irq_index: The interrupt index to configure
446 : : * @mask: Returned event mask to trigger interrupt
447 : : *
448 : : * Every interrupt can have up to 32 causes and the interrupt model supports
449 : : * masking/unmasking each cause independently
450 : : *
451 : : * Return: '0' on Success; Error code otherwise.
452 : : */
453 : 0 : int dpni_get_irq_mask(struct fsl_mc_io *mc_io,
454 : : uint32_t cmd_flags,
455 : : uint16_t token,
456 : : uint8_t irq_index,
457 : : uint32_t *mask)
458 : : {
459 : 0 : struct mc_command cmd = { 0 };
460 : : struct dpni_cmd_get_irq_mask *cmd_params;
461 : : struct dpni_rsp_get_irq_mask *rsp_params;
462 : : int err;
463 : :
464 : : /* prepare command */
465 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_MASK,
466 : : cmd_flags,
467 : : token);
468 : : cmd_params = (struct dpni_cmd_get_irq_mask *)cmd.params;
469 : 0 : cmd_params->irq_index = irq_index;
470 : :
471 : : /* send command to mc*/
472 : 0 : err = mc_send_command(mc_io, &cmd);
473 [ # # ]: 0 : if (err)
474 : : return err;
475 : :
476 : : /* retrieve response parameters */
477 : : rsp_params = (struct dpni_rsp_get_irq_mask *)cmd.params;
478 : 0 : *mask = le32_to_cpu(rsp_params->mask);
479 : :
480 : 0 : return 0;
481 : : }
482 : :
483 : : /**
484 : : * dpni_get_irq_status() - Get the current status of any pending interrupts.
485 : : * @mc_io: Pointer to MC portal's I/O object
486 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
487 : : * @token: Token of DPNI object
488 : : * @irq_index: The interrupt index to configure
489 : : * @status: Returned interrupts status - one bit per cause:
490 : : * 0 = no interrupt pending
491 : : * 1 = interrupt pending
492 : : *
493 : : * Return: '0' on Success; Error code otherwise.
494 : : */
495 : 0 : int dpni_get_irq_status(struct fsl_mc_io *mc_io,
496 : : uint32_t cmd_flags,
497 : : uint16_t token,
498 : : uint8_t irq_index,
499 : : uint32_t *status)
500 : : {
501 : 0 : struct mc_command cmd = { 0 };
502 : : struct dpni_cmd_get_irq_status *cmd_params;
503 : : struct dpni_rsp_get_irq_status *rsp_params;
504 : : int err;
505 : :
506 : : /* prepare command */
507 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_STATUS,
508 : : cmd_flags,
509 : : token);
510 : : cmd_params = (struct dpni_cmd_get_irq_status *)cmd.params;
511 : 0 : cmd_params->status = cpu_to_le32(*status);
512 : 0 : cmd_params->irq_index = irq_index;
513 : :
514 : : /* send command to mc*/
515 : 0 : err = mc_send_command(mc_io, &cmd);
516 [ # # ]: 0 : if (err)
517 : : return err;
518 : :
519 : : /* retrieve response parameters */
520 : : rsp_params = (struct dpni_rsp_get_irq_status *)cmd.params;
521 : 0 : *status = le32_to_cpu(rsp_params->status);
522 : :
523 : 0 : return 0;
524 : : }
525 : :
526 : : /**
527 : : * dpni_clear_irq_status() - Clear a pending interrupt's status
528 : : * @mc_io: Pointer to MC portal's I/O object
529 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
530 : : * @token: Token of DPNI object
531 : : * @irq_index: The interrupt index to configure
532 : : * @status: bits to clear (W1C) - one bit per cause:
533 : : * 0 = don't change
534 : : * 1 = clear status bit
535 : : *
536 : : * Return: '0' on Success; Error code otherwise.
537 : : */
538 : 0 : int dpni_clear_irq_status(struct fsl_mc_io *mc_io,
539 : : uint32_t cmd_flags,
540 : : uint16_t token,
541 : : uint8_t irq_index,
542 : : uint32_t status)
543 : : {
544 : 0 : struct mc_command cmd = { 0 };
545 : : struct dpni_cmd_clear_irq_status *cmd_params;
546 : :
547 : : /* prepare command */
548 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLEAR_IRQ_STATUS,
549 : : cmd_flags,
550 : : token);
551 : : cmd_params = (struct dpni_cmd_clear_irq_status *)cmd.params;
552 : 0 : cmd_params->irq_index = irq_index;
553 : 0 : cmd_params->status = cpu_to_le32(status);
554 : :
555 : : /* send command to mc*/
556 : 0 : return mc_send_command(mc_io, &cmd);
557 : : }
558 : :
559 : : /**
560 : : * dpni_get_attributes() - Retrieve DPNI attributes.
561 : : * @mc_io: Pointer to MC portal's I/O object
562 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
563 : : * @token: Token of DPNI object
564 : : * @attr: Object's attributes
565 : : *
566 : : * Return: '0' on Success; Error code otherwise.
567 : : */
568 : 0 : int dpni_get_attributes(struct fsl_mc_io *mc_io,
569 : : uint32_t cmd_flags,
570 : : uint16_t token,
571 : : struct dpni_attr *attr)
572 : : {
573 : 0 : struct mc_command cmd = { 0 };
574 : : struct dpni_rsp_get_attr *rsp_params;
575 : :
576 : : int err;
577 : :
578 : : /* prepare command */
579 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR,
580 : : cmd_flags,
581 : : token);
582 : :
583 : : /* send command to mc*/
584 : 0 : err = mc_send_command(mc_io, &cmd);
585 [ # # ]: 0 : if (err)
586 : : return err;
587 : :
588 : : /* retrieve response parameters */
589 : : rsp_params = (struct dpni_rsp_get_attr *)cmd.params;
590 : 0 : attr->options = le32_to_cpu(rsp_params->options);
591 : 0 : attr->num_queues = rsp_params->num_queues;
592 : 0 : attr->num_rx_tcs = rsp_params->num_rx_tcs;
593 : 0 : attr->num_tx_tcs = rsp_params->num_tx_tcs;
594 : 0 : attr->mac_filter_entries = rsp_params->mac_filter_entries;
595 : 0 : attr->vlan_filter_entries = rsp_params->vlan_filter_entries;
596 : 0 : attr->num_channels = rsp_params->num_channels;
597 : 0 : attr->qos_entries = rsp_params->qos_entries;
598 : 0 : attr->fs_entries = le16_to_cpu(rsp_params->fs_entries);
599 : 0 : attr->num_opr = le16_to_cpu(rsp_params->num_opr);
600 : 0 : attr->qos_key_size = rsp_params->qos_key_size;
601 : 0 : attr->fs_key_size = rsp_params->fs_key_size;
602 : 0 : attr->wriop_version = le16_to_cpu(rsp_params->wriop_version);
603 : 0 : attr->num_cgs = rsp_params->num_cgs;
604 : :
605 : 0 : return 0;
606 : : }
607 : :
608 : : /**
609 : : * dpni_set_errors_behavior() - Set errors behavior
610 : : * @mc_io: Pointer to MC portal's I/O object
611 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
612 : : * @token: Token of DPNI object
613 : : * @cfg: Errors configuration
614 : : *
615 : : * This function may be called numerous times with different
616 : : * error masks
617 : : *
618 : : * Return: '0' on Success; Error code otherwise.
619 : : */
620 : 0 : int dpni_set_errors_behavior(struct fsl_mc_io *mc_io,
621 : : uint32_t cmd_flags,
622 : : uint16_t token,
623 : : struct dpni_error_cfg *cfg)
624 : : {
625 : 0 : struct mc_command cmd = { 0 };
626 : : struct dpni_cmd_set_errors_behavior *cmd_params;
627 : :
628 : : /* prepare command */
629 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR,
630 : : cmd_flags,
631 : : token);
632 : : cmd_params = (struct dpni_cmd_set_errors_behavior *)cmd.params;
633 : 0 : cmd_params->errors = cpu_to_le32(cfg->errors);
634 : 0 : dpni_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
635 : 0 : dpni_set_field(cmd_params->flags, FRAME_ANN, cfg->set_frame_annotation);
636 : :
637 : : /* send command to mc*/
638 : 0 : return mc_send_command(mc_io, &cmd);
639 : : }
640 : :
641 : : /**
642 : : * dpni_get_buffer_layout() - Retrieve buffer layout attributes.
643 : : * @mc_io: Pointer to MC portal's I/O object
644 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
645 : : * @token: Token of DPNI object
646 : : * @qtype: Type of queue to retrieve configuration for
647 : : * @layout: Returns buffer layout attributes
648 : : *
649 : : * Return: '0' on Success; Error code otherwise.
650 : : */
651 : 0 : int dpni_get_buffer_layout(struct fsl_mc_io *mc_io,
652 : : uint32_t cmd_flags,
653 : : uint16_t token,
654 : : enum dpni_queue_type qtype,
655 : : struct dpni_buffer_layout *layout)
656 : : {
657 : 0 : struct mc_command cmd = { 0 };
658 : : struct dpni_cmd_get_buffer_layout *cmd_params;
659 : : struct dpni_rsp_get_buffer_layout *rsp_params;
660 : : int err;
661 : :
662 : : /* prepare command */
663 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_BUFFER_LAYOUT,
664 : : cmd_flags,
665 : : token);
666 : : cmd_params = (struct dpni_cmd_get_buffer_layout *)cmd.params;
667 : 0 : cmd_params->qtype = qtype;
668 : :
669 : : /* send command to mc*/
670 : 0 : err = mc_send_command(mc_io, &cmd);
671 [ # # ]: 0 : if (err)
672 : : return err;
673 : :
674 : : /* retrieve response parameters */
675 : : rsp_params = (struct dpni_rsp_get_buffer_layout *)cmd.params;
676 : 0 : layout->pass_timestamp =
677 : 0 : (int)dpni_get_field(rsp_params->flags, PASS_TS);
678 : 0 : layout->pass_parser_result =
679 : 0 : (int)dpni_get_field(rsp_params->flags, PASS_PR);
680 : 0 : layout->pass_frame_status =
681 : 0 : (int)dpni_get_field(rsp_params->flags, PASS_FS);
682 : 0 : layout->pass_sw_opaque =
683 : 0 : (int)dpni_get_field(rsp_params->flags, PASS_SWO);
684 : 0 : layout->private_data_size = le16_to_cpu(rsp_params->private_data_size);
685 : 0 : layout->data_align = le16_to_cpu(rsp_params->data_align);
686 : 0 : layout->data_head_room = le16_to_cpu(rsp_params->head_room);
687 : 0 : layout->data_tail_room = le16_to_cpu(rsp_params->tail_room);
688 : :
689 : 0 : return 0;
690 : : }
691 : :
692 : : /**
693 : : * dpni_set_buffer_layout() - Set buffer layout configuration.
694 : : * @mc_io: Pointer to MC portal's I/O object
695 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
696 : : * @token: Token of DPNI object
697 : : * @qtype: Type of queue this configuration applies to
698 : : * @layout: Buffer layout configuration
699 : : *
700 : : * Return: '0' on Success; Error code otherwise.
701 : : *
702 : : * @warning Allowed only when DPNI is disabled
703 : : */
704 : 0 : int dpni_set_buffer_layout(struct fsl_mc_io *mc_io,
705 : : uint32_t cmd_flags,
706 : : uint16_t token,
707 : : enum dpni_queue_type qtype,
708 : : const struct dpni_buffer_layout *layout)
709 : : {
710 : 0 : struct mc_command cmd = { 0 };
711 : : struct dpni_cmd_set_buffer_layout *cmd_params;
712 : :
713 : : /* prepare command */
714 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT,
715 : : cmd_flags,
716 : : token);
717 : : cmd_params = (struct dpni_cmd_set_buffer_layout *)cmd.params;
718 : 0 : cmd_params->qtype = qtype;
719 : 0 : cmd_params->options = cpu_to_le16((uint16_t)layout->options);
720 : 0 : dpni_set_field(cmd_params->flags, PASS_TS, layout->pass_timestamp);
721 : 0 : dpni_set_field(cmd_params->flags, PASS_PR, layout->pass_parser_result);
722 : 0 : dpni_set_field(cmd_params->flags, PASS_FS, layout->pass_frame_status);
723 : 0 : dpni_set_field(cmd_params->flags, PASS_SWO, layout->pass_sw_opaque);
724 : 0 : cmd_params->private_data_size = cpu_to_le16(layout->private_data_size);
725 : 0 : cmd_params->data_align = cpu_to_le16(layout->data_align);
726 : 0 : cmd_params->head_room = cpu_to_le16(layout->data_head_room);
727 : 0 : cmd_params->tail_room = cpu_to_le16(layout->data_tail_room);
728 : :
729 : : /* send command to mc*/
730 : 0 : return mc_send_command(mc_io, &cmd);
731 : : }
732 : :
733 : : /**
734 : : * dpni_set_offload() - Set DPNI offload configuration.
735 : : * @mc_io: Pointer to MC portal's I/O object
736 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
737 : : * @token: Token of DPNI object
738 : : * @type: Type of DPNI offload
739 : : * @config: Offload configuration.
740 : : * For checksum offloads, non-zero value enables the offload
741 : : *
742 : : * Return: '0' on Success; Error code otherwise.
743 : : *
744 : : * @warning Allowed only when DPNI is disabled
745 : : */
746 : :
747 : 0 : int dpni_set_offload(struct fsl_mc_io *mc_io,
748 : : uint32_t cmd_flags,
749 : : uint16_t token,
750 : : enum dpni_offload type,
751 : : uint32_t config)
752 : : {
753 : 0 : struct mc_command cmd = { 0 };
754 : : struct dpni_cmd_set_offload *cmd_params;
755 : :
756 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD,
757 : : cmd_flags,
758 : : token);
759 : : cmd_params = (struct dpni_cmd_set_offload *)cmd.params;
760 : 0 : cmd_params->dpni_offload = type;
761 : 0 : cmd_params->config = cpu_to_le32(config);
762 : :
763 : 0 : return mc_send_command(mc_io, &cmd);
764 : : }
765 : :
766 : : /**
767 : : * dpni_get_offload() - Get DPNI offload configuration.
768 : : * @mc_io: Pointer to MC portal's I/O object
769 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
770 : : * @token: Token of DPNI object
771 : : * @type: Type of DPNI offload
772 : : * @config: Offload configuration.
773 : : * For checksum offloads, a value of 1 indicates that the
774 : : * offload is enabled.
775 : : *
776 : : * Return: '0' on Success; Error code otherwise.
777 : : *
778 : : * @warning Allowed only when DPNI is disabled
779 : : */
780 : 0 : int dpni_get_offload(struct fsl_mc_io *mc_io,
781 : : uint32_t cmd_flags,
782 : : uint16_t token,
783 : : enum dpni_offload type,
784 : : uint32_t *config)
785 : : {
786 : 0 : struct mc_command cmd = { 0 };
787 : : struct dpni_cmd_get_offload *cmd_params;
788 : : struct dpni_rsp_get_offload *rsp_params;
789 : : int err;
790 : :
791 : : /* prepare command */
792 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OFFLOAD,
793 : : cmd_flags,
794 : : token);
795 : : cmd_params = (struct dpni_cmd_get_offload *)cmd.params;
796 : 0 : cmd_params->dpni_offload = type;
797 : :
798 : : /* send command to mc*/
799 : 0 : err = mc_send_command(mc_io, &cmd);
800 [ # # ]: 0 : if (err)
801 : : return err;
802 : :
803 : : /* retrieve response parameters */
804 : : rsp_params = (struct dpni_rsp_get_offload *)cmd.params;
805 : 0 : *config = le32_to_cpu(rsp_params->config);
806 : :
807 : 0 : return 0;
808 : : }
809 : :
810 : : /**
811 : : * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used
812 : : * for enqueue operations
813 : : * @mc_io: Pointer to MC portal's I/O object
814 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
815 : : * @token: Token of DPNI object
816 : : * @qtype: Type of queue to receive QDID for
817 : : * @qdid: Returned virtual QDID value that should be used as an argument
818 : : * in all enqueue operations
819 : : *
820 : : * Return: '0' on Success; Error code otherwise.
821 : : *
822 : : * If dpni object is created using multiple Tc channels this function will return
823 : : * qdid value for the first channel
824 : : */
825 : 0 : int dpni_get_qdid(struct fsl_mc_io *mc_io,
826 : : uint32_t cmd_flags,
827 : : uint16_t token,
828 : : enum dpni_queue_type qtype,
829 : : uint16_t *qdid)
830 : : {
831 : 0 : struct mc_command cmd = { 0 };
832 : : struct dpni_cmd_get_qdid *cmd_params;
833 : : struct dpni_rsp_get_qdid *rsp_params;
834 : : int err;
835 : :
836 : : /* prepare command */
837 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID,
838 : : cmd_flags,
839 : : token);
840 : : cmd_params = (struct dpni_cmd_get_qdid *)cmd.params;
841 : 0 : cmd_params->qtype = qtype;
842 : :
843 : : /* send command to mc*/
844 : 0 : err = mc_send_command(mc_io, &cmd);
845 [ # # ]: 0 : if (err)
846 : : return err;
847 : :
848 : : /* retrieve response parameters */
849 : : rsp_params = (struct dpni_rsp_get_qdid *)cmd.params;
850 : 0 : *qdid = le16_to_cpu(rsp_params->qdid);
851 : :
852 : 0 : return 0;
853 : : }
854 : :
855 : : /**
856 : : * dpni_get_tx_data_offset() - Get the Tx data offset (from start of buffer)
857 : : * @mc_io: Pointer to MC portal's I/O object
858 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
859 : : * @token: Token of DPNI object
860 : : * @data_offset: Tx data offset (from start of buffer)
861 : : *
862 : : * Return: '0' on Success; Error code otherwise.
863 : : */
864 : 0 : int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io,
865 : : uint32_t cmd_flags,
866 : : uint16_t token,
867 : : uint16_t *data_offset)
868 : : {
869 : 0 : struct mc_command cmd = { 0 };
870 : : struct dpni_rsp_get_tx_data_offset *rsp_params;
871 : : int err;
872 : :
873 : : /* prepare command */
874 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET,
875 : : cmd_flags,
876 : : token);
877 : :
878 : : /* send command to mc*/
879 : 0 : err = mc_send_command(mc_io, &cmd);
880 [ # # ]: 0 : if (err)
881 : : return err;
882 : :
883 : : /* retrieve response parameters */
884 : : rsp_params = (struct dpni_rsp_get_tx_data_offset *)cmd.params;
885 : 0 : *data_offset = le16_to_cpu(rsp_params->data_offset);
886 : :
887 : 0 : return 0;
888 : : }
889 : :
890 : : /**
891 : : * dpni_set_link_cfg() - set the link configuration.
892 : : * @mc_io: Pointer to MC portal's I/O object
893 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
894 : : * @token: Token of DPNI object
895 : : * @cfg: Link configuration
896 : : *
897 : : * Return: '0' on Success; Error code otherwise.
898 : : */
899 : 0 : int dpni_set_link_cfg(struct fsl_mc_io *mc_io,
900 : : uint32_t cmd_flags,
901 : : uint16_t token,
902 : : const struct dpni_link_cfg *cfg)
903 : : {
904 : 0 : struct mc_command cmd = { 0 };
905 : : struct dpni_cmd_set_link_cfg *cmd_params;
906 : :
907 : : /* prepare command */
908 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG,
909 : : cmd_flags,
910 : : token);
911 : : cmd_params = (struct dpni_cmd_set_link_cfg *)cmd.params;
912 : 0 : cmd_params->rate = cpu_to_le32(cfg->rate);
913 : 0 : cmd_params->options = cpu_to_le64(cfg->options);
914 : 0 : cmd_params->advertising = cpu_to_le64(cfg->advertising);
915 : :
916 : : /* send command to mc*/
917 : 0 : return mc_send_command(mc_io, &cmd);
918 : : }
919 : :
920 : : /**
921 : : * dpni_get_link_cfg() - return the link configuration configured by
922 : : * dpni_set_link_cfg().
923 : : * @mc_io: Pointer to MC portal's I/O object
924 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
925 : : * @token: Token of DPNI object
926 : : * @cfg: Link configuration from dpni object
927 : : *
928 : : * Return: '0' on Success; Error code otherwise.
929 : : */
930 : 0 : int dpni_get_link_cfg(struct fsl_mc_io *mc_io,
931 : : uint32_t cmd_flags,
932 : : uint16_t token,
933 : : struct dpni_link_cfg *cfg)
934 : : {
935 : 0 : struct mc_command cmd = { 0 };
936 : : struct dpni_cmd_set_link_cfg *rsp_params;
937 : : int err;
938 : :
939 : : /* prepare command */
940 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_CFG,
941 : : cmd_flags,
942 : : token);
943 : :
944 : : /* send command to mc*/
945 : 0 : err = mc_send_command(mc_io, &cmd);
946 [ # # ]: 0 : if (err)
947 : : return err;
948 : :
949 : : /* retrieve response parameters */
950 : : rsp_params = (struct dpni_cmd_set_link_cfg *)cmd.params;
951 : 0 : cfg->advertising = le64_to_cpu(rsp_params->advertising);
952 : 0 : cfg->options = le64_to_cpu(rsp_params->options);
953 : 0 : cfg->rate = le32_to_cpu(rsp_params->rate);
954 : :
955 : 0 : return err;
956 : : }
957 : :
958 : : /**
959 : : * dpni_get_link_state() - Return the link state (either up or down)
960 : : * @mc_io: Pointer to MC portal's I/O object
961 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
962 : : * @token: Token of DPNI object
963 : : * @state: Returned link state;
964 : : *
965 : : * Return: '0' on Success; Error code otherwise.
966 : : */
967 : 0 : int dpni_get_link_state(struct fsl_mc_io *mc_io,
968 : : uint32_t cmd_flags,
969 : : uint16_t token,
970 : : struct dpni_link_state *state)
971 : : {
972 : 0 : struct mc_command cmd = { 0 };
973 : : struct dpni_rsp_get_link_state *rsp_params;
974 : : int err;
975 : :
976 : : /* prepare command */
977 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE,
978 : : cmd_flags,
979 : : token);
980 : :
981 : : /* send command to mc*/
982 : 0 : err = mc_send_command(mc_io, &cmd);
983 [ # # ]: 0 : if (err)
984 : : return err;
985 : :
986 : : /* retrieve response parameters */
987 : : rsp_params = (struct dpni_rsp_get_link_state *)cmd.params;
988 : 0 : state->up = dpni_get_field(rsp_params->flags, LINK_STATE);
989 : 0 : state->state_valid = dpni_get_field(rsp_params->flags, STATE_VALID);
990 : 0 : state->rate = le32_to_cpu(rsp_params->rate);
991 : 0 : state->options = le64_to_cpu(rsp_params->options);
992 : 0 : state->supported = le64_to_cpu(rsp_params->supported);
993 : 0 : state->advertising = le64_to_cpu(rsp_params->advertising);
994 : :
995 : 0 : return 0;
996 : : }
997 : :
998 : : /**
999 : : * dpni_set_tx_shaping() - Set the transmit shaping
1000 : : * @mc_io: Pointer to MC portal's I/O object
1001 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1002 : : * @token: Token of DPNI object
1003 : : * @tx_cr_shaper: TX committed rate shaping configuration
1004 : : * @tx_er_shaper: TX excess rate shaping configuration
1005 : : * @param: Special parameters
1006 : : * bit0: Committed and excess rates are coupled
1007 : : * bit1: 1 modify LNI shaper, 0 modify channel shaper
1008 : : * bit8-15: Tx channel to be shaped. Used only if bit1 is set to zero
1009 : : * bits16-26: OAL (Overhead accounting length 11bit value). Used only
1010 : : * when bit1 is set.
1011 : : *
1012 : : * Return: '0' on Success; Error code otherwise.
1013 : : */
1014 : 0 : int dpni_set_tx_shaping(struct fsl_mc_io *mc_io,
1015 : : uint32_t cmd_flags,
1016 : : uint16_t token,
1017 : : const struct dpni_tx_shaping_cfg *tx_cr_shaper,
1018 : : const struct dpni_tx_shaping_cfg *tx_er_shaper,
1019 : : uint32_t param)
1020 : : {
1021 : : struct dpni_cmd_set_tx_shaping *cmd_params;
1022 : 0 : struct mc_command cmd = { 0 };
1023 : : int coupled, lni_shaper;
1024 : : uint8_t channel_id;
1025 : : uint16_t oal;
1026 : :
1027 : : /* prepare command */
1028 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_SHAPING,
1029 : : cmd_flags,
1030 : : token);
1031 : : cmd_params = (struct dpni_cmd_set_tx_shaping *)cmd.params;
1032 : 0 : cmd_params->tx_cr_max_burst_size =
1033 : 0 : cpu_to_le16(tx_cr_shaper->max_burst_size);
1034 : 0 : cmd_params->tx_er_max_burst_size =
1035 : 0 : cpu_to_le16(tx_er_shaper->max_burst_size);
1036 : 0 : cmd_params->tx_cr_rate_limit =
1037 : 0 : cpu_to_le32(tx_cr_shaper->rate_limit);
1038 : 0 : cmd_params->tx_er_rate_limit =
1039 : 0 : cpu_to_le32(tx_er_shaper->rate_limit);
1040 : :
1041 : 0 : coupled = !!(param & 0x01);
1042 : 0 : dpni_set_field(cmd_params->options, COUPLED, coupled);
1043 : :
1044 : 0 : lni_shaper = !!((param >> 1) & 0x01);
1045 : 0 : dpni_set_field(cmd_params->options, LNI_SHAPER, lni_shaper);
1046 : :
1047 : 0 : channel_id = (param >> 8) & 0xff;
1048 : 0 : cmd_params->channel_id = channel_id;
1049 : :
1050 : 0 : oal = (param >> 16) & 0x7FF;
1051 : 0 : cmd_params->oal = cpu_to_le16(oal);
1052 : :
1053 : : /* send command to mc*/
1054 : 0 : return mc_send_command(mc_io, &cmd);
1055 : : }
1056 : :
1057 : : /**
1058 : : * dpni_set_max_frame_length() - Set the maximum received frame length.
1059 : : * @mc_io: Pointer to MC portal's I/O object
1060 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1061 : : * @token: Token of DPNI object
1062 : : * @max_frame_length: Maximum received frame length (in bytes);
1063 : : * frame is discarded if its length exceeds this value
1064 : : *
1065 : : * Return: '0' on Success; Error code otherwise.
1066 : : */
1067 : 0 : int dpni_set_max_frame_length(struct fsl_mc_io *mc_io,
1068 : : uint32_t cmd_flags,
1069 : : uint16_t token,
1070 : : uint16_t max_frame_length)
1071 : : {
1072 : 0 : struct mc_command cmd = { 0 };
1073 : : struct dpni_cmd_set_max_frame_length *cmd_params;
1074 : :
1075 : : /* prepare command */
1076 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH,
1077 : : cmd_flags,
1078 : : token);
1079 : : cmd_params = (struct dpni_cmd_set_max_frame_length *)cmd.params;
1080 : 0 : cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
1081 : :
1082 : : /* send command to mc*/
1083 : 0 : return mc_send_command(mc_io, &cmd);
1084 : : }
1085 : :
1086 : : /**
1087 : : * dpni_get_max_frame_length() - Get the maximum received frame length.
1088 : : * @mc_io: Pointer to MC portal's I/O object
1089 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1090 : : * @token: Token of DPNI object
1091 : : * @max_frame_length: Maximum received frame length (in bytes);
1092 : : * frame is discarded if its length exceeds this value
1093 : : *
1094 : : * Return: '0' on Success; Error code otherwise.
1095 : : */
1096 : 0 : int dpni_get_max_frame_length(struct fsl_mc_io *mc_io,
1097 : : uint32_t cmd_flags,
1098 : : uint16_t token,
1099 : : uint16_t *max_frame_length)
1100 : : {
1101 : 0 : struct mc_command cmd = { 0 };
1102 : : struct dpni_rsp_get_max_frame_length *rsp_params;
1103 : : int err;
1104 : :
1105 : : /* prepare command */
1106 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH,
1107 : : cmd_flags,
1108 : : token);
1109 : :
1110 : : /* send command to mc*/
1111 : 0 : err = mc_send_command(mc_io, &cmd);
1112 [ # # ]: 0 : if (err)
1113 : : return err;
1114 : :
1115 : : /* retrieve response parameters */
1116 : : rsp_params = (struct dpni_rsp_get_max_frame_length *)cmd.params;
1117 : 0 : *max_frame_length = le16_to_cpu(rsp_params->max_frame_length);
1118 : :
1119 : 0 : return 0;
1120 : : }
1121 : :
1122 : : /**
1123 : : * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode
1124 : : * @mc_io: Pointer to MC portal's I/O object
1125 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1126 : : * @token: Token of DPNI object
1127 : : * @en: Set to '1' to enable; '0' to disable
1128 : : *
1129 : : * Return: '0' on Success; Error code otherwise.
1130 : : */
1131 : 0 : int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io,
1132 : : uint32_t cmd_flags,
1133 : : uint16_t token,
1134 : : int en)
1135 : : {
1136 : 0 : struct mc_command cmd = { 0 };
1137 : : struct dpni_cmd_set_multicast_promisc *cmd_params;
1138 : :
1139 : : /* prepare command */
1140 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC,
1141 : : cmd_flags,
1142 : : token);
1143 : : cmd_params = (struct dpni_cmd_set_multicast_promisc *)cmd.params;
1144 : 0 : dpni_set_field(cmd_params->enable, ENABLE, en);
1145 : :
1146 : : /* send command to mc*/
1147 : 0 : return mc_send_command(mc_io, &cmd);
1148 : : }
1149 : :
1150 : : /**
1151 : : * dpni_get_multicast_promisc() - Get multicast promiscuous mode
1152 : : * @mc_io: Pointer to MC portal's I/O object
1153 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1154 : : * @token: Token of DPNI object
1155 : : * @en: Returns '1' if enabled; '0' otherwise
1156 : : *
1157 : : * Return: '0' on Success; Error code otherwise.
1158 : : */
1159 : 0 : int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io,
1160 : : uint32_t cmd_flags,
1161 : : uint16_t token,
1162 : : int *en)
1163 : : {
1164 : 0 : struct mc_command cmd = { 0 };
1165 : : struct dpni_rsp_get_multicast_promisc *rsp_params;
1166 : : int err;
1167 : :
1168 : : /* prepare command */
1169 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC,
1170 : : cmd_flags,
1171 : : token);
1172 : :
1173 : : /* send command to mc*/
1174 : 0 : err = mc_send_command(mc_io, &cmd);
1175 [ # # ]: 0 : if (err)
1176 : : return err;
1177 : :
1178 : : /* retrieve response parameters */
1179 : : rsp_params = (struct dpni_rsp_get_multicast_promisc *)cmd.params;
1180 : 0 : *en = dpni_get_field(rsp_params->enabled, ENABLE);
1181 : :
1182 : 0 : return 0;
1183 : : }
1184 : :
1185 : : /**
1186 : : * dpni_set_unicast_promisc() - Enable/disable unicast promiscuous mode
1187 : : * @mc_io: Pointer to MC portal's I/O object
1188 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1189 : : * @token: Token of DPNI object
1190 : : * @en: Set to '1' to enable; '0' to disable
1191 : : *
1192 : : * Return: '0' on Success; Error code otherwise.
1193 : : */
1194 : 0 : int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io,
1195 : : uint32_t cmd_flags,
1196 : : uint16_t token,
1197 : : int en)
1198 : : {
1199 : 0 : struct mc_command cmd = { 0 };
1200 : : struct dpni_cmd_set_unicast_promisc *cmd_params;
1201 : :
1202 : : /* prepare command */
1203 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC,
1204 : : cmd_flags,
1205 : : token);
1206 : : cmd_params = (struct dpni_cmd_set_unicast_promisc *)cmd.params;
1207 : 0 : dpni_set_field(cmd_params->enable, ENABLE, en);
1208 : :
1209 : : /* send command to mc*/
1210 : 0 : return mc_send_command(mc_io, &cmd);
1211 : : }
1212 : :
1213 : : /**
1214 : : * dpni_get_unicast_promisc() - Get unicast promiscuous mode
1215 : : * @mc_io: Pointer to MC portal's I/O object
1216 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1217 : : * @token: Token of DPNI object
1218 : : * @en: Returns '1' if enabled; '0' otherwise
1219 : : *
1220 : : * Return: '0' on Success; Error code otherwise.
1221 : : */
1222 : 0 : int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io,
1223 : : uint32_t cmd_flags,
1224 : : uint16_t token,
1225 : : int *en)
1226 : : {
1227 : 0 : struct mc_command cmd = { 0 };
1228 : : struct dpni_rsp_get_unicast_promisc *rsp_params;
1229 : : int err;
1230 : :
1231 : : /* prepare command */
1232 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC,
1233 : : cmd_flags,
1234 : : token);
1235 : :
1236 : : /* send command to mc*/
1237 : 0 : err = mc_send_command(mc_io, &cmd);
1238 [ # # ]: 0 : if (err)
1239 : : return err;
1240 : :
1241 : : /* retrieve response parameters */
1242 : : rsp_params = (struct dpni_rsp_get_unicast_promisc *)cmd.params;
1243 : 0 : *en = dpni_get_field(rsp_params->enabled, ENABLE);
1244 : :
1245 : 0 : return 0;
1246 : : }
1247 : :
1248 : : /**
1249 : : * dpni_set_primary_mac_addr() - Set the primary MAC address
1250 : : * @mc_io: Pointer to MC portal's I/O object
1251 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1252 : : * @token: Token of DPNI object
1253 : : * @mac_addr: MAC address to set as primary address
1254 : : *
1255 : : * Return: '0' on Success; Error code otherwise.
1256 : : */
1257 : 0 : int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io,
1258 : : uint32_t cmd_flags,
1259 : : uint16_t token,
1260 : : const uint8_t mac_addr[6])
1261 : : {
1262 : 0 : struct mc_command cmd = { 0 };
1263 : : struct dpni_cmd_set_primary_mac_addr *cmd_params;
1264 : : int i;
1265 : :
1266 : : /* prepare command */
1267 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC,
1268 : : cmd_flags,
1269 : : token);
1270 : : cmd_params = (struct dpni_cmd_set_primary_mac_addr *)cmd.params;
1271 [ # # ]: 0 : for (i = 0; i < 6; i++)
1272 : 0 : cmd_params->mac_addr[i] = mac_addr[5 - i];
1273 : :
1274 : : /* send command to mc*/
1275 : 0 : return mc_send_command(mc_io, &cmd);
1276 : : }
1277 : :
1278 : : /**
1279 : : * dpni_get_primary_mac_addr() - Get the primary MAC address
1280 : : * @mc_io: Pointer to MC portal's I/O object
1281 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1282 : : * @token: Token of DPNI object
1283 : : * @mac_addr: Returned MAC address
1284 : : *
1285 : : * Return: '0' on Success; Error code otherwise.
1286 : : */
1287 : 0 : int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io,
1288 : : uint32_t cmd_flags,
1289 : : uint16_t token,
1290 : : uint8_t mac_addr[6])
1291 : : {
1292 : 0 : struct mc_command cmd = { 0 };
1293 : : struct dpni_rsp_get_primary_mac_addr *rsp_params;
1294 : : int i, err;
1295 : :
1296 : : /* prepare command */
1297 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC,
1298 : : cmd_flags,
1299 : : token);
1300 : :
1301 : : /* send command to mc*/
1302 : 0 : err = mc_send_command(mc_io, &cmd);
1303 [ # # ]: 0 : if (err)
1304 : : return err;
1305 : :
1306 : : /* retrieve response parameters */
1307 : : rsp_params = (struct dpni_rsp_get_primary_mac_addr *)cmd.params;
1308 [ # # ]: 0 : for (i = 0; i < 6; i++)
1309 : 0 : mac_addr[5 - i] = rsp_params->mac_addr[i];
1310 : :
1311 : : return 0;
1312 : : }
1313 : :
1314 : : /**
1315 : : * dpni_add_mac_addr() - Add MAC address filter
1316 : : * @mc_io: Pointer to MC portal's I/O object
1317 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1318 : : * @token: Token of DPNI object
1319 : : * @mac_addr: MAC address to add
1320 : : * @flags : 0 - tc_id and flow_id will be ignored.
1321 : : * Pkt with this mac_id will be passed to the next
1322 : : * classification stages
1323 : : * DPNI_MAC_SET_QUEUE_ACTION
1324 : : * Pkt with this mac will be forward directly to
1325 : : * queue defined by the tc_id and flow_id
1326 : : * @tc_id : Traffic class selection (0-7)
1327 : : * @flow_id : Selects the specific queue out of the set allocated for the
1328 : : * same as tc_id. Value must be in range 0 to NUM_QUEUES - 1
1329 : : * Return: '0' on Success; Error code otherwise.
1330 : : */
1331 : 0 : int dpni_add_mac_addr(struct fsl_mc_io *mc_io,
1332 : : uint32_t cmd_flags,
1333 : : uint16_t token,
1334 : : const uint8_t mac_addr[6],
1335 : : uint8_t flags,
1336 : : uint8_t tc_id,
1337 : : uint8_t flow_id)
1338 : : {
1339 : 0 : struct mc_command cmd = { 0 };
1340 : : struct dpni_cmd_add_mac_addr *cmd_params;
1341 : : int i;
1342 : :
1343 : : /* prepare command */
1344 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR,
1345 : : cmd_flags,
1346 : : token);
1347 : : cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params;
1348 : 0 : cmd_params->flags = flags;
1349 : 0 : cmd_params->tc_id = tc_id;
1350 : 0 : cmd_params->fq_id = flow_id;
1351 : :
1352 [ # # ]: 0 : for (i = 0; i < 6; i++)
1353 : 0 : cmd_params->mac_addr[i] = mac_addr[5 - i];
1354 : :
1355 : : /* send command to mc*/
1356 : 0 : return mc_send_command(mc_io, &cmd);
1357 : : }
1358 : :
1359 : : /**
1360 : : * dpni_remove_mac_addr() - Remove MAC address filter
1361 : : * @mc_io: Pointer to MC portal's I/O object
1362 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1363 : : * @token: Token of DPNI object
1364 : : * @mac_addr: MAC address to remove
1365 : : *
1366 : : * Return: '0' on Success; Error code otherwise.
1367 : : */
1368 : 0 : int dpni_remove_mac_addr(struct fsl_mc_io *mc_io,
1369 : : uint32_t cmd_flags,
1370 : : uint16_t token,
1371 : : const uint8_t mac_addr[6])
1372 : : {
1373 : 0 : struct mc_command cmd = { 0 };
1374 : : struct dpni_cmd_remove_mac_addr *cmd_params;
1375 : : int i;
1376 : :
1377 : : /* prepare command */
1378 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR,
1379 : : cmd_flags,
1380 : : token);
1381 : : cmd_params = (struct dpni_cmd_remove_mac_addr *)cmd.params;
1382 [ # # ]: 0 : for (i = 0; i < 6; i++)
1383 : 0 : cmd_params->mac_addr[i] = mac_addr[5 - i];
1384 : :
1385 : : /* send command to mc*/
1386 : 0 : return mc_send_command(mc_io, &cmd);
1387 : : }
1388 : :
1389 : : /**
1390 : : * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters
1391 : : * @mc_io: Pointer to MC portal's I/O object
1392 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1393 : : * @token: Token of DPNI object
1394 : : * @unicast: Set to '1' to clear unicast addresses
1395 : : * @multicast: Set to '1' to clear multicast addresses
1396 : : *
1397 : : * The primary MAC address is not cleared by this operation.
1398 : : *
1399 : : * Return: '0' on Success; Error code otherwise.
1400 : : */
1401 : 0 : int dpni_clear_mac_filters(struct fsl_mc_io *mc_io,
1402 : : uint32_t cmd_flags,
1403 : : uint16_t token,
1404 : : int unicast,
1405 : : int multicast)
1406 : : {
1407 : 0 : struct mc_command cmd = { 0 };
1408 : : struct dpni_cmd_clear_mac_filters *cmd_params;
1409 : :
1410 : : /* prepare command */
1411 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS,
1412 : : cmd_flags,
1413 : : token);
1414 : : cmd_params = (struct dpni_cmd_clear_mac_filters *)cmd.params;
1415 : 0 : dpni_set_field(cmd_params->flags, UNICAST_FILTERS, unicast);
1416 : 0 : dpni_set_field(cmd_params->flags, MULTICAST_FILTERS, multicast);
1417 : :
1418 : : /* send command to mc*/
1419 : 0 : return mc_send_command(mc_io, &cmd);
1420 : : }
1421 : :
1422 : : /**
1423 : : * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical
1424 : : * port the DPNI is attached to
1425 : : * @mc_io: Pointer to MC portal's I/O object
1426 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1427 : : * @token: Token of DPNI object
1428 : : * @mac_addr: MAC address of the physical port, if any, otherwise 0
1429 : : *
1430 : : * The primary MAC address is not cleared by this operation.
1431 : : *
1432 : : * Return: '0' on Success; Error code otherwise.
1433 : : */
1434 : 0 : int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io,
1435 : : uint32_t cmd_flags,
1436 : : uint16_t token,
1437 : : uint8_t mac_addr[6])
1438 : : {
1439 : 0 : struct mc_command cmd = { 0 };
1440 : : struct dpni_rsp_get_port_mac_addr *rsp_params;
1441 : : int i, err;
1442 : :
1443 : : /* prepare command */
1444 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR,
1445 : : cmd_flags,
1446 : : token);
1447 : :
1448 : : /* send command to mc*/
1449 : 0 : err = mc_send_command(mc_io, &cmd);
1450 [ # # ]: 0 : if (err)
1451 : : return err;
1452 : :
1453 : : /* retrieve response parameters */
1454 : : rsp_params = (struct dpni_rsp_get_port_mac_addr *)cmd.params;
1455 [ # # ]: 0 : for (i = 0; i < 6; i++)
1456 : 0 : mac_addr[5 - i] = rsp_params->mac_addr[i];
1457 : :
1458 : : return 0;
1459 : : }
1460 : :
1461 : : /**
1462 : : * dpni_enable_vlan_filter() - Enable/disable VLAN filtering mode
1463 : : * @mc_io: Pointer to MC portal's I/O object
1464 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1465 : : * @token: Token of DPNI object
1466 : : * @en: Set to '1' to enable; '0' to disable
1467 : : *
1468 : : * Return: '0' on Success; Error code otherwise.
1469 : : */
1470 : 0 : int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io,
1471 : : uint32_t cmd_flags,
1472 : : uint16_t token,
1473 : : int en)
1474 : : {
1475 : : struct dpni_cmd_enable_vlan_filter *cmd_params;
1476 : 0 : struct mc_command cmd = { 0 };
1477 : :
1478 : : /* prepare command */
1479 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_VLAN_FILTER,
1480 : : cmd_flags,
1481 : : token);
1482 : : cmd_params = (struct dpni_cmd_enable_vlan_filter *)cmd.params;
1483 : 0 : dpni_set_field(cmd_params->en, ENABLE, en);
1484 : :
1485 : : /* send command to mc*/
1486 : 0 : return mc_send_command(mc_io, &cmd);
1487 : : }
1488 : :
1489 : : /**
1490 : : * dpni_add_vlan_id() - Add VLAN ID filter
1491 : : * @mc_io: Pointer to MC portal's I/O object
1492 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1493 : : * @token: Token of DPNI object
1494 : : * @vlan_id: VLAN ID to add
1495 : : * @flags: 0 - tc_id and flow_id will be ignored.
1496 : : * Pkt with this vlan_id will be passed to the next
1497 : : * classification stages
1498 : : * DPNI_VLAN_SET_QUEUE_ACTION
1499 : : * Pkt with this vlan_id will be forward directly to
1500 : : * queue defined by the tc_id and flow_id
1501 : : *
1502 : : * @tc_id: Traffic class selection (0-7)
1503 : : * @flow_id: Selects the specific queue out of the set allocated for the
1504 : : * same as tc_id. Value must be in range 0 to NUM_QUEUES - 1
1505 : : *
1506 : : * Return: '0' on Success; Error code otherwise.
1507 : : */
1508 : 0 : int dpni_add_vlan_id(struct fsl_mc_io *mc_io,
1509 : : uint32_t cmd_flags,
1510 : : uint16_t token,
1511 : : uint16_t vlan_id,
1512 : : uint8_t flags,
1513 : : uint8_t tc_id,
1514 : : uint8_t flow_id)
1515 : : {
1516 : : struct dpni_cmd_vlan_id *cmd_params;
1517 : 0 : struct mc_command cmd = { 0 };
1518 : :
1519 : : /* prepare command */
1520 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_VLAN_ID,
1521 : : cmd_flags,
1522 : : token);
1523 : : cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1524 : 0 : cmd_params->flags = flags;
1525 : 0 : cmd_params->tc_id = tc_id;
1526 : 0 : cmd_params->flow_id = flow_id;
1527 : 0 : cmd_params->vlan_id = cpu_to_le16(vlan_id);
1528 : :
1529 : : /* send command to mc*/
1530 : 0 : return mc_send_command(mc_io, &cmd);
1531 : : }
1532 : :
1533 : : /**
1534 : : * dpni_remove_vlan_id() - Remove VLAN ID filter
1535 : : * @mc_io: Pointer to MC portal's I/O object
1536 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1537 : : * @token: Token of DPNI object
1538 : : * @vlan_id: VLAN ID to remove
1539 : : *
1540 : : * Return: '0' on Success; Error code otherwise.
1541 : : */
1542 : 0 : int dpni_remove_vlan_id(struct fsl_mc_io *mc_io,
1543 : : uint32_t cmd_flags,
1544 : : uint16_t token,
1545 : : uint16_t vlan_id)
1546 : : {
1547 : : struct dpni_cmd_vlan_id *cmd_params;
1548 : 0 : struct mc_command cmd = { 0 };
1549 : :
1550 : : /* prepare command */
1551 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_VLAN_ID,
1552 : : cmd_flags,
1553 : : token);
1554 : : cmd_params = (struct dpni_cmd_vlan_id *)cmd.params;
1555 : 0 : cmd_params->vlan_id = cpu_to_le16(vlan_id);
1556 : :
1557 : : /* send command to mc*/
1558 : 0 : return mc_send_command(mc_io, &cmd);
1559 : : }
1560 : :
1561 : : /**
1562 : : * dpni_clear_vlan_filters() - Clear all VLAN filters
1563 : : * @mc_io: Pointer to MC portal's I/O object
1564 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1565 : : * @token: Token of DPNI object
1566 : : *
1567 : : * Return: '0' on Success; Error code otherwise.
1568 : : */
1569 : 0 : int dpni_clear_vlan_filters(struct fsl_mc_io *mc_io,
1570 : : uint32_t cmd_flags,
1571 : : uint16_t token)
1572 : : {
1573 : 0 : struct mc_command cmd = { 0 };
1574 : :
1575 : : /* prepare command */
1576 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_VLAN_FILTERS,
1577 : : cmd_flags,
1578 : : token);
1579 : :
1580 : : /* send command to mc*/
1581 : 0 : return mc_send_command(mc_io, &cmd);
1582 : : }
1583 : :
1584 : : /**
1585 : : * dpni_set_tx_priorities() - Set transmission TC priority configuration
1586 : : * @mc_io: Pointer to MC portal's I/O object
1587 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1588 : : * @token: Token of DPNI object
1589 : : * @cfg: Transmission selection configuration
1590 : : *
1591 : : * warning: Allowed only when DPNI is disabled
1592 : : *
1593 : : * Return: '0' on Success; Error code otherwise.
1594 : : */
1595 : 0 : int dpni_set_tx_priorities(struct fsl_mc_io *mc_io,
1596 : : uint32_t cmd_flags,
1597 : : uint16_t token,
1598 : : const struct dpni_tx_priorities_cfg *cfg)
1599 : : {
1600 : : struct dpni_cmd_set_tx_priorities *cmd_params;
1601 : 0 : struct mc_command cmd = { 0 };
1602 : : int i;
1603 : :
1604 : : /* prepare command */
1605 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_PRIORITIES,
1606 : : cmd_flags,
1607 : : token);
1608 : : cmd_params = (struct dpni_cmd_set_tx_priorities *)cmd.params;
1609 : 0 : cmd_params->channel_idx = cfg->channel_idx;
1610 : 0 : dpni_set_field(cmd_params->flags,
1611 : : SEPARATE_GRP,
1612 : : cfg->separate_groups);
1613 : 0 : cmd_params->prio_group_A = cfg->prio_group_A;
1614 : 0 : cmd_params->prio_group_B = cfg->prio_group_B;
1615 : :
1616 [ # # ]: 0 : for (i = 0; i + 1 < DPNI_MAX_TC; i = i + 2) {
1617 : 0 : dpni_set_field(cmd_params->modes[i / 2],
1618 : : MODE_1,
1619 : : cfg->tc_sched[i].mode);
1620 : 0 : dpni_set_field(cmd_params->modes[i / 2],
1621 : : MODE_2,
1622 : : cfg->tc_sched[i + 1].mode);
1623 : : }
1624 : :
1625 [ # # ]: 0 : for (i = 0; i < DPNI_MAX_TC; i++) {
1626 : 0 : cmd_params->delta_bandwidth[i] =
1627 : 0 : cpu_to_le16(cfg->tc_sched[i].delta_bandwidth);
1628 : : }
1629 : :
1630 : : /* send command to mc*/
1631 : 0 : return mc_send_command(mc_io, &cmd);
1632 : : }
1633 : :
1634 : : /**
1635 : : * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration
1636 : : * @mc_io: Pointer to MC portal's I/O object
1637 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1638 : : * @token: Token of DPNI object
1639 : : * @tc_id: Traffic class selection (0-7)
1640 : : * @cfg: Traffic class distribution configuration
1641 : : *
1642 : : * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpkg_prepare_key_cfg()
1643 : : * first to prepare the key_cfg_iova parameter
1644 : : *
1645 : : * Return: '0' on Success; error code otherwise.
1646 : : */
1647 : 0 : int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io,
1648 : : uint32_t cmd_flags,
1649 : : uint16_t token,
1650 : : uint8_t tc_id,
1651 : : const struct dpni_rx_tc_dist_cfg *cfg)
1652 : : {
1653 : 0 : struct mc_command cmd = { 0 };
1654 : : struct dpni_cmd_set_rx_tc_dist *cmd_params;
1655 : :
1656 : : /* prepare command */
1657 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST,
1658 : : cmd_flags,
1659 : : token);
1660 : : cmd_params = (struct dpni_cmd_set_rx_tc_dist *)cmd.params;
1661 : 0 : cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
1662 : 0 : cmd_params->tc_id = tc_id;
1663 : 0 : cmd_params->default_flow_id = cpu_to_le16(cfg->fs_cfg.default_flow_id);
1664 : 0 : cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1665 : 0 : dpni_set_field(cmd_params->flags,
1666 : : DIST_MODE,
1667 : : cfg->dist_mode);
1668 : 0 : dpni_set_field(cmd_params->flags,
1669 : : MISS_ACTION,
1670 : : cfg->fs_cfg.miss_action);
1671 : 0 : dpni_set_field(cmd_params->keep_hash_key,
1672 : : KEEP_HASH_KEY,
1673 : : cfg->fs_cfg.keep_hash_key);
1674 : 0 : dpni_set_field(cmd_params->keep_hash_key,
1675 : : KEEP_ENTRIES,
1676 : : cfg->fs_cfg.keep_entries);
1677 : :
1678 : : /* send command to mc*/
1679 : 0 : return mc_send_command(mc_io, &cmd);
1680 : : }
1681 : :
1682 : : /**
1683 : : * dpni_set_tx_confirmation_mode() - Tx confirmation mode
1684 : : * @mc_io: Pointer to MC portal's I/O object
1685 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1686 : : * @token: Token of DPNI object
1687 : : * @mode: Tx confirmation mode
1688 : : *
1689 : : * This function is useful only when 'DPNI_OPT_TX_CONF_DISABLED' is not
1690 : : * selected at DPNI creation.
1691 : : * Calling this function with 'mode' set to DPNI_CONF_DISABLE disables all
1692 : : * transmit confirmation (including the private confirmation queues), regardless
1693 : : * of previous settings; Note that in this case, Tx error frames are still
1694 : : * enqueued to the general transmit errors queue.
1695 : : * Calling this function with 'mode' set to DPNI_CONF_SINGLE switches all
1696 : : * Tx confirmations to a shared Tx conf queue. 'index' field in dpni_get_queue
1697 : : * command will be ignored.
1698 : : *
1699 : : * Return: '0' on Success; Error code otherwise.
1700 : : */
1701 : 0 : int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1702 : : uint32_t cmd_flags,
1703 : : uint16_t token,
1704 : : enum dpni_confirmation_mode mode)
1705 : : {
1706 : : struct dpni_tx_confirmation_mode *cmd_params;
1707 : 0 : struct mc_command cmd = { 0 };
1708 : :
1709 : : /* prepare command */
1710 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONFIRMATION_MODE,
1711 : : cmd_flags,
1712 : : token);
1713 : : cmd_params = (struct dpni_tx_confirmation_mode *)cmd.params;
1714 : 0 : cmd_params->confirmation_mode = mode;
1715 : :
1716 : : /* send command to mc*/
1717 : 0 : return mc_send_command(mc_io, &cmd);
1718 : : }
1719 : :
1720 : : /**
1721 : : * dpni_get_tx_confirmation_mode() - Get Tx confirmation mode
1722 : : * @mc_io: Pointer to MC portal's I/O object
1723 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1724 : : * @token: Token of DPNI object
1725 : : * @mode: Tx confirmation mode
1726 : : *
1727 : : * Return: '0' on Success; Error code otherwise.
1728 : : */
1729 : 0 : int dpni_get_tx_confirmation_mode(struct fsl_mc_io *mc_io,
1730 : : uint32_t cmd_flags,
1731 : : uint16_t token,
1732 : : enum dpni_confirmation_mode *mode)
1733 : : {
1734 : : struct dpni_tx_confirmation_mode *rsp_params;
1735 : 0 : struct mc_command cmd = { 0 };
1736 : : int err;
1737 : :
1738 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_CONFIRMATION_MODE,
1739 : : cmd_flags,
1740 : : token);
1741 : :
1742 : 0 : err = mc_send_command(mc_io, &cmd);
1743 [ # # ]: 0 : if (err)
1744 : : return err;
1745 : :
1746 : : rsp_params = (struct dpni_tx_confirmation_mode *)cmd.params;
1747 : 0 : *mode = rsp_params->confirmation_mode;
1748 : :
1749 : 0 : return 0;
1750 : : }
1751 : :
1752 : : /**
1753 : : * dpni_set_qos_table() - Set QoS mapping table
1754 : : * @mc_io: Pointer to MC portal's I/O object
1755 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1756 : : * @token: Token of DPNI object
1757 : : * @cfg: QoS table configuration
1758 : : *
1759 : : * This function and all QoS-related functions require that
1760 : : *'max_tcs > 1' was set at DPNI creation.
1761 : : *
1762 : : * warning: Before calling this function, call dpkg_prepare_key_cfg() to
1763 : : * prepare the key_cfg_iova parameter
1764 : : *
1765 : : * Return: '0' on Success; Error code otherwise.
1766 : : */
1767 : 0 : int dpni_set_qos_table(struct fsl_mc_io *mc_io,
1768 : : uint32_t cmd_flags,
1769 : : uint16_t token,
1770 : : const struct dpni_qos_tbl_cfg *cfg)
1771 : : {
1772 : : struct dpni_cmd_set_qos_table *cmd_params;
1773 : 0 : struct mc_command cmd = { 0 };
1774 : :
1775 : : /* prepare command */
1776 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QOS_TBL,
1777 : : cmd_flags,
1778 : : token);
1779 : : cmd_params = (struct dpni_cmd_set_qos_table *)cmd.params;
1780 : 0 : cmd_params->default_tc = cfg->default_tc;
1781 : 0 : cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
1782 : 0 : dpni_set_field(cmd_params->discard_on_miss,
1783 : : ENABLE,
1784 : : cfg->discard_on_miss);
1785 : 0 : dpni_set_field(cmd_params->discard_on_miss,
1786 : : KEEP_QOS_ENTRIES,
1787 : : cfg->keep_entries);
1788 : :
1789 : : /* send command to mc*/
1790 : 0 : return mc_send_command(mc_io, &cmd);
1791 : : }
1792 : :
1793 : : /**
1794 : : * dpni_add_qos_entry() - Add QoS mapping entry (to select a traffic class)
1795 : : * @mc_io: Pointer to MC portal's I/O object
1796 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1797 : : * @token: Token of DPNI object
1798 : : * @cfg: QoS rule to add
1799 : : * @tc_id: Traffic class selection (0-7)
1800 : : * @index: Location in the QoS table where to insert the entry.
1801 : : * Only relevant if MASKING is enabled for QoS classification on
1802 : : * this DPNI, it is ignored for exact match.
1803 : : *
1804 : : * Return: '0' on Success; Error code otherwise.
1805 : : */
1806 : 0 : int dpni_add_qos_entry(struct fsl_mc_io *mc_io,
1807 : : uint32_t cmd_flags,
1808 : : uint16_t token,
1809 : : const struct dpni_rule_cfg *cfg,
1810 : : uint8_t tc_id,
1811 : : uint16_t index,
1812 : : uint8_t flags,
1813 : : uint8_t flow_id)
1814 : : {
1815 : : struct dpni_cmd_add_qos_entry *cmd_params;
1816 : 0 : struct mc_command cmd = { 0 };
1817 : :
1818 : : /* prepare command */
1819 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_QOS_ENT,
1820 : : cmd_flags,
1821 : : token);
1822 : : cmd_params = (struct dpni_cmd_add_qos_entry *)cmd.params;
1823 : 0 : cmd_params->flags = flags;
1824 : 0 : cmd_params->flow_id = flow_id;
1825 : 0 : cmd_params->tc_id = tc_id;
1826 : 0 : cmd_params->key_size = cfg->key_size;
1827 : 0 : cmd_params->index = cpu_to_le16(index);
1828 : 0 : cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1829 : 0 : cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1830 : :
1831 : : /* send command to mc*/
1832 : 0 : return mc_send_command(mc_io, &cmd);
1833 : : }
1834 : :
1835 : : /**
1836 : : * dpni_remove_qos_entry() - Remove QoS mapping entry
1837 : : * @mc_io: Pointer to MC portal's I/O object
1838 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1839 : : * @token: Token of DPNI object
1840 : : * @cfg: QoS rule to remove
1841 : : *
1842 : : * Return: '0' on Success; Error code otherwise.
1843 : : */
1844 : 0 : int dpni_remove_qos_entry(struct fsl_mc_io *mc_io,
1845 : : uint32_t cmd_flags,
1846 : : uint16_t token,
1847 : : const struct dpni_rule_cfg *cfg)
1848 : : {
1849 : : struct dpni_cmd_remove_qos_entry *cmd_params;
1850 : 0 : struct mc_command cmd = { 0 };
1851 : :
1852 : : /* prepare command */
1853 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_QOS_ENT,
1854 : : cmd_flags,
1855 : : token);
1856 : : cmd_params = (struct dpni_cmd_remove_qos_entry *)cmd.params;
1857 : 0 : cmd_params->key_size = cfg->key_size;
1858 : 0 : cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1859 : 0 : cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1860 : :
1861 : : /* send command to mc*/
1862 : 0 : return mc_send_command(mc_io, &cmd);
1863 : : }
1864 : :
1865 : : /**
1866 : : * dpni_clear_qos_table() - Clear all QoS mapping entries
1867 : : * @mc_io: Pointer to MC portal's I/O object
1868 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1869 : : * @token: Token of DPNI object
1870 : : *
1871 : : * Following this function call, all frames are directed to
1872 : : * the default traffic class (0)
1873 : : *
1874 : : * Return: '0' on Success; Error code otherwise.
1875 : : */
1876 : 0 : int dpni_clear_qos_table(struct fsl_mc_io *mc_io,
1877 : : uint32_t cmd_flags,
1878 : : uint16_t token)
1879 : : {
1880 : 0 : struct mc_command cmd = { 0 };
1881 : :
1882 : : /* prepare command */
1883 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_QOS_TBL,
1884 : : cmd_flags,
1885 : : token);
1886 : :
1887 : : /* send command to mc*/
1888 : 0 : return mc_send_command(mc_io, &cmd);
1889 : : }
1890 : :
1891 : : /**
1892 : : * dpni_add_fs_entry() - Add Flow Steering entry for a specific traffic class
1893 : : * (to select a flow ID)
1894 : : * @mc_io: Pointer to MC portal's I/O object
1895 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1896 : : * @token: Token of DPNI object
1897 : : * @tc_id: Traffic class selection (0-7)
1898 : : * @index: Location in the QoS table where to insert the entry.
1899 : : * Only relevant if MASKING is enabled for QoS classification
1900 : : * on this DPNI, it is ignored for exact match.
1901 : : * @cfg: Flow steering rule to add
1902 : : * @action: Action to be taken as result of a classification hit
1903 : : *
1904 : : * Return: '0' on Success; Error code otherwise.
1905 : : */
1906 : 0 : int dpni_add_fs_entry(struct fsl_mc_io *mc_io,
1907 : : uint32_t cmd_flags,
1908 : : uint16_t token,
1909 : : uint8_t tc_id,
1910 : : uint16_t index,
1911 : : const struct dpni_rule_cfg *cfg,
1912 : : const struct dpni_fs_action_cfg *action)
1913 : : {
1914 : : struct dpni_cmd_add_fs_entry *cmd_params;
1915 : 0 : struct mc_command cmd = { 0 };
1916 : :
1917 : : /* prepare command */
1918 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_FS_ENT,
1919 : : cmd_flags,
1920 : : token);
1921 : : cmd_params = (struct dpni_cmd_add_fs_entry *)cmd.params;
1922 : 0 : cmd_params->tc_id = tc_id;
1923 : 0 : cmd_params->key_size = cfg->key_size;
1924 : 0 : cmd_params->index = cpu_to_le16(index);
1925 : 0 : cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1926 : 0 : cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1927 : 0 : cmd_params->options = cpu_to_le16(action->options);
1928 : 0 : cmd_params->flow_id = cpu_to_le16(action->flow_id);
1929 : 0 : cmd_params->flc = cpu_to_le64(action->flc);
1930 : 0 : cmd_params->redir_token = cpu_to_le16(action->redirect_obj_token);
1931 : :
1932 : : /* send command to mc*/
1933 : 0 : return mc_send_command(mc_io, &cmd);
1934 : : }
1935 : :
1936 : : /**
1937 : : * dpni_remove_fs_entry() - Remove Flow Steering entry from a specific
1938 : : * traffic class
1939 : : * @mc_io: Pointer to MC portal's I/O object
1940 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1941 : : * @token: Token of DPNI object
1942 : : * @tc_id: Traffic class selection (0-7)
1943 : : * @cfg: Flow steering rule to remove
1944 : : *
1945 : : * Return: '0' on Success; Error code otherwise.
1946 : : */
1947 : 0 : int dpni_remove_fs_entry(struct fsl_mc_io *mc_io,
1948 : : uint32_t cmd_flags,
1949 : : uint16_t token,
1950 : : uint8_t tc_id,
1951 : : const struct dpni_rule_cfg *cfg)
1952 : : {
1953 : : struct dpni_cmd_remove_fs_entry *cmd_params;
1954 : 0 : struct mc_command cmd = { 0 };
1955 : :
1956 : : /* prepare command */
1957 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_FS_ENT,
1958 : : cmd_flags,
1959 : : token);
1960 : : cmd_params = (struct dpni_cmd_remove_fs_entry *)cmd.params;
1961 : 0 : cmd_params->tc_id = tc_id;
1962 : 0 : cmd_params->key_size = cfg->key_size;
1963 : 0 : cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
1964 : 0 : cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova);
1965 : :
1966 : : /* send command to mc*/
1967 : 0 : return mc_send_command(mc_io, &cmd);
1968 : : }
1969 : :
1970 : : /**
1971 : : * dpni_clear_fs_entries() - Clear all Flow Steering entries of a specific
1972 : : * traffic class
1973 : : * @mc_io: Pointer to MC portal's I/O object
1974 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1975 : : * @token: Token of DPNI object
1976 : : * @tc_id: Traffic class selection (0-7)
1977 : : *
1978 : : * Return: '0' on Success; Error code otherwise.
1979 : : */
1980 : 0 : int dpni_clear_fs_entries(struct fsl_mc_io *mc_io,
1981 : : uint32_t cmd_flags,
1982 : : uint16_t token,
1983 : : uint8_t tc_id)
1984 : : {
1985 : : struct dpni_cmd_clear_fs_entries *cmd_params;
1986 : 0 : struct mc_command cmd = { 0 };
1987 : :
1988 : : /* prepare command */
1989 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_FS_ENT,
1990 : : cmd_flags,
1991 : : token);
1992 : : cmd_params = (struct dpni_cmd_clear_fs_entries *)cmd.params;
1993 : 0 : cmd_params->tc_id = tc_id;
1994 : :
1995 : : /* send command to mc*/
1996 : 0 : return mc_send_command(mc_io, &cmd);
1997 : : }
1998 : :
1999 : : /**
2000 : : * dpni_set_rx_tc_policing() - Set Rx traffic class policing configuration
2001 : : * @mc_io: Pointer to MC portal's I/O object
2002 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2003 : : * @token: Token of DPNI object
2004 : : * @tc_id: Traffic class selection (0-7)
2005 : : * @cfg: Traffic class policing configuration
2006 : : *
2007 : : * Return: '0' on Success; error code otherwise.
2008 : : */
2009 : 0 : int dpni_set_rx_tc_policing(struct fsl_mc_io *mc_io,
2010 : : uint32_t cmd_flags,
2011 : : uint16_t token,
2012 : : uint8_t tc_id,
2013 : : const struct dpni_rx_tc_policing_cfg *cfg)
2014 : : {
2015 : : struct dpni_cmd_set_rx_tc_policing *cmd_params;
2016 : 0 : struct mc_command cmd = { 0 };
2017 : :
2018 : : /* prepare command */
2019 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_POLICING,
2020 : : cmd_flags,
2021 : : token);
2022 : : cmd_params = (struct dpni_cmd_set_rx_tc_policing *)cmd.params;
2023 : 0 : dpni_set_field(cmd_params->mode_color, COLOR, cfg->default_color);
2024 : 0 : dpni_set_field(cmd_params->mode_color, MODE, cfg->mode);
2025 : 0 : dpni_set_field(cmd_params->units, UNITS, cfg->units);
2026 : 0 : cmd_params->options = cpu_to_le32(cfg->options);
2027 : 0 : cmd_params->cir = cpu_to_le32(cfg->cir);
2028 : 0 : cmd_params->cbs = cpu_to_le32(cfg->cbs);
2029 : 0 : cmd_params->eir = cpu_to_le32(cfg->eir);
2030 : 0 : cmd_params->ebs = cpu_to_le32(cfg->ebs);
2031 : 0 : cmd_params->tc_id = tc_id;
2032 : :
2033 : : /* send command to mc*/
2034 : 0 : return mc_send_command(mc_io, &cmd);
2035 : : }
2036 : :
2037 : : /**
2038 : : * dpni_get_rx_tc_policing() - Get Rx traffic class policing configuration
2039 : : * @mc_io: Pointer to MC portal's I/O object
2040 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2041 : : * @token: Token of DPNI object
2042 : : * @tc_id: Traffic class selection (0-7)
2043 : : * @cfg: Traffic class policing configuration
2044 : : *
2045 : : * Return: '0' on Success; error code otherwise.
2046 : : */
2047 : 0 : int dpni_get_rx_tc_policing(struct fsl_mc_io *mc_io,
2048 : : uint32_t cmd_flags,
2049 : : uint16_t token,
2050 : : uint8_t tc_id,
2051 : : struct dpni_rx_tc_policing_cfg *cfg)
2052 : : {
2053 : : struct dpni_rsp_get_rx_tc_policing *rsp_params;
2054 : : struct dpni_cmd_get_rx_tc_policing *cmd_params;
2055 : 0 : struct mc_command cmd = { 0 };
2056 : : int err;
2057 : :
2058 : : /* prepare command */
2059 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_RX_TC_POLICING,
2060 : : cmd_flags,
2061 : : token);
2062 : : cmd_params = (struct dpni_cmd_get_rx_tc_policing *)cmd.params;
2063 : 0 : cmd_params->tc_id = tc_id;
2064 : :
2065 : :
2066 : : /* send command to mc*/
2067 : 0 : err = mc_send_command(mc_io, &cmd);
2068 [ # # ]: 0 : if (err)
2069 : : return err;
2070 : :
2071 : : rsp_params = (struct dpni_rsp_get_rx_tc_policing *)cmd.params;
2072 : 0 : cfg->options = le32_to_cpu(rsp_params->options);
2073 : 0 : cfg->cir = le32_to_cpu(rsp_params->cir);
2074 : 0 : cfg->cbs = le32_to_cpu(rsp_params->cbs);
2075 : 0 : cfg->eir = le32_to_cpu(rsp_params->eir);
2076 : 0 : cfg->ebs = le32_to_cpu(rsp_params->ebs);
2077 : 0 : cfg->units = dpni_get_field(rsp_params->units, UNITS);
2078 : 0 : cfg->mode = dpni_get_field(rsp_params->mode_color, MODE);
2079 : 0 : cfg->default_color = dpni_get_field(rsp_params->mode_color, COLOR);
2080 : :
2081 : 0 : return 0;
2082 : : }
2083 : :
2084 : : /**
2085 : : * dpni_prepare_early_drop() - prepare an early drop.
2086 : : * @cfg: Early-drop configuration
2087 : : * @early_drop_buf: Zeroed 256 bytes of memory before mapping it to DMA
2088 : : *
2089 : : * This function has to be called before dpni_set_rx_tc_early_drop or
2090 : : * dpni_set_tx_tc_early_drop
2091 : : *
2092 : : */
2093 : 0 : void dpni_prepare_early_drop(const struct dpni_early_drop_cfg *cfg,
2094 : : uint8_t *early_drop_buf)
2095 : : {
2096 : : struct dpni_early_drop *ext_params;
2097 : :
2098 : : ext_params = (struct dpni_early_drop *)early_drop_buf;
2099 : :
2100 : 0 : dpni_set_field(ext_params->flags, DROP_ENABLE, cfg->enable);
2101 : 0 : dpni_set_field(ext_params->flags, DROP_UNITS, cfg->units);
2102 : 0 : ext_params->green_drop_probability = cfg->green.drop_probability;
2103 : 0 : ext_params->green_max_threshold = cpu_to_le64(cfg->green.max_threshold);
2104 : 0 : ext_params->green_min_threshold = cpu_to_le64(cfg->green.min_threshold);
2105 : 0 : ext_params->yellow_drop_probability = cfg->yellow.drop_probability;
2106 : 0 : ext_params->yellow_max_threshold =
2107 : 0 : cpu_to_le64(cfg->yellow.max_threshold);
2108 : 0 : ext_params->yellow_min_threshold =
2109 : 0 : cpu_to_le64(cfg->yellow.min_threshold);
2110 : 0 : ext_params->red_drop_probability = cfg->red.drop_probability;
2111 : 0 : ext_params->red_max_threshold = cpu_to_le64(cfg->red.max_threshold);
2112 : 0 : ext_params->red_min_threshold = cpu_to_le64(cfg->red.min_threshold);
2113 : 0 : }
2114 : :
2115 : : /**
2116 : : * dpni_extract_early_drop() - extract the early drop configuration.
2117 : : * @cfg: Early-drop configuration
2118 : : * @early_drop_buf: Zeroed 256 bytes of memory before mapping it to DMA
2119 : : *
2120 : : * This function has to be called after dpni_get_rx_tc_early_drop or
2121 : : * dpni_get_tx_tc_early_drop
2122 : : *
2123 : : */
2124 : 0 : void dpni_extract_early_drop(struct dpni_early_drop_cfg *cfg,
2125 : : const uint8_t *early_drop_buf)
2126 : : {
2127 : : const struct dpni_early_drop *ext_params;
2128 : :
2129 : : ext_params = (const struct dpni_early_drop *)early_drop_buf;
2130 : :
2131 : 0 : cfg->enable = dpni_get_field(ext_params->flags, DROP_ENABLE);
2132 : 0 : cfg->units = dpni_get_field(ext_params->flags, DROP_UNITS);
2133 : 0 : cfg->green.drop_probability = ext_params->green_drop_probability;
2134 : 0 : cfg->green.max_threshold = le64_to_cpu(ext_params->green_max_threshold);
2135 : 0 : cfg->green.min_threshold = le64_to_cpu(ext_params->green_min_threshold);
2136 : 0 : cfg->yellow.drop_probability = ext_params->yellow_drop_probability;
2137 : 0 : cfg->yellow.max_threshold =
2138 : 0 : le64_to_cpu(ext_params->yellow_max_threshold);
2139 : 0 : cfg->yellow.min_threshold =
2140 : 0 : le64_to_cpu(ext_params->yellow_min_threshold);
2141 : 0 : cfg->red.drop_probability = ext_params->red_drop_probability;
2142 : 0 : cfg->red.max_threshold = le64_to_cpu(ext_params->red_max_threshold);
2143 : 0 : cfg->red.min_threshold = le64_to_cpu(ext_params->red_min_threshold);
2144 : 0 : }
2145 : :
2146 : : /**
2147 : : * dpni_set_early_drop() - Set traffic class early-drop configuration
2148 : : * @mc_io: Pointer to MC portal's I/O object
2149 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2150 : : * @token: Token of DPNI object
2151 : : * @qtype: Type of queue - only Rx and Tx types are supported
2152 : : * @param: Traffic class and channel ID.
2153 : : * MSB - channel id; used only for DPNI_QUEUE_TX and DPNI_QUEUE_TX_CONFIRM,
2154 : : * ignored for the rest
2155 : : * LSB - traffic class
2156 : : * Use macro DPNI_BUILD_PARAM() to build correct value.
2157 : : * If dpni uses a single channel (uses only channel zero) the parameter can receive
2158 : : * traffic class directly.
2159 : : * @early_drop_iova: I/O virtual address of 256 bytes DMA-able memory filled
2160 : : * with the early-drop configuration by calling dpni_prepare_early_drop()
2161 : : *
2162 : : * warning: Before calling this function, call dpni_prepare_early_drop() to
2163 : : * prepare the early_drop_iova parameter
2164 : : *
2165 : : * Return: '0' on Success; error code otherwise.
2166 : : */
2167 : 0 : int dpni_set_early_drop(struct fsl_mc_io *mc_io,
2168 : : uint32_t cmd_flags,
2169 : : uint16_t token,
2170 : : enum dpni_queue_type qtype,
2171 : : uint16_t param,
2172 : : uint64_t early_drop_iova)
2173 : : {
2174 : : struct dpni_cmd_early_drop *cmd_params;
2175 : 0 : struct mc_command cmd = { 0 };
2176 : :
2177 : : /* prepare command */
2178 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_EARLY_DROP,
2179 : : cmd_flags,
2180 : : token);
2181 : : cmd_params = (struct dpni_cmd_early_drop *)cmd.params;
2182 : 0 : cmd_params->qtype = qtype;
2183 : 0 : cmd_params->tc = (uint8_t)(param & 0xff);
2184 : 0 : cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2185 : 0 : cmd_params->early_drop_iova = cpu_to_le64(early_drop_iova);
2186 : :
2187 : : /* send command to mc*/
2188 : 0 : return mc_send_command(mc_io, &cmd);
2189 : : }
2190 : :
2191 : : /**
2192 : : * dpni_get_early_drop() - Get Rx traffic class early-drop configuration
2193 : : * @mc_io: Pointer to MC portal's I/O object
2194 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2195 : : * @token: Token of DPNI object
2196 : : * @qtype: Type of queue - only Rx and Tx types are supported
2197 : : * @param: Traffic class and channel ID.
2198 : : * MSB - channel id; used only for DPNI_QUEUE_TX and DPNI_QUEUE_TX_CONFIRM,
2199 : : * ignored for the rest
2200 : : * LSB - traffic class
2201 : : * Use macro DPNI_BUILD_PARAM() to build correct value.
2202 : : * If dpni uses a single channel (uses only channel zero) the parameter can receive
2203 : : * traffic class directly.
2204 : : * @early_drop_iova: I/O virtual address of 256 bytes DMA-able memory
2205 : : *
2206 : : * warning: After calling this function, call dpni_extract_early_drop() to
2207 : : * get the early drop configuration
2208 : : *
2209 : : * Return: '0' on Success; error code otherwise.
2210 : : */
2211 : 0 : int dpni_get_early_drop(struct fsl_mc_io *mc_io,
2212 : : uint32_t cmd_flags,
2213 : : uint16_t token,
2214 : : enum dpni_queue_type qtype,
2215 : : uint16_t param,
2216 : : uint64_t early_drop_iova)
2217 : : {
2218 : : struct dpni_cmd_early_drop *cmd_params;
2219 : 0 : struct mc_command cmd = { 0 };
2220 : :
2221 : : /* prepare command */
2222 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_EARLY_DROP,
2223 : : cmd_flags,
2224 : : token);
2225 : : cmd_params = (struct dpni_cmd_early_drop *)cmd.params;
2226 : 0 : cmd_params->qtype = qtype;
2227 : 0 : cmd_params->tc = (uint8_t)(param & 0xff);
2228 : 0 : cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2229 : 0 : cmd_params->early_drop_iova = cpu_to_le64(early_drop_iova);
2230 : :
2231 : : /* send command to mc*/
2232 : 0 : return mc_send_command(mc_io, &cmd);
2233 : : }
2234 : :
2235 : : /**
2236 : : * dpni_set_congestion_notification() - Set traffic class congestion
2237 : : * notification configuration
2238 : : * @mc_io: Pointer to MC portal's I/O object
2239 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2240 : : * @token: Token of DPNI object
2241 : : * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
2242 : : * @param: Traffic class and channel. Bits[0-7] contain traaffic class,
2243 : : * bite[8-15] contains channel id
2244 : : * @cfg: congestion notification configuration
2245 : : *
2246 : : * Return: '0' on Success; error code otherwise.
2247 : : */
2248 : 0 : int dpni_set_congestion_notification(struct fsl_mc_io *mc_io,
2249 : : uint32_t cmd_flags,
2250 : : uint16_t token,
2251 : : enum dpni_queue_type qtype,
2252 : : uint16_t param,
2253 : : const struct dpni_congestion_notification_cfg *cfg)
2254 : : {
2255 : : struct dpni_cmd_set_congestion_notification *cmd_params;
2256 : 0 : struct mc_command cmd = { 0 };
2257 : :
2258 : : /* prepare command */
2259 : 0 : cmd.header = mc_encode_cmd_header(
2260 : : DPNI_CMDID_SET_CONGESTION_NOTIFICATION,
2261 : : cmd_flags,
2262 : : token);
2263 : : cmd_params = (struct dpni_cmd_set_congestion_notification *)cmd.params;
2264 : 0 : cmd_params->qtype = qtype;
2265 : 0 : cmd_params->tc = (uint8_t)(param & 0xff);
2266 : 0 : cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2267 : 0 : cmd_params->congestion_point = cfg->cg_point;
2268 : 0 : cmd_params->cgid = (uint8_t)cfg->cgid;
2269 : 0 : cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
2270 : 0 : cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode);
2271 : 0 : cmd_params->dest_priority = cfg->dest_cfg.priority;
2272 : 0 : cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
2273 : 0 : cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
2274 : 0 : cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry);
2275 : 0 : cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit);
2276 : 0 : dpni_set_field(cmd_params->type_units,
2277 : : DEST_TYPE,
2278 : : cfg->dest_cfg.dest_type);
2279 : 0 : dpni_set_field(cmd_params->type_units,
2280 : : CONG_UNITS,
2281 : : cfg->units);
2282 : :
2283 : : /* send command to mc*/
2284 : 0 : return mc_send_command(mc_io, &cmd);
2285 : : }
2286 : :
2287 : : /**
2288 : : * dpni_get_congestion_notification() - Get traffic class congestion
2289 : : * notification configuration
2290 : : * @mc_io: Pointer to MC portal's I/O object
2291 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2292 : : * @token: Token of DPNI object
2293 : : * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
2294 : : * @param: Traffic class and channel. Bits[0-7] contain traaffic class,
2295 : : * byte[8-15] contains channel id
2296 : : * @cfg: congestion notification configuration
2297 : : *
2298 : : * Return: '0' on Success; error code otherwise.
2299 : : */
2300 : 0 : int dpni_get_congestion_notification(struct fsl_mc_io *mc_io,
2301 : : uint32_t cmd_flags,
2302 : : uint16_t token,
2303 : : enum dpni_queue_type qtype,
2304 : : uint16_t param,
2305 : : struct dpni_congestion_notification_cfg *cfg)
2306 : : {
2307 : : struct dpni_rsp_get_congestion_notification *rsp_params;
2308 : : struct dpni_cmd_get_congestion_notification *cmd_params;
2309 : 0 : struct mc_command cmd = { 0 };
2310 : : int err;
2311 : :
2312 : : /* prepare command */
2313 : 0 : cmd.header = mc_encode_cmd_header(
2314 : : DPNI_CMDID_GET_CONGESTION_NOTIFICATION,
2315 : : cmd_flags,
2316 : : token);
2317 : : cmd_params = (struct dpni_cmd_get_congestion_notification *)cmd.params;
2318 : 0 : cmd_params->qtype = qtype;
2319 : 0 : cmd_params->tc = (uint8_t)(param & 0xff);
2320 : 0 : cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2321 : 0 : cmd_params->congestion_point = cfg->cg_point;
2322 : 0 : cmd_params->cgid = cfg->cgid;
2323 : :
2324 : : /* send command to mc*/
2325 : 0 : err = mc_send_command(mc_io, &cmd);
2326 [ # # ]: 0 : if (err)
2327 : : return err;
2328 : :
2329 : : rsp_params = (struct dpni_rsp_get_congestion_notification *)cmd.params;
2330 : 0 : cfg->units = dpni_get_field(rsp_params->type_units, CONG_UNITS);
2331 : 0 : cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
2332 : 0 : cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
2333 : 0 : cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
2334 : 0 : cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
2335 : 0 : cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
2336 : 0 : cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
2337 : 0 : cfg->dest_cfg.priority = rsp_params->dest_priority;
2338 : 0 : cfg->dest_cfg.dest_type = dpni_get_field(rsp_params->type_units,
2339 : : DEST_TYPE);
2340 : :
2341 : 0 : return 0;
2342 : : }
2343 : :
2344 : : /**
2345 : : * dpni_get_api_version() - Get Data Path Network Interface API version
2346 : : * @mc_io: Pointer to MC portal's I/O object
2347 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2348 : : * @major_ver: Major version of data path network interface API
2349 : : * @minor_ver: Minor version of data path network interface API
2350 : : *
2351 : : * Return: '0' on Success; Error code otherwise.
2352 : : */
2353 : 0 : int dpni_get_api_version(struct fsl_mc_io *mc_io,
2354 : : uint32_t cmd_flags,
2355 : : uint16_t *major_ver,
2356 : : uint16_t *minor_ver)
2357 : : {
2358 : : struct dpni_rsp_get_api_version *rsp_params;
2359 : 0 : struct mc_command cmd = { 0 };
2360 : : int err;
2361 : :
2362 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION,
2363 : : cmd_flags,
2364 : : 0);
2365 : :
2366 : 0 : err = mc_send_command(mc_io, &cmd);
2367 [ # # ]: 0 : if (err)
2368 : : return err;
2369 : :
2370 : : rsp_params = (struct dpni_rsp_get_api_version *)cmd.params;
2371 : 0 : *major_ver = le16_to_cpu(rsp_params->major);
2372 : 0 : *minor_ver = le16_to_cpu(rsp_params->minor);
2373 : :
2374 : 0 : return 0;
2375 : : }
2376 : :
2377 : : /**
2378 : : * dpni_set_queue() - Set queue parameters
2379 : : * @mc_io: Pointer to MC portal's I/O object
2380 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2381 : : * @token: Token of DPNI object
2382 : : * @qtype: Type of queue - all queue types are supported, although
2383 : : * the command is ignored for Tx
2384 : : * @tc: Traffic class, in range 0 to NUM_TCS - 1
2385 : : * @index: Selects the specific queue out of the set allocated for the
2386 : : * same TC. Value must be in range 0 to NUM_QUEUES - 1
2387 : : * @options: A combination of DPNI_QUEUE_OPT_ values that control what
2388 : : * configuration options are set on the queue
2389 : : * @queue: Queue structure
2390 : : *
2391 : : * Return: '0' on Success; Error code otherwise.
2392 : : */
2393 : 0 : int dpni_set_queue(struct fsl_mc_io *mc_io,
2394 : : uint32_t cmd_flags,
2395 : : uint16_t token,
2396 : : enum dpni_queue_type qtype,
2397 : : uint16_t param,
2398 : : uint8_t index,
2399 : : uint8_t options,
2400 : : const struct dpni_queue *queue)
2401 : : {
2402 : 0 : struct mc_command cmd = { 0 };
2403 : : struct dpni_cmd_set_queue *cmd_params;
2404 : :
2405 : : /* prepare command */
2406 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE,
2407 : : cmd_flags,
2408 : : token);
2409 : : cmd_params = (struct dpni_cmd_set_queue *)cmd.params;
2410 : 0 : cmd_params->qtype = qtype;
2411 : 0 : cmd_params->tc = (uint8_t)(param & 0xff);
2412 : 0 : cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2413 : 0 : cmd_params->index = index;
2414 : 0 : cmd_params->options = options;
2415 : 0 : cmd_params->dest_id = cpu_to_le32(queue->destination.id);
2416 : 0 : cmd_params->dest_prio = queue->destination.priority;
2417 : 0 : dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type);
2418 : 0 : dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control);
2419 : 0 : dpni_set_field(cmd_params->flags, HOLD_ACTIVE,
2420 : : queue->destination.hold_active);
2421 : 0 : cmd_params->flc = cpu_to_le64(queue->flc.value);
2422 : 0 : cmd_params->user_context = cpu_to_le64(queue->user_context);
2423 : 0 : cmd_params->cgid = queue->cgid;
2424 : :
2425 : : /* send command to mc */
2426 : 0 : return mc_send_command(mc_io, &cmd);
2427 : : }
2428 : :
2429 : : /**
2430 : : * dpni_get_queue() - Get queue parameters
2431 : : * @mc_io: Pointer to MC portal's I/O object
2432 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2433 : : * @token: Token of DPNI object
2434 : : * @qtype: Type of queue - all queue types are supported
2435 : : * @param: Traffic class and channel ID.
2436 : : * MSB - channel id; used only for DPNI_QUEUE_TX and DPNI_QUEUE_TX_CONFIRM,
2437 : : * ignored for the rest
2438 : : * LSB - traffic class
2439 : : * Use macro DPNI_BUILD_PARAM() to build correct value.
2440 : : * If dpni uses a single channel (uses only channel zero) the parameter can receive
2441 : : * traffic class directly.
2442 : : * @index: Selects the specific queue out of the set allocated for the
2443 : : * same TC. Value must be in range 0 to NUM_QUEUES - 1
2444 : : * @queue: Queue configuration structure
2445 : : * @qid: Queue identification
2446 : : *
2447 : : * Return: '0' on Success; Error code otherwise.
2448 : : */
2449 : 0 : int dpni_get_queue(struct fsl_mc_io *mc_io,
2450 : : uint32_t cmd_flags,
2451 : : uint16_t token,
2452 : : enum dpni_queue_type qtype,
2453 : : uint16_t param,
2454 : : uint8_t index,
2455 : : struct dpni_queue *queue,
2456 : : struct dpni_queue_id *qid)
2457 : : {
2458 : 0 : struct mc_command cmd = { 0 };
2459 : : struct dpni_cmd_get_queue *cmd_params;
2460 : : struct dpni_rsp_get_queue *rsp_params;
2461 : : int err;
2462 : :
2463 : : /* prepare command */
2464 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE,
2465 : : cmd_flags,
2466 : : token);
2467 : : cmd_params = (struct dpni_cmd_get_queue *)cmd.params;
2468 : 0 : cmd_params->qtype = qtype;
2469 : 0 : cmd_params->tc = (uint8_t)(param & 0xff);
2470 : 0 : cmd_params->index = index;
2471 : 0 : cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2472 : :
2473 : : /* send command to mc */
2474 : 0 : err = mc_send_command(mc_io, &cmd);
2475 [ # # ]: 0 : if (err)
2476 : : return err;
2477 : :
2478 : : /* retrieve response parameters */
2479 : : rsp_params = (struct dpni_rsp_get_queue *)cmd.params;
2480 : 0 : queue->destination.id = le32_to_cpu(rsp_params->dest_id);
2481 : 0 : queue->destination.priority = rsp_params->dest_prio;
2482 : 0 : queue->destination.type = dpni_get_field(rsp_params->flags,
2483 : : DEST_TYPE);
2484 : 0 : queue->flc.stash_control = dpni_get_field(rsp_params->flags,
2485 : : STASH_CTRL);
2486 : 0 : queue->destination.hold_active = dpni_get_field(rsp_params->flags,
2487 : : HOLD_ACTIVE);
2488 : 0 : queue->flc.value = le64_to_cpu(rsp_params->flc);
2489 : 0 : queue->user_context = le64_to_cpu(rsp_params->user_context);
2490 : 0 : qid->fqid = le32_to_cpu(rsp_params->fqid);
2491 : 0 : qid->qdbin = le16_to_cpu(rsp_params->qdbin);
2492 [ # # ]: 0 : if (dpni_get_field(rsp_params->flags, CGID_VALID))
2493 : 0 : queue->cgid = rsp_params->cgid;
2494 : : else
2495 : 0 : queue->cgid = -1;
2496 : :
2497 : : return 0;
2498 : : }
2499 : :
2500 : : /**
2501 : : * dpni_get_statistics() - Get DPNI statistics
2502 : : * @mc_io: Pointer to MC portal's I/O object
2503 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2504 : : * @token: Token of DPNI object
2505 : : * @page: Selects the statistics page to retrieve, see
2506 : : * DPNI_GET_STATISTICS output. Pages are numbered 0 to 6.
2507 : : * @param: Custom parameter for some pages used to select
2508 : : * a certain statistic source, for example the TC.
2509 : : * - page_0: not used
2510 : : * - page_1: not used
2511 : : * - page_2: not used
2512 : : * - page_3: high_byte - channel_id, low_byte - traffic class
2513 : : * - page_4: high_byte - queue_index have meaning only if dpni is
2514 : : * created using option DPNI_OPT_CUSTOM_CG, low_byte - traffic class
2515 : : * - page_5: not used
2516 : : * - page_6: not used
2517 : : * @stat: Structure containing the statistics
2518 : : *
2519 : : * Return: '0' on Success; Error code otherwise.
2520 : : */
2521 : 0 : int dpni_get_statistics(struct fsl_mc_io *mc_io,
2522 : : uint32_t cmd_flags,
2523 : : uint16_t token,
2524 : : uint8_t page,
2525 : : uint16_t param,
2526 : : union dpni_statistics *stat)
2527 : : {
2528 : 0 : struct mc_command cmd = { 0 };
2529 : : struct dpni_cmd_get_statistics *cmd_params;
2530 : : struct dpni_rsp_get_statistics *rsp_params;
2531 : : int i, err;
2532 : :
2533 : : /* prepare command */
2534 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS,
2535 : : cmd_flags,
2536 : : token);
2537 : : cmd_params = (struct dpni_cmd_get_statistics *)cmd.params;
2538 : 0 : cmd_params->page_number = page;
2539 : 0 : cmd_params->param = param;
2540 : :
2541 : : /* send command to mc */
2542 : 0 : err = mc_send_command(mc_io, &cmd);
2543 [ # # ]: 0 : if (err)
2544 : : return err;
2545 : :
2546 : : /* retrieve response parameters */
2547 : : rsp_params = (struct dpni_rsp_get_statistics *)cmd.params;
2548 [ # # ]: 0 : for (i = 0; i < DPNI_STATISTICS_CNT; i++)
2549 : 0 : stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]);
2550 : :
2551 : : return 0;
2552 : : }
2553 : :
2554 : : /**
2555 : : * dpni_reset_statistics() - Clears DPNI statistics
2556 : : * @mc_io: Pointer to MC portal's I/O object
2557 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2558 : : * @token: Token of DPNI object
2559 : : *
2560 : : * Return: '0' on Success; Error code otherwise.
2561 : : */
2562 : 0 : int dpni_reset_statistics(struct fsl_mc_io *mc_io,
2563 : : uint32_t cmd_flags,
2564 : : uint16_t token)
2565 : : {
2566 : 0 : struct mc_command cmd = { 0 };
2567 : :
2568 : : /* prepare command */
2569 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS,
2570 : : cmd_flags,
2571 : : token);
2572 : :
2573 : : /* send command to mc*/
2574 : 0 : return mc_send_command(mc_io, &cmd);
2575 : : }
2576 : :
2577 : : /**
2578 : : * dpni_set_taildrop() - Set taildrop per congestion group
2579 : : *
2580 : : * Setting a per-TC taildrop (cg_point = DPNI_CP_GROUP) will reset any current
2581 : : * congestion notification or early drop (WRED) configuration previously applied
2582 : : * to the same TC.
2583 : : *
2584 : : * @mc_io: Pointer to MC portal's I/O object
2585 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2586 : : * @token: Token of DPNI object
2587 : : * @cg_point: Congestion group identifier DPNI_CP_QUEUE is only supported in
2588 : : * combination with DPNI_QUEUE_RX.
2589 : : * @q_type: Queue type, can be DPNI_QUEUE_RX or DPNI_QUEUE_TX.
2590 : : * @tc: Traffic class to apply this taildrop to
2591 : : * @index/cgid: Index of the queue if the DPNI supports multiple queues for
2592 : : * traffic distribution.
2593 : : * If CONGESTION_POINT is DPNI_CP_CONGESTION_GROUP then it
2594 : : * represent the cgid of the congestion point
2595 : : * @taildrop: Taildrop structure
2596 : : *
2597 : : * Return: '0' on Success; Error code otherwise.
2598 : : */
2599 : 0 : int dpni_set_taildrop(struct fsl_mc_io *mc_io,
2600 : : uint32_t cmd_flags,
2601 : : uint16_t token,
2602 : : enum dpni_congestion_point cg_point,
2603 : : enum dpni_queue_type qtype,
2604 : : uint16_t param,
2605 : : uint8_t index,
2606 : : struct dpni_taildrop *taildrop)
2607 : : {
2608 : 0 : struct mc_command cmd = { 0 };
2609 : : struct dpni_cmd_set_taildrop *cmd_params;
2610 : :
2611 : : /* prepare command */
2612 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP,
2613 : : cmd_flags,
2614 : : token);
2615 : : cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params;
2616 : 0 : cmd_params->congestion_point = cg_point;
2617 : 0 : cmd_params->qtype = qtype;
2618 : 0 : cmd_params->tc = (uint8_t)(param & 0xff);
2619 : 0 : cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff);
2620 : 0 : cmd_params->index = index;
2621 : 0 : cmd_params->units = taildrop->units;
2622 : 0 : cmd_params->threshold = cpu_to_le32(taildrop->threshold);
2623 : 0 : dpni_set_field(cmd_params->enable_oal_lo, ENABLE, taildrop->enable);
2624 : 0 : dpni_set_field(cmd_params->enable_oal_lo, OAL_LO, taildrop->oal);
2625 : 0 : dpni_set_field(cmd_params->oal_hi,
2626 : : OAL_HI,
2627 : : taildrop->oal >> DPNI_OAL_LO_SIZE);
2628 : :
2629 : : /* send command to mc */
2630 : 0 : return mc_send_command(mc_io, &cmd);
2631 : : }
2632 : :
2633 : : /**
2634 : : * dpni_get_taildrop() - Get taildrop information
2635 : : * @mc_io: Pointer to MC portal's I/O object
2636 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2637 : : * @token: Token of DPNI object
2638 : : * @cg_point: Congestion point
2639 : : * @q_type: Queue type on which the taildrop is configured.
2640 : : * Only Rx queues are supported for now
2641 : : * @tc: Traffic class to apply this taildrop to
2642 : : * @q_index: Index of the queue if the DPNI supports multiple queues for
2643 : : * traffic distribution. Ignored if CONGESTION_POINT is not 0.
2644 : : * @taildrop: Taildrop structure
2645 : : *
2646 : : * Return: '0' on Success; Error code otherwise.
2647 : : */
2648 : 0 : int dpni_get_taildrop(struct fsl_mc_io *mc_io,
2649 : : uint32_t cmd_flags,
2650 : : uint16_t token,
2651 : : enum dpni_congestion_point cg_point,
2652 : : enum dpni_queue_type qtype,
2653 : : uint8_t tc,
2654 : : uint8_t index,
2655 : : struct dpni_taildrop *taildrop)
2656 : : {
2657 : 0 : struct mc_command cmd = { 0 };
2658 : : struct dpni_cmd_get_taildrop *cmd_params;
2659 : : struct dpni_rsp_get_taildrop *rsp_params;
2660 : : uint8_t oal_lo, oal_hi;
2661 : : int err;
2662 : :
2663 : : /* prepare command */
2664 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP,
2665 : : cmd_flags,
2666 : : token);
2667 : : cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params;
2668 : 0 : cmd_params->congestion_point = cg_point;
2669 : 0 : cmd_params->qtype = qtype;
2670 : 0 : cmd_params->tc = tc;
2671 : 0 : cmd_params->index = index;
2672 : :
2673 : : /* send command to mc */
2674 : 0 : err = mc_send_command(mc_io, &cmd);
2675 [ # # ]: 0 : if (err)
2676 : : return err;
2677 : :
2678 : : /* retrieve response parameters */
2679 : : rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params;
2680 : 0 : taildrop->enable = dpni_get_field(rsp_params->enable_oal_lo, ENABLE);
2681 : 0 : taildrop->units = rsp_params->units;
2682 : 0 : taildrop->threshold = le32_to_cpu(rsp_params->threshold);
2683 : 0 : oal_lo = dpni_get_field(rsp_params->enable_oal_lo, OAL_LO);
2684 : 0 : oal_hi = dpni_get_field(rsp_params->oal_hi, OAL_HI);
2685 : 0 : taildrop->oal = oal_hi << DPNI_OAL_LO_SIZE | oal_lo;
2686 : :
2687 : : /* Fill the first 4 bits, 'oal' is a 2's complement value of 12 bits */
2688 [ # # ]: 0 : if (taildrop->oal >= 0x0800)
2689 : 0 : taildrop->oal |= 0xF000;
2690 : :
2691 : : return 0;
2692 : : }
2693 : :
2694 : : /**
2695 : : * dpni_set_opr() - Set Order Restoration configuration.
2696 : : * @mc_io: Pointer to MC portal's I/O object
2697 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2698 : : * @token: Token of DPNI object
2699 : : * @tc: Traffic class, in range 0 to NUM_TCS - 1
2700 : : * @index: Selects the specific queue out of the set allocated
2701 : : * for the same TC. Value must be in range 0 to
2702 : : * NUM_QUEUES - 1
2703 : : * @options: Configuration mode options
2704 : : * can be OPR_OPT_CREATE or OPR_OPT_RETIRE
2705 : : * @cfg: Configuration options for the OPR
2706 : : *
2707 : : * Return: '0' on Success; Error code otherwise.
2708 : : */
2709 : 0 : int dpni_set_opr(struct fsl_mc_io *mc_io,
2710 : : uint32_t cmd_flags,
2711 : : uint16_t token,
2712 : : uint8_t tc,
2713 : : uint8_t index,
2714 : : uint8_t options,
2715 : : struct opr_cfg *cfg,
2716 : : uint8_t opr_id)
2717 : : {
2718 : : struct dpni_cmd_set_opr *cmd_params;
2719 : 0 : struct mc_command cmd = { 0 };
2720 : :
2721 : : /* prepare command */
2722 : 0 : cmd.header = mc_encode_cmd_header(
2723 : : DPNI_CMDID_SET_OPR,
2724 : : cmd_flags,
2725 : : token);
2726 : : cmd_params = (struct dpni_cmd_set_opr *)cmd.params;
2727 : 0 : cmd_params->tc_id = tc;
2728 : 0 : cmd_params->index = index;
2729 : 0 : cmd_params->options = options;
2730 : 0 : cmd_params->opr_id = opr_id;
2731 : 0 : cmd_params->oloe = cfg->oloe;
2732 : 0 : cmd_params->oeane = cfg->oeane;
2733 : 0 : cmd_params->olws = cfg->olws;
2734 : 0 : cmd_params->oa = cfg->oa;
2735 : 0 : cmd_params->oprrws = cfg->oprrws;
2736 : :
2737 : : /* send command to mc*/
2738 : 0 : return mc_send_command(mc_io, &cmd);
2739 : : }
2740 : :
2741 : : /**
2742 : : * dpni_get_opr() - Retrieve Order Restoration config and query.
2743 : : * @mc_io: Pointer to MC portal's I/O object
2744 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2745 : : * @token: Token of DPNI object
2746 : : * @tc: Traffic class, in range 0 to NUM_TCS - 1
2747 : : * @index: Selects the specific queue out of the set allocated
2748 : : * for the same TC. Value must be in range 0 to
2749 : : * NUM_QUEUES - 1
2750 : : * @cfg: Returned OPR configuration
2751 : : * @qry: Returned OPR query
2752 : : *
2753 : : * Return: '0' on Success; Error code otherwise.
2754 : : */
2755 : 0 : int dpni_get_opr(struct fsl_mc_io *mc_io,
2756 : : uint32_t cmd_flags,
2757 : : uint16_t token,
2758 : : uint8_t tc,
2759 : : uint8_t index,
2760 : : struct opr_cfg *cfg,
2761 : : struct opr_qry *qry,
2762 : : uint8_t flags,
2763 : : uint8_t opr_id)
2764 : : {
2765 : : struct dpni_rsp_get_opr *rsp_params;
2766 : : struct dpni_cmd_get_opr *cmd_params;
2767 : 0 : struct mc_command cmd = { 0 };
2768 : : int err;
2769 : :
2770 : : /* prepare command */
2771 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OPR,
2772 : : cmd_flags,
2773 : : token);
2774 : : cmd_params = (struct dpni_cmd_get_opr *)cmd.params;
2775 : 0 : cmd_params->index = index;
2776 : 0 : cmd_params->tc_id = tc;
2777 : 0 : cmd_params->flags = flags;
2778 : 0 : cmd_params->opr_id = opr_id;
2779 : :
2780 : : /* send command to mc*/
2781 : 0 : err = mc_send_command(mc_io, &cmd);
2782 [ # # ]: 0 : if (err)
2783 : : return err;
2784 : :
2785 : : /* retrieve response parameters */
2786 : : rsp_params = (struct dpni_rsp_get_opr *)cmd.params;
2787 : 0 : cfg->oloe = rsp_params->oloe;
2788 : 0 : cfg->oeane = rsp_params->oeane;
2789 : 0 : cfg->olws = rsp_params->olws;
2790 : 0 : cfg->oa = rsp_params->oa;
2791 : 0 : cfg->oprrws = rsp_params->oprrws;
2792 : 0 : qry->rip = dpni_get_field(rsp_params->flags, RIP);
2793 : 0 : qry->enable = dpni_get_field(rsp_params->flags, OPR_ENABLE);
2794 : 0 : qry->nesn = le16_to_cpu(rsp_params->nesn);
2795 : 0 : qry->ndsn = le16_to_cpu(rsp_params->ndsn);
2796 : 0 : qry->ea_tseq = le16_to_cpu(rsp_params->ea_tseq);
2797 : 0 : qry->tseq_nlis = dpni_get_field(rsp_params->tseq_nlis, TSEQ_NLIS);
2798 : 0 : qry->ea_hseq = le16_to_cpu(rsp_params->ea_hseq);
2799 : 0 : qry->hseq_nlis = dpni_get_field(rsp_params->hseq_nlis, HSEQ_NLIS);
2800 : 0 : qry->ea_hptr = le16_to_cpu(rsp_params->ea_hptr);
2801 : 0 : qry->ea_tptr = le16_to_cpu(rsp_params->ea_tptr);
2802 : 0 : qry->opr_vid = le16_to_cpu(rsp_params->opr_vid);
2803 : 0 : qry->opr_id = le16_to_cpu(rsp_params->opr_id);
2804 : :
2805 : 0 : return 0;
2806 : : }
2807 : :
2808 : 0 : int dpni_load_sw_sequence(struct fsl_mc_io *mc_io,
2809 : : uint32_t cmd_flags,
2810 : : uint16_t token,
2811 : : struct dpni_load_ss_cfg *cfg)
2812 : : {
2813 : : struct dpni_load_sw_sequence *cmd_params;
2814 : 0 : struct mc_command cmd = { 0 };
2815 : :
2816 : : /* prepare command */
2817 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_LOAD_SW_SEQUENCE,
2818 : : cmd_flags,
2819 : : token);
2820 : : cmd_params = (struct dpni_load_sw_sequence *)cmd.params;
2821 : 0 : cmd_params->dest = cfg->dest;
2822 : 0 : cmd_params->ss_offset = cpu_to_le16(cfg->ss_offset);
2823 : 0 : cmd_params->ss_size = cpu_to_le16(cfg->ss_size);
2824 : 0 : cmd_params->ss_iova = cpu_to_le64(cfg->ss_iova);
2825 : :
2826 : : /* send command to mc*/
2827 : 0 : return mc_send_command(mc_io, &cmd);
2828 : : }
2829 : :
2830 : 0 : int dpni_enable_sw_sequence(struct fsl_mc_io *mc_io,
2831 : : uint32_t cmd_flags,
2832 : : uint16_t token,
2833 : : struct dpni_enable_ss_cfg *cfg)
2834 : : {
2835 : : struct dpni_enable_sw_sequence *cmd_params;
2836 : 0 : struct mc_command cmd = { 0 };
2837 : :
2838 : : /* prepare command */
2839 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_SW_SEQUENCE,
2840 : : cmd_flags,
2841 : : token);
2842 : : cmd_params = (struct dpni_enable_sw_sequence *)cmd.params;
2843 : 0 : cmd_params->dest = cfg->dest;
2844 : 0 : cmd_params->set_start = cfg->set_start;
2845 : 0 : cmd_params->hxs = cpu_to_le16(cfg->hxs);
2846 : 0 : cmd_params->ss_offset = cpu_to_le16(cfg->ss_offset);
2847 : 0 : cmd_params->param_offset = cfg->param_offset;
2848 : 0 : cmd_params->param_size = cfg->param_size;
2849 : 0 : cmd_params->param_iova = cpu_to_le64(cfg->param_iova);
2850 : :
2851 : : /* send command to mc*/
2852 : 0 : return mc_send_command(mc_io, &cmd);
2853 : : }
2854 : :
2855 : : /**
2856 : : * dpni_get_sw_sequence_layout() - Get the soft sequence layout
2857 : : * @mc_io: Pointer to MC portal's I/O object
2858 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2859 : : * @token: Token of DPNI object
2860 : : * @src: Source of the layout (WRIOP Rx or Tx)
2861 : : * @ss_layout_iova: I/O virtual address of 264 bytes DMA-able memory
2862 : : *
2863 : : * warning: After calling this function, call dpni_extract_sw_sequence_layout()
2864 : : * to get the layout.
2865 : : *
2866 : : * Return: '0' on Success; error code otherwise.
2867 : : */
2868 : 0 : int dpni_get_sw_sequence_layout(struct fsl_mc_io *mc_io,
2869 : : uint32_t cmd_flags,
2870 : : uint16_t token,
2871 : : enum dpni_soft_sequence_dest src,
2872 : : uint64_t ss_layout_iova)
2873 : : {
2874 : : struct dpni_get_sw_sequence_layout *cmd_params;
2875 : 0 : struct mc_command cmd = { 0 };
2876 : :
2877 : : /* prepare command */
2878 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_SW_SEQUENCE_LAYOUT,
2879 : : cmd_flags,
2880 : : token);
2881 : :
2882 : : cmd_params = (struct dpni_get_sw_sequence_layout *)cmd.params;
2883 : 0 : cmd_params->src = src;
2884 : 0 : cmd_params->layout_iova = cpu_to_le64(ss_layout_iova);
2885 : :
2886 : : /* send command to mc*/
2887 : 0 : return mc_send_command(mc_io, &cmd);
2888 : : }
2889 : :
2890 : : /**
2891 : : * dpni_extract_sw_sequence_layout() - extract the software sequence layout
2892 : : * @layout: software sequence layout
2893 : : * @sw_sequence_layout_buf: Zeroed 264 bytes of memory before mapping it
2894 : : * to DMA
2895 : : *
2896 : : * This function has to be called after dpni_get_sw_sequence_layout
2897 : : *
2898 : : */
2899 : 0 : void dpni_extract_sw_sequence_layout(struct dpni_sw_sequence_layout *layout,
2900 : : const uint8_t *sw_sequence_layout_buf)
2901 : : {
2902 : : const struct dpni_sw_sequence_layout_entry *ext_params;
2903 : : int i;
2904 : : uint16_t ss_size, ss_offset;
2905 : :
2906 : : ext_params = (const struct dpni_sw_sequence_layout_entry *)
2907 : : sw_sequence_layout_buf;
2908 : :
2909 [ # # ]: 0 : for (i = 0; i < DPNI_SW_SEQUENCE_LAYOUT_SIZE; i++) {
2910 : 0 : ss_offset = le16_to_cpu(ext_params[i].ss_offset);
2911 : 0 : ss_size = le16_to_cpu(ext_params[i].ss_size);
2912 : :
2913 [ # # ]: 0 : if (ss_offset == 0 && ss_size == 0) {
2914 : 0 : layout->num_ss = i;
2915 : 0 : return;
2916 : : }
2917 : :
2918 : 0 : layout->ss[i].ss_offset = ss_offset;
2919 : 0 : layout->ss[i].ss_size = ss_size;
2920 : 0 : layout->ss[i].param_offset = ext_params[i].param_offset;
2921 : 0 : layout->ss[i].param_size = ext_params[i].param_size;
2922 : : }
2923 : : }
2924 : : /**
2925 : : * dpni_set_rx_fs_dist() - Set Rx traffic class FS distribution
2926 : : * @mc_io: Pointer to MC portal's I/O object
2927 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2928 : : * @token: Token of DPNI object
2929 : : * @cfg: Distribution configuration
2930 : : * If the FS is already enabled with a previous call the classification
2931 : : * key will be changed but all the table rules are kept. If the
2932 : : * existing rules do not match the key the results will not be
2933 : : * predictable. It is the user responsibility to keep keyintegrity.
2934 : : * If cfg.enable is set to 1 the command will create a flow steering table
2935 : : * and will classify packets according to this table. The packets
2936 : : * that miss all the table rules will be classified according to
2937 : : * settings made in dpni_set_rx_hash_dist()
2938 : : * If cfg.enable is set to 0 the command will clear flow steering table. The
2939 : : * packets will be classified according to settings made in
2940 : : * dpni_set_rx_hash_dist()
2941 : : */
2942 : 0 : int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2943 : : uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2944 : : {
2945 : : struct dpni_cmd_set_rx_fs_dist *cmd_params;
2946 : 0 : struct mc_command cmd = { 0 };
2947 : :
2948 : : /* prepare command */
2949 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FS_DIST,
2950 : : cmd_flags,
2951 : : token);
2952 : : cmd_params = (struct dpni_cmd_set_rx_fs_dist *)cmd.params;
2953 : 0 : cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
2954 : 0 : dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2955 : 0 : cmd_params->tc = cfg->tc;
2956 : 0 : cmd_params->miss_flow_id = cpu_to_le16(cfg->fs_miss_flow_id);
2957 : 0 : cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2958 : :
2959 : : /* send command to mc*/
2960 : 0 : return mc_send_command(mc_io, &cmd);
2961 : : }
2962 : :
2963 : : /**
2964 : : * dpni_set_rx_hash_dist() - Set Rx traffic class HASH distribution
2965 : : * @mc_io: Pointer to MC portal's I/O object
2966 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2967 : : * @token: Token of DPNI object
2968 : : * @cfg: Distribution configuration
2969 : : * If cfg.enable is set to 1 the packets will be classified using a hash
2970 : : * function based on the key received in cfg.key_cfg_iova parameter.
2971 : : * If cfg.enable is set to 0 the packets will be sent to the queue configured in
2972 : : * dpni_set_rx_dist_default_queue() call
2973 : : */
2974 : 0 : int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
2975 : : uint16_t token, const struct dpni_rx_dist_cfg *cfg)
2976 : : {
2977 : : struct dpni_cmd_set_rx_hash_dist *cmd_params;
2978 : 0 : struct mc_command cmd = { 0 };
2979 : :
2980 : : /* prepare command */
2981 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_HASH_DIST,
2982 : : cmd_flags,
2983 : : token);
2984 : : cmd_params = (struct dpni_cmd_set_rx_hash_dist *)cmd.params;
2985 : 0 : cmd_params->dist_size = cpu_to_le16(cfg->dist_size);
2986 : 0 : dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable);
2987 : 0 : cmd_params->tc_id = cfg->tc;
2988 : 0 : cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova);
2989 : :
2990 : : /* send command to mc*/
2991 : 0 : return mc_send_command(mc_io, &cmd);
2992 : : }
2993 : :
2994 : : /**
2995 : : * dpni_add_custom_tpid() - Configures a distinct Ethertype value (or TPID
2996 : : * value) to indicate VLAN tag in adition to the common TPID values
2997 : : * 0x81000 and 0x88A8
2998 : : * @mc_io: Pointer to MC portal's I/O object
2999 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
3000 : : * @token: Token of DPNI object
3001 : : * @tpid: New value for TPID
3002 : : *
3003 : : * Only two custom values are accepted. If the function is called for the third
3004 : : * time it will return error.
3005 : : * To replace an existing value use dpni_remove_custom_tpid() to remove a
3006 : : * previous TPID and after that use again the function.
3007 : : *
3008 : : * Return: '0' on Success; Error code otherwise.
3009 : : */
3010 : 0 : int dpni_add_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
3011 : : uint16_t token, uint16_t tpid)
3012 : : {
3013 : : struct dpni_cmd_add_custom_tpid *cmd_params;
3014 : 0 : struct mc_command cmd = { 0 };
3015 : :
3016 : : /* prepare command */
3017 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_CUSTOM_TPID,
3018 : : cmd_flags,
3019 : : token);
3020 : : cmd_params = (struct dpni_cmd_add_custom_tpid *)cmd.params;
3021 : 0 : cmd_params->tpid = cpu_to_le16(tpid);
3022 : :
3023 : : /* send command to mc*/
3024 : 0 : return mc_send_command(mc_io, &cmd);
3025 : : }
3026 : :
3027 : : /**
3028 : : * dpni_remove_custom_tpid() - Removes a distinct Ethertype value added
3029 : : * previously with dpni_add_custom_tpid()
3030 : : * @mc_io: Pointer to MC portal's I/O object
3031 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
3032 : : * @token: Token of DPNI object
3033 : : * @tpid: New value for TPID
3034 : : *
3035 : : * Use this function when a TPID value added with dpni_add_custom_tpid() needs
3036 : : * to be replaced.
3037 : : *
3038 : : * Return: '0' on Success; Error code otherwise.
3039 : : */
3040 : 0 : int dpni_remove_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
3041 : : uint16_t token, uint16_t tpid)
3042 : : {
3043 : : struct dpni_cmd_remove_custom_tpid *cmd_params;
3044 : 0 : struct mc_command cmd = { 0 };
3045 : :
3046 : : /* prepare command */
3047 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_CUSTOM_TPID,
3048 : : cmd_flags,
3049 : : token);
3050 : : cmd_params = (struct dpni_cmd_remove_custom_tpid *)cmd.params;
3051 : 0 : cmd_params->tpid = cpu_to_le16(tpid);
3052 : :
3053 : : /* send command to mc*/
3054 : 0 : return mc_send_command(mc_io, &cmd);
3055 : : }
3056 : :
3057 : : /**
3058 : : * dpni_get_custom_tpid() - Returns custom TPID (vlan tags) values configured to
3059 : : * detect 802.1q frames
3060 : : * @mc_io: Pointer to MC portal's I/O object
3061 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
3062 : : * @token: Token of DPNI object
3063 : : * @tpid: TPID values. Only nonzero members of the structure are valid.
3064 : : *
3065 : : * Return: '0' on Success; Error code otherwise.
3066 : : */
3067 : 0 : int dpni_get_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
3068 : : uint16_t token, struct dpni_custom_tpid_cfg *tpid)
3069 : : {
3070 : : struct dpni_rsp_get_custom_tpid *rsp_params;
3071 : 0 : struct mc_command cmd = { 0 };
3072 : : int err;
3073 : :
3074 : : /* prepare command */
3075 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_CUSTOM_TPID,
3076 : : cmd_flags,
3077 : : token);
3078 : :
3079 : : /* send command to mc*/
3080 : 0 : err = mc_send_command(mc_io, &cmd);
3081 [ # # ]: 0 : if (err)
3082 : : return err;
3083 : :
3084 : : /* read command response */
3085 : : rsp_params = (struct dpni_rsp_get_custom_tpid *)cmd.params;
3086 : 0 : tpid->tpid1 = le16_to_cpu(rsp_params->tpid1);
3087 : 0 : tpid->tpid2 = le16_to_cpu(rsp_params->tpid2);
3088 : :
3089 : 0 : return err;
3090 : : }
3091 : :
3092 : : /**
3093 : : * dpni_set_port_cfg() - performs configurations at physical port connected on
3094 : : * this dpni. The command have effect only if dpni is connected to
3095 : : * another dpni object
3096 : : * @mc_io: Pointer to MC portal's I/O object
3097 : : * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
3098 : : * @token: Token of DPNI object
3099 : : * @flags: Valid fields from port_cfg structure
3100 : : * @port_cfg: Configuration data; one or more of DPNI_PORT_CFG_
3101 : : * The command can be called only when dpni is connected to a dpmac object. If
3102 : : * the dpni is unconnected or the endpoint is not a dpni it will return error.
3103 : : * If dpmac endpoint is disconnected the settings will be lost
3104 : : */
3105 : 0 : int dpni_set_port_cfg(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
3106 : : uint16_t token, uint32_t flags, struct dpni_port_cfg *port_cfg)
3107 : : {
3108 : : struct dpni_cmd_set_port_cfg *cmd_params;
3109 : 0 : struct mc_command cmd = { 0 };
3110 : :
3111 : : /* prepare command */
3112 : 0 : cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PORT_CFG,
3113 : : cmd_flags, token);
3114 : :
3115 : : cmd_params = (struct dpni_cmd_set_port_cfg *)cmd.params;
3116 : 0 : cmd_params->flags = cpu_to_le32(flags);
3117 : 0 : dpni_set_field(cmd_params->bit_params, PORT_LOOPBACK_EN,
3118 : : !!port_cfg->loopback_en);
3119 : :
3120 : : /* send command to MC */
3121 : 0 : return mc_send_command(mc_io, &cmd);
3122 : : }
|