1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2 /* Copyright 2013-2016 Freescale Semiconductor Inc.
6 #include <linux/kernel.h>
7 #include <linux/errno.h>
8 #include <linux/fsl/mc.h>
13 * dpni_prepare_key_cfg() - function prepare extract parameters
14 * @cfg: defining a full Key Generation profile (rule)
15 * @key_cfg_buf: Zeroed 256 bytes of memory before mapping it to DMA
17 * This function has to be called before the following functions:
18 * - dpni_set_rx_tc_dist()
19 * - dpni_set_qos_table()
21 int dpni_prepare_key_cfg(const struct dpkg_profile_cfg
*cfg
, u8
*key_cfg_buf
)
24 struct dpni_ext_set_rx_tc_dist
*dpni_ext
;
25 struct dpni_dist_extract
*extr
;
27 if (cfg
->num_extracts
> DPKG_MAX_NUM_OF_EXTRACTS
)
30 dpni_ext
= (struct dpni_ext_set_rx_tc_dist
*)key_cfg_buf
;
31 dpni_ext
->num_extracts
= cfg
->num_extracts
;
33 for (i
= 0; i
< cfg
->num_extracts
; i
++) {
34 extr
= &dpni_ext
->extracts
[i
];
36 switch (cfg
->extracts
[i
].type
) {
37 case DPKG_EXTRACT_FROM_HDR
:
38 extr
->prot
= cfg
->extracts
[i
].extract
.from_hdr
.prot
;
39 dpni_set_field(extr
->efh_type
, EFH_TYPE
,
40 cfg
->extracts
[i
].extract
.from_hdr
.type
);
41 extr
->size
= cfg
->extracts
[i
].extract
.from_hdr
.size
;
42 extr
->offset
= cfg
->extracts
[i
].extract
.from_hdr
.offset
;
43 extr
->field
= cpu_to_le32(
44 cfg
->extracts
[i
].extract
.from_hdr
.field
);
46 cfg
->extracts
[i
].extract
.from_hdr
.hdr_index
;
48 case DPKG_EXTRACT_FROM_DATA
:
49 extr
->size
= cfg
->extracts
[i
].extract
.from_data
.size
;
51 cfg
->extracts
[i
].extract
.from_data
.offset
;
53 case DPKG_EXTRACT_FROM_PARSE
:
54 extr
->size
= cfg
->extracts
[i
].extract
.from_parse
.size
;
56 cfg
->extracts
[i
].extract
.from_parse
.offset
;
62 extr
->num_of_byte_masks
= cfg
->extracts
[i
].num_of_byte_masks
;
63 dpni_set_field(extr
->extract_type
, EXTRACT_TYPE
,
64 cfg
->extracts
[i
].type
);
66 for (j
= 0; j
< DPKG_NUM_OF_MASKS
; j
++) {
67 extr
->masks
[j
].mask
= cfg
->extracts
[i
].masks
[j
].mask
;
68 extr
->masks
[j
].offset
=
69 cfg
->extracts
[i
].masks
[j
].offset
;
77 * dpni_open() - Open a control session for the specified object
78 * @mc_io: Pointer to MC portal's I/O object
79 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
80 * @dpni_id: DPNI unique ID
81 * @token: Returned token; use in subsequent API calls
83 * This function can be used to open a control session for an
84 * already created object; an object may have been declared in
85 * the DPL or by calling the dpni_create() function.
86 * This function returns a unique authentication token,
87 * associated with the specific object ID and the specific MC
88 * portal; this token must be used in all subsequent commands for
89 * this specific object.
91 * Return: '0' on Success; Error code otherwise.
93 int dpni_open(struct fsl_mc_io
*mc_io
,
98 struct fsl_mc_command cmd
= { 0 };
99 struct dpni_cmd_open
*cmd_params
;
103 /* prepare command */
104 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_OPEN
,
107 cmd_params
= (struct dpni_cmd_open
*)cmd
.params
;
108 cmd_params
->dpni_id
= cpu_to_le32(dpni_id
);
110 /* send command to mc*/
111 err
= mc_send_command(mc_io
, &cmd
);
115 /* retrieve response parameters */
116 *token
= mc_cmd_hdr_read_token(&cmd
);
122 * dpni_close() - Close the control session of the object
123 * @mc_io: Pointer to MC portal's I/O object
124 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
125 * @token: Token of DPNI object
127 * After this function is called, no further operations are
128 * allowed on the object without opening a new control session.
130 * Return: '0' on Success; Error code otherwise.
132 int dpni_close(struct fsl_mc_io
*mc_io
,
136 struct fsl_mc_command cmd
= { 0 };
138 /* prepare command */
139 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_CLOSE
,
143 /* send command to mc*/
144 return mc_send_command(mc_io
, &cmd
);
148 * dpni_set_pools() - Set buffer pools configuration
149 * @mc_io: Pointer to MC portal's I/O object
150 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
151 * @token: Token of DPNI object
152 * @cfg: Buffer pools configuration
154 * mandatory for DPNI operation
155 * warning:Allowed only when DPNI is disabled
157 * Return: '0' on Success; Error code otherwise.
159 int dpni_set_pools(struct fsl_mc_io
*mc_io
,
162 const struct dpni_pools_cfg
*cfg
)
164 struct fsl_mc_command cmd
= { 0 };
165 struct dpni_cmd_set_pools
*cmd_params
;
168 /* prepare command */
169 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_POOLS
,
172 cmd_params
= (struct dpni_cmd_set_pools
*)cmd
.params
;
173 cmd_params
->num_dpbp
= cfg
->num_dpbp
;
174 for (i
= 0; i
< DPNI_MAX_DPBP
; i
++) {
175 cmd_params
->dpbp_id
[i
] = cpu_to_le32(cfg
->pools
[i
].dpbp_id
);
176 cmd_params
->buffer_size
[i
] =
177 cpu_to_le16(cfg
->pools
[i
].buffer_size
);
178 cmd_params
->backup_pool_mask
|=
179 DPNI_BACKUP_POOL(cfg
->pools
[i
].backup_pool
, i
);
182 /* send command to mc*/
183 return mc_send_command(mc_io
, &cmd
);
187 * dpni_enable() - Enable the DPNI, allow sending and receiving frames.
188 * @mc_io: Pointer to MC portal's I/O object
189 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
190 * @token: Token of DPNI object
192 * Return: '0' on Success; Error code otherwise.
194 int dpni_enable(struct fsl_mc_io
*mc_io
,
198 struct fsl_mc_command cmd
= { 0 };
200 /* prepare command */
201 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_ENABLE
,
205 /* send command to mc*/
206 return mc_send_command(mc_io
, &cmd
);
210 * dpni_disable() - Disable the DPNI, stop sending and receiving frames.
211 * @mc_io: Pointer to MC portal's I/O object
212 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
213 * @token: Token of DPNI object
215 * Return: '0' on Success; Error code otherwise.
217 int dpni_disable(struct fsl_mc_io
*mc_io
,
221 struct fsl_mc_command cmd
= { 0 };
223 /* prepare command */
224 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_DISABLE
,
228 /* send command to mc*/
229 return mc_send_command(mc_io
, &cmd
);
233 * dpni_is_enabled() - Check if the DPNI is enabled.
234 * @mc_io: Pointer to MC portal's I/O object
235 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
236 * @token: Token of DPNI object
237 * @en: Returns '1' if object is enabled; '0' otherwise
239 * Return: '0' on Success; Error code otherwise.
241 int dpni_is_enabled(struct fsl_mc_io
*mc_io
,
246 struct fsl_mc_command cmd
= { 0 };
247 struct dpni_rsp_is_enabled
*rsp_params
;
250 /* prepare command */
251 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_IS_ENABLED
,
255 /* send command to mc*/
256 err
= mc_send_command(mc_io
, &cmd
);
260 /* retrieve response parameters */
261 rsp_params
= (struct dpni_rsp_is_enabled
*)cmd
.params
;
262 *en
= dpni_get_field(rsp_params
->enabled
, ENABLE
);
268 * dpni_reset() - Reset the DPNI, returns the object to initial state.
269 * @mc_io: Pointer to MC portal's I/O object
270 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
271 * @token: Token of DPNI object
273 * Return: '0' on Success; Error code otherwise.
275 int dpni_reset(struct fsl_mc_io
*mc_io
,
279 struct fsl_mc_command cmd
= { 0 };
281 /* prepare command */
282 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_RESET
,
286 /* send command to mc*/
287 return mc_send_command(mc_io
, &cmd
);
291 * dpni_set_irq_enable() - Set overall interrupt state.
292 * @mc_io: Pointer to MC portal's I/O object
293 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
294 * @token: Token of DPNI object
295 * @irq_index: The interrupt index to configure
296 * @en: Interrupt state: - enable = 1, disable = 0
298 * Allows GPP software to control when interrupts are generated.
299 * Each interrupt can have up to 32 causes. The enable/disable control's the
300 * overall interrupt state. if the interrupt is disabled no causes will cause
303 * Return: '0' on Success; Error code otherwise.
305 int dpni_set_irq_enable(struct fsl_mc_io
*mc_io
,
311 struct fsl_mc_command cmd
= { 0 };
312 struct dpni_cmd_set_irq_enable
*cmd_params
;
314 /* prepare command */
315 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_ENABLE
,
318 cmd_params
= (struct dpni_cmd_set_irq_enable
*)cmd
.params
;
319 dpni_set_field(cmd_params
->enable
, ENABLE
, en
);
320 cmd_params
->irq_index
= irq_index
;
322 /* send command to mc*/
323 return mc_send_command(mc_io
, &cmd
);
327 * dpni_get_irq_enable() - Get 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: Returned interrupt state - enable = 1, disable = 0
334 * Return: '0' on Success; Error code otherwise.
336 int dpni_get_irq_enable(struct fsl_mc_io
*mc_io
,
342 struct fsl_mc_command cmd
= { 0 };
343 struct dpni_cmd_get_irq_enable
*cmd_params
;
344 struct dpni_rsp_get_irq_enable
*rsp_params
;
348 /* prepare command */
349 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_ENABLE
,
352 cmd_params
= (struct dpni_cmd_get_irq_enable
*)cmd
.params
;
353 cmd_params
->irq_index
= irq_index
;
355 /* send command to mc*/
356 err
= mc_send_command(mc_io
, &cmd
);
360 /* retrieve response parameters */
361 rsp_params
= (struct dpni_rsp_get_irq_enable
*)cmd
.params
;
362 *en
= dpni_get_field(rsp_params
->enabled
, ENABLE
);
368 * dpni_set_irq_mask() - Set interrupt mask.
369 * @mc_io: Pointer to MC portal's I/O object
370 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
371 * @token: Token of DPNI object
372 * @irq_index: The interrupt index to configure
373 * @mask: event mask to trigger interrupt;
376 * 1 = consider event for asserting IRQ
378 * Every interrupt can have up to 32 causes and the interrupt model supports
379 * masking/unmasking each cause independently
381 * Return: '0' on Success; Error code otherwise.
383 int dpni_set_irq_mask(struct fsl_mc_io
*mc_io
,
389 struct fsl_mc_command cmd
= { 0 };
390 struct dpni_cmd_set_irq_mask
*cmd_params
;
392 /* prepare command */
393 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_MASK
,
396 cmd_params
= (struct dpni_cmd_set_irq_mask
*)cmd
.params
;
397 cmd_params
->mask
= cpu_to_le32(mask
);
398 cmd_params
->irq_index
= irq_index
;
400 /* send command to mc*/
401 return mc_send_command(mc_io
, &cmd
);
405 * dpni_get_irq_mask() - Get interrupt mask.
406 * @mc_io: Pointer to MC portal's I/O object
407 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
408 * @token: Token of DPNI object
409 * @irq_index: The interrupt index to configure
410 * @mask: Returned event mask to trigger interrupt
412 * Every interrupt can have up to 32 causes and the interrupt model supports
413 * masking/unmasking each cause independently
415 * Return: '0' on Success; Error code otherwise.
417 int dpni_get_irq_mask(struct fsl_mc_io
*mc_io
,
423 struct fsl_mc_command cmd
= { 0 };
424 struct dpni_cmd_get_irq_mask
*cmd_params
;
425 struct dpni_rsp_get_irq_mask
*rsp_params
;
428 /* prepare command */
429 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_MASK
,
432 cmd_params
= (struct dpni_cmd_get_irq_mask
*)cmd
.params
;
433 cmd_params
->irq_index
= irq_index
;
435 /* send command to mc*/
436 err
= mc_send_command(mc_io
, &cmd
);
440 /* retrieve response parameters */
441 rsp_params
= (struct dpni_rsp_get_irq_mask
*)cmd
.params
;
442 *mask
= le32_to_cpu(rsp_params
->mask
);
448 * dpni_get_irq_status() - Get the current status of any pending interrupts.
449 * @mc_io: Pointer to MC portal's I/O object
450 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
451 * @token: Token of DPNI object
452 * @irq_index: The interrupt index to configure
453 * @status: Returned interrupts status - one bit per cause:
454 * 0 = no interrupt pending
455 * 1 = interrupt pending
457 * Return: '0' on Success; Error code otherwise.
459 int dpni_get_irq_status(struct fsl_mc_io
*mc_io
,
465 struct fsl_mc_command cmd
= { 0 };
466 struct dpni_cmd_get_irq_status
*cmd_params
;
467 struct dpni_rsp_get_irq_status
*rsp_params
;
470 /* prepare command */
471 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_STATUS
,
474 cmd_params
= (struct dpni_cmd_get_irq_status
*)cmd
.params
;
475 cmd_params
->status
= cpu_to_le32(*status
);
476 cmd_params
->irq_index
= irq_index
;
478 /* send command to mc*/
479 err
= mc_send_command(mc_io
, &cmd
);
483 /* retrieve response parameters */
484 rsp_params
= (struct dpni_rsp_get_irq_status
*)cmd
.params
;
485 *status
= le32_to_cpu(rsp_params
->status
);
491 * dpni_clear_irq_status() - Clear a pending interrupt's status
492 * @mc_io: Pointer to MC portal's I/O object
493 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
494 * @token: Token of DPNI object
495 * @irq_index: The interrupt index to configure
496 * @status: bits to clear (W1C) - one bit per cause:
498 * 1 = clear status bit
500 * Return: '0' on Success; Error code otherwise.
502 int dpni_clear_irq_status(struct fsl_mc_io
*mc_io
,
508 struct fsl_mc_command cmd
= { 0 };
509 struct dpni_cmd_clear_irq_status
*cmd_params
;
511 /* prepare command */
512 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_CLEAR_IRQ_STATUS
,
515 cmd_params
= (struct dpni_cmd_clear_irq_status
*)cmd
.params
;
516 cmd_params
->irq_index
= irq_index
;
517 cmd_params
->status
= cpu_to_le32(status
);
519 /* send command to mc*/
520 return mc_send_command(mc_io
, &cmd
);
524 * dpni_get_attributes() - Retrieve DPNI attributes.
525 * @mc_io: Pointer to MC portal's I/O object
526 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
527 * @token: Token of DPNI object
528 * @attr: Object's attributes
530 * Return: '0' on Success; Error code otherwise.
532 int dpni_get_attributes(struct fsl_mc_io
*mc_io
,
535 struct dpni_attr
*attr
)
537 struct fsl_mc_command cmd
= { 0 };
538 struct dpni_rsp_get_attr
*rsp_params
;
542 /* prepare command */
543 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_ATTR
,
547 /* send command to mc*/
548 err
= mc_send_command(mc_io
, &cmd
);
552 /* retrieve response parameters */
553 rsp_params
= (struct dpni_rsp_get_attr
*)cmd
.params
;
554 attr
->options
= le32_to_cpu(rsp_params
->options
);
555 attr
->num_queues
= rsp_params
->num_queues
;
556 attr
->num_tcs
= rsp_params
->num_tcs
;
557 attr
->mac_filter_entries
= rsp_params
->mac_filter_entries
;
558 attr
->vlan_filter_entries
= rsp_params
->vlan_filter_entries
;
559 attr
->qos_entries
= rsp_params
->qos_entries
;
560 attr
->fs_entries
= le16_to_cpu(rsp_params
->fs_entries
);
561 attr
->qos_key_size
= rsp_params
->qos_key_size
;
562 attr
->fs_key_size
= rsp_params
->fs_key_size
;
563 attr
->wriop_version
= le16_to_cpu(rsp_params
->wriop_version
);
569 * dpni_set_errors_behavior() - Set errors behavior
570 * @mc_io: Pointer to MC portal's I/O object
571 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
572 * @token: Token of DPNI object
573 * @cfg: Errors configuration
575 * this function may be called numerous times with different
578 * Return: '0' on Success; Error code otherwise.
580 int dpni_set_errors_behavior(struct fsl_mc_io
*mc_io
,
583 struct dpni_error_cfg
*cfg
)
585 struct fsl_mc_command cmd
= { 0 };
586 struct dpni_cmd_set_errors_behavior
*cmd_params
;
588 /* prepare command */
589 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR
,
592 cmd_params
= (struct dpni_cmd_set_errors_behavior
*)cmd
.params
;
593 cmd_params
->errors
= cpu_to_le32(cfg
->errors
);
594 dpni_set_field(cmd_params
->flags
, ERROR_ACTION
, cfg
->error_action
);
595 dpni_set_field(cmd_params
->flags
, FRAME_ANN
, cfg
->set_frame_annotation
);
597 /* send command to mc*/
598 return mc_send_command(mc_io
, &cmd
);
602 * dpni_get_buffer_layout() - Retrieve buffer layout attributes.
603 * @mc_io: Pointer to MC portal's I/O object
604 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
605 * @token: Token of DPNI object
606 * @qtype: Type of queue to retrieve configuration for
607 * @layout: Returns buffer layout attributes
609 * Return: '0' on Success; Error code otherwise.
611 int dpni_get_buffer_layout(struct fsl_mc_io
*mc_io
,
614 enum dpni_queue_type qtype
,
615 struct dpni_buffer_layout
*layout
)
617 struct fsl_mc_command cmd
= { 0 };
618 struct dpni_cmd_get_buffer_layout
*cmd_params
;
619 struct dpni_rsp_get_buffer_layout
*rsp_params
;
622 /* prepare command */
623 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_BUFFER_LAYOUT
,
626 cmd_params
= (struct dpni_cmd_get_buffer_layout
*)cmd
.params
;
627 cmd_params
->qtype
= qtype
;
629 /* send command to mc*/
630 err
= mc_send_command(mc_io
, &cmd
);
634 /* retrieve response parameters */
635 rsp_params
= (struct dpni_rsp_get_buffer_layout
*)cmd
.params
;
636 layout
->pass_timestamp
= dpni_get_field(rsp_params
->flags
, PASS_TS
);
637 layout
->pass_parser_result
= dpni_get_field(rsp_params
->flags
, PASS_PR
);
638 layout
->pass_frame_status
= dpni_get_field(rsp_params
->flags
, PASS_FS
);
639 layout
->private_data_size
= le16_to_cpu(rsp_params
->private_data_size
);
640 layout
->data_align
= le16_to_cpu(rsp_params
->data_align
);
641 layout
->data_head_room
= le16_to_cpu(rsp_params
->head_room
);
642 layout
->data_tail_room
= le16_to_cpu(rsp_params
->tail_room
);
648 * dpni_set_buffer_layout() - Set buffer layout configuration.
649 * @mc_io: Pointer to MC portal's I/O object
650 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
651 * @token: Token of DPNI object
652 * @qtype: Type of queue this configuration applies to
653 * @layout: Buffer layout configuration
655 * Return: '0' on Success; Error code otherwise.
657 * @warning Allowed only when DPNI is disabled
659 int dpni_set_buffer_layout(struct fsl_mc_io
*mc_io
,
662 enum dpni_queue_type qtype
,
663 const struct dpni_buffer_layout
*layout
)
665 struct fsl_mc_command cmd
= { 0 };
666 struct dpni_cmd_set_buffer_layout
*cmd_params
;
668 /* prepare command */
669 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT
,
672 cmd_params
= (struct dpni_cmd_set_buffer_layout
*)cmd
.params
;
673 cmd_params
->qtype
= qtype
;
674 cmd_params
->options
= cpu_to_le16(layout
->options
);
675 dpni_set_field(cmd_params
->flags
, PASS_TS
, layout
->pass_timestamp
);
676 dpni_set_field(cmd_params
->flags
, PASS_PR
, layout
->pass_parser_result
);
677 dpni_set_field(cmd_params
->flags
, PASS_FS
, layout
->pass_frame_status
);
678 cmd_params
->private_data_size
= cpu_to_le16(layout
->private_data_size
);
679 cmd_params
->data_align
= cpu_to_le16(layout
->data_align
);
680 cmd_params
->head_room
= cpu_to_le16(layout
->data_head_room
);
681 cmd_params
->tail_room
= cpu_to_le16(layout
->data_tail_room
);
683 /* send command to mc*/
684 return mc_send_command(mc_io
, &cmd
);
688 * dpni_set_offload() - Set DPNI offload configuration.
689 * @mc_io: Pointer to MC portal's I/O object
690 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
691 * @token: Token of DPNI object
692 * @type: Type of DPNI offload
693 * @config: Offload configuration.
694 * For checksum offloads, non-zero value enables the offload
696 * Return: '0' on Success; Error code otherwise.
698 * @warning Allowed only when DPNI is disabled
701 int dpni_set_offload(struct fsl_mc_io
*mc_io
,
704 enum dpni_offload type
,
707 struct fsl_mc_command cmd
= { 0 };
708 struct dpni_cmd_set_offload
*cmd_params
;
710 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD
,
713 cmd_params
= (struct dpni_cmd_set_offload
*)cmd
.params
;
714 cmd_params
->dpni_offload
= type
;
715 cmd_params
->config
= cpu_to_le32(config
);
717 return mc_send_command(mc_io
, &cmd
);
720 int dpni_get_offload(struct fsl_mc_io
*mc_io
,
723 enum dpni_offload type
,
726 struct fsl_mc_command cmd
= { 0 };
727 struct dpni_cmd_get_offload
*cmd_params
;
728 struct dpni_rsp_get_offload
*rsp_params
;
731 /* prepare command */
732 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_OFFLOAD
,
735 cmd_params
= (struct dpni_cmd_get_offload
*)cmd
.params
;
736 cmd_params
->dpni_offload
= type
;
738 /* send command to mc*/
739 err
= mc_send_command(mc_io
, &cmd
);
743 /* retrieve response parameters */
744 rsp_params
= (struct dpni_rsp_get_offload
*)cmd
.params
;
745 *config
= le32_to_cpu(rsp_params
->config
);
751 * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used
752 * for enqueue operations
753 * @mc_io: Pointer to MC portal's I/O object
754 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
755 * @token: Token of DPNI object
756 * @qtype: Type of queue to receive QDID for
757 * @qdid: Returned virtual QDID value that should be used as an argument
758 * in all enqueue operations
760 * Return: '0' on Success; Error code otherwise.
762 int dpni_get_qdid(struct fsl_mc_io
*mc_io
,
765 enum dpni_queue_type qtype
,
768 struct fsl_mc_command cmd
= { 0 };
769 struct dpni_cmd_get_qdid
*cmd_params
;
770 struct dpni_rsp_get_qdid
*rsp_params
;
773 /* prepare command */
774 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_QDID
,
777 cmd_params
= (struct dpni_cmd_get_qdid
*)cmd
.params
;
778 cmd_params
->qtype
= qtype
;
780 /* send command to mc*/
781 err
= mc_send_command(mc_io
, &cmd
);
785 /* retrieve response parameters */
786 rsp_params
= (struct dpni_rsp_get_qdid
*)cmd
.params
;
787 *qdid
= le16_to_cpu(rsp_params
->qdid
);
793 * dpni_get_tx_data_offset() - Get the Tx data offset (from start of buffer)
794 * @mc_io: Pointer to MC portal's I/O object
795 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
796 * @token: Token of DPNI object
797 * @data_offset: Tx data offset (from start of buffer)
799 * Return: '0' on Success; Error code otherwise.
801 int dpni_get_tx_data_offset(struct fsl_mc_io
*mc_io
,
806 struct fsl_mc_command cmd
= { 0 };
807 struct dpni_rsp_get_tx_data_offset
*rsp_params
;
810 /* prepare command */
811 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET
,
815 /* send command to mc*/
816 err
= mc_send_command(mc_io
, &cmd
);
820 /* retrieve response parameters */
821 rsp_params
= (struct dpni_rsp_get_tx_data_offset
*)cmd
.params
;
822 *data_offset
= le16_to_cpu(rsp_params
->data_offset
);
828 * dpni_set_link_cfg() - set the link configuration.
829 * @mc_io: Pointer to MC portal's I/O object
830 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
831 * @token: Token of DPNI object
832 * @cfg: Link configuration
834 * Return: '0' on Success; Error code otherwise.
836 int dpni_set_link_cfg(struct fsl_mc_io
*mc_io
,
839 const struct dpni_link_cfg
*cfg
)
841 struct fsl_mc_command cmd
= { 0 };
842 struct dpni_cmd_link_cfg
*cmd_params
;
844 /* prepare command */
845 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG
,
848 cmd_params
= (struct dpni_cmd_link_cfg
*)cmd
.params
;
849 cmd_params
->rate
= cpu_to_le32(cfg
->rate
);
850 cmd_params
->options
= cpu_to_le64(cfg
->options
);
852 /* send command to mc*/
853 return mc_send_command(mc_io
, &cmd
);
857 * dpni_get_link_cfg() - return the link configuration
858 * @mc_io: Pointer to MC portal's I/O object
859 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
860 * @token: Token of DPNI object
861 * @cfg: Link configuration from dpni object
863 * Return: '0' on Success; Error code otherwise.
865 int dpni_get_link_cfg(struct fsl_mc_io
*mc_io
,
868 struct dpni_link_cfg
*cfg
)
870 struct fsl_mc_command cmd
= { 0 };
871 struct dpni_cmd_link_cfg
*rsp_params
;
874 /* prepare command */
875 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_LINK_CFG
,
879 /* send command to mc*/
880 err
= mc_send_command(mc_io
, &cmd
);
884 /* retrieve response parameters */
885 rsp_params
= (struct dpni_cmd_link_cfg
*)cmd
.params
;
886 cfg
->rate
= le32_to_cpu(rsp_params
->rate
);
887 cfg
->options
= le64_to_cpu(rsp_params
->options
);
893 * dpni_get_link_state() - Return the link state (either up or down)
894 * @mc_io: Pointer to MC portal's I/O object
895 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
896 * @token: Token of DPNI object
897 * @state: Returned link state;
899 * Return: '0' on Success; Error code otherwise.
901 int dpni_get_link_state(struct fsl_mc_io
*mc_io
,
904 struct dpni_link_state
*state
)
906 struct fsl_mc_command cmd
= { 0 };
907 struct dpni_rsp_get_link_state
*rsp_params
;
910 /* prepare command */
911 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE
,
915 /* send command to mc*/
916 err
= mc_send_command(mc_io
, &cmd
);
920 /* retrieve response parameters */
921 rsp_params
= (struct dpni_rsp_get_link_state
*)cmd
.params
;
922 state
->up
= dpni_get_field(rsp_params
->flags
, LINK_STATE
);
923 state
->rate
= le32_to_cpu(rsp_params
->rate
);
924 state
->options
= le64_to_cpu(rsp_params
->options
);
930 * dpni_set_max_frame_length() - Set the maximum received frame length.
931 * @mc_io: Pointer to MC portal's I/O object
932 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
933 * @token: Token of DPNI object
934 * @max_frame_length: Maximum received frame length (in
935 * bytes); frame is discarded if its
936 * length exceeds this value
938 * Return: '0' on Success; Error code otherwise.
940 int dpni_set_max_frame_length(struct fsl_mc_io
*mc_io
,
943 u16 max_frame_length
)
945 struct fsl_mc_command cmd
= { 0 };
946 struct dpni_cmd_set_max_frame_length
*cmd_params
;
948 /* prepare command */
949 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH
,
952 cmd_params
= (struct dpni_cmd_set_max_frame_length
*)cmd
.params
;
953 cmd_params
->max_frame_length
= cpu_to_le16(max_frame_length
);
955 /* send command to mc*/
956 return mc_send_command(mc_io
, &cmd
);
960 * dpni_get_max_frame_length() - Get the maximum received frame length.
961 * @mc_io: Pointer to MC portal's I/O object
962 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
963 * @token: Token of DPNI object
964 * @max_frame_length: Maximum received frame length (in
965 * bytes); frame is discarded if its
966 * length exceeds this value
968 * Return: '0' on Success; Error code otherwise.
970 int dpni_get_max_frame_length(struct fsl_mc_io
*mc_io
,
973 u16
*max_frame_length
)
975 struct fsl_mc_command cmd
= { 0 };
976 struct dpni_rsp_get_max_frame_length
*rsp_params
;
979 /* prepare command */
980 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH
,
984 /* send command to mc*/
985 err
= mc_send_command(mc_io
, &cmd
);
989 /* retrieve response parameters */
990 rsp_params
= (struct dpni_rsp_get_max_frame_length
*)cmd
.params
;
991 *max_frame_length
= le16_to_cpu(rsp_params
->max_frame_length
);
997 * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode
998 * @mc_io: Pointer to MC portal's I/O object
999 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1000 * @token: Token of DPNI object
1001 * @en: Set to '1' to enable; '0' to disable
1003 * Return: '0' on Success; Error code otherwise.
1005 int dpni_set_multicast_promisc(struct fsl_mc_io
*mc_io
,
1010 struct fsl_mc_command cmd
= { 0 };
1011 struct dpni_cmd_set_multicast_promisc
*cmd_params
;
1013 /* prepare command */
1014 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC
,
1017 cmd_params
= (struct dpni_cmd_set_multicast_promisc
*)cmd
.params
;
1018 dpni_set_field(cmd_params
->enable
, ENABLE
, en
);
1020 /* send command to mc*/
1021 return mc_send_command(mc_io
, &cmd
);
1025 * dpni_get_multicast_promisc() - Get multicast promiscuous mode
1026 * @mc_io: Pointer to MC portal's I/O object
1027 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1028 * @token: Token of DPNI object
1029 * @en: Returns '1' if enabled; '0' otherwise
1031 * Return: '0' on Success; Error code otherwise.
1033 int dpni_get_multicast_promisc(struct fsl_mc_io
*mc_io
,
1038 struct fsl_mc_command cmd
= { 0 };
1039 struct dpni_rsp_get_multicast_promisc
*rsp_params
;
1042 /* prepare command */
1043 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC
,
1047 /* send command to mc*/
1048 err
= mc_send_command(mc_io
, &cmd
);
1052 /* retrieve response parameters */
1053 rsp_params
= (struct dpni_rsp_get_multicast_promisc
*)cmd
.params
;
1054 *en
= dpni_get_field(rsp_params
->enabled
, ENABLE
);
1060 * dpni_set_unicast_promisc() - Enable/disable unicast promiscuous mode
1061 * @mc_io: Pointer to MC portal's I/O object
1062 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1063 * @token: Token of DPNI object
1064 * @en: Set to '1' to enable; '0' to disable
1066 * Return: '0' on Success; Error code otherwise.
1068 int dpni_set_unicast_promisc(struct fsl_mc_io
*mc_io
,
1073 struct fsl_mc_command cmd
= { 0 };
1074 struct dpni_cmd_set_unicast_promisc
*cmd_params
;
1076 /* prepare command */
1077 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC
,
1080 cmd_params
= (struct dpni_cmd_set_unicast_promisc
*)cmd
.params
;
1081 dpni_set_field(cmd_params
->enable
, ENABLE
, en
);
1083 /* send command to mc*/
1084 return mc_send_command(mc_io
, &cmd
);
1088 * dpni_get_unicast_promisc() - Get unicast promiscuous mode
1089 * @mc_io: Pointer to MC portal's I/O object
1090 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1091 * @token: Token of DPNI object
1092 * @en: Returns '1' if enabled; '0' otherwise
1094 * Return: '0' on Success; Error code otherwise.
1096 int dpni_get_unicast_promisc(struct fsl_mc_io
*mc_io
,
1101 struct fsl_mc_command cmd
= { 0 };
1102 struct dpni_rsp_get_unicast_promisc
*rsp_params
;
1105 /* prepare command */
1106 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC
,
1110 /* send command to mc*/
1111 err
= mc_send_command(mc_io
, &cmd
);
1115 /* retrieve response parameters */
1116 rsp_params
= (struct dpni_rsp_get_unicast_promisc
*)cmd
.params
;
1117 *en
= dpni_get_field(rsp_params
->enabled
, ENABLE
);
1123 * dpni_set_primary_mac_addr() - Set the primary MAC address
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 * @mac_addr: MAC address to set as primary address
1129 * Return: '0' on Success; Error code otherwise.
1131 int dpni_set_primary_mac_addr(struct fsl_mc_io
*mc_io
,
1134 const u8 mac_addr
[6])
1136 struct fsl_mc_command cmd
= { 0 };
1137 struct dpni_cmd_set_primary_mac_addr
*cmd_params
;
1140 /* prepare command */
1141 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC
,
1144 cmd_params
= (struct dpni_cmd_set_primary_mac_addr
*)cmd
.params
;
1145 for (i
= 0; i
< 6; i
++)
1146 cmd_params
->mac_addr
[i
] = mac_addr
[5 - i
];
1148 /* send command to mc*/
1149 return mc_send_command(mc_io
, &cmd
);
1153 * dpni_get_primary_mac_addr() - Get the primary MAC address
1154 * @mc_io: Pointer to MC portal's I/O object
1155 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1156 * @token: Token of DPNI object
1157 * @mac_addr: Returned MAC address
1159 * Return: '0' on Success; Error code otherwise.
1161 int dpni_get_primary_mac_addr(struct fsl_mc_io
*mc_io
,
1166 struct fsl_mc_command cmd
= { 0 };
1167 struct dpni_rsp_get_primary_mac_addr
*rsp_params
;
1170 /* prepare command */
1171 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC
,
1175 /* send command to mc*/
1176 err
= mc_send_command(mc_io
, &cmd
);
1180 /* retrieve response parameters */
1181 rsp_params
= (struct dpni_rsp_get_primary_mac_addr
*)cmd
.params
;
1182 for (i
= 0; i
< 6; i
++)
1183 mac_addr
[5 - i
] = rsp_params
->mac_addr
[i
];
1189 * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical
1190 * port the DPNI is attached to
1191 * @mc_io: Pointer to MC portal's I/O object
1192 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1193 * @token: Token of DPNI object
1194 * @mac_addr: MAC address of the physical port, if any, otherwise 0
1196 * The primary MAC address is not cleared by this operation.
1198 * Return: '0' on Success; Error code otherwise.
1200 int dpni_get_port_mac_addr(struct fsl_mc_io
*mc_io
,
1205 struct fsl_mc_command cmd
= { 0 };
1206 struct dpni_rsp_get_port_mac_addr
*rsp_params
;
1209 /* prepare command */
1210 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR
,
1214 /* send command to mc*/
1215 err
= mc_send_command(mc_io
, &cmd
);
1219 /* retrieve response parameters */
1220 rsp_params
= (struct dpni_rsp_get_port_mac_addr
*)cmd
.params
;
1221 for (i
= 0; i
< 6; i
++)
1222 mac_addr
[5 - i
] = rsp_params
->mac_addr
[i
];
1228 * dpni_add_mac_addr() - Add MAC address filter
1229 * @mc_io: Pointer to MC portal's I/O object
1230 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1231 * @token: Token of DPNI object
1232 * @mac_addr: MAC address to add
1234 * Return: '0' on Success; Error code otherwise.
1236 int dpni_add_mac_addr(struct fsl_mc_io
*mc_io
,
1239 const u8 mac_addr
[6])
1241 struct fsl_mc_command cmd
= { 0 };
1242 struct dpni_cmd_add_mac_addr
*cmd_params
;
1245 /* prepare command */
1246 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR
,
1249 cmd_params
= (struct dpni_cmd_add_mac_addr
*)cmd
.params
;
1250 for (i
= 0; i
< 6; i
++)
1251 cmd_params
->mac_addr
[i
] = mac_addr
[5 - i
];
1253 /* send command to mc*/
1254 return mc_send_command(mc_io
, &cmd
);
1258 * dpni_remove_mac_addr() - Remove MAC address filter
1259 * @mc_io: Pointer to MC portal's I/O object
1260 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1261 * @token: Token of DPNI object
1262 * @mac_addr: MAC address to remove
1264 * Return: '0' on Success; Error code otherwise.
1266 int dpni_remove_mac_addr(struct fsl_mc_io
*mc_io
,
1269 const u8 mac_addr
[6])
1271 struct fsl_mc_command cmd
= { 0 };
1272 struct dpni_cmd_remove_mac_addr
*cmd_params
;
1275 /* prepare command */
1276 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR
,
1279 cmd_params
= (struct dpni_cmd_remove_mac_addr
*)cmd
.params
;
1280 for (i
= 0; i
< 6; i
++)
1281 cmd_params
->mac_addr
[i
] = mac_addr
[5 - i
];
1283 /* send command to mc*/
1284 return mc_send_command(mc_io
, &cmd
);
1288 * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters
1289 * @mc_io: Pointer to MC portal's I/O object
1290 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1291 * @token: Token of DPNI object
1292 * @unicast: Set to '1' to clear unicast addresses
1293 * @multicast: Set to '1' to clear multicast addresses
1295 * The primary MAC address is not cleared by this operation.
1297 * Return: '0' on Success; Error code otherwise.
1299 int dpni_clear_mac_filters(struct fsl_mc_io
*mc_io
,
1305 struct fsl_mc_command cmd
= { 0 };
1306 struct dpni_cmd_clear_mac_filters
*cmd_params
;
1308 /* prepare command */
1309 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS
,
1312 cmd_params
= (struct dpni_cmd_clear_mac_filters
*)cmd
.params
;
1313 dpni_set_field(cmd_params
->flags
, UNICAST_FILTERS
, unicast
);
1314 dpni_set_field(cmd_params
->flags
, MULTICAST_FILTERS
, multicast
);
1316 /* send command to mc*/
1317 return mc_send_command(mc_io
, &cmd
);
1321 * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration
1322 * @mc_io: Pointer to MC portal's I/O object
1323 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1324 * @token: Token of DPNI object
1325 * @tc_id: Traffic class selection (0-7)
1326 * @cfg: Traffic class distribution configuration
1328 * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpni_prepare_key_cfg()
1329 * first to prepare the key_cfg_iova parameter
1331 * Return: '0' on Success; error code otherwise.
1333 int dpni_set_rx_tc_dist(struct fsl_mc_io
*mc_io
,
1337 const struct dpni_rx_tc_dist_cfg
*cfg
)
1339 struct fsl_mc_command cmd
= { 0 };
1340 struct dpni_cmd_set_rx_tc_dist
*cmd_params
;
1342 /* prepare command */
1343 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST
,
1346 cmd_params
= (struct dpni_cmd_set_rx_tc_dist
*)cmd
.params
;
1347 cmd_params
->dist_size
= cpu_to_le16(cfg
->dist_size
);
1348 cmd_params
->tc_id
= tc_id
;
1349 dpni_set_field(cmd_params
->flags
, DIST_MODE
, cfg
->dist_mode
);
1350 dpni_set_field(cmd_params
->flags
, MISS_ACTION
, cfg
->fs_cfg
.miss_action
);
1351 cmd_params
->default_flow_id
= cpu_to_le16(cfg
->fs_cfg
.default_flow_id
);
1352 cmd_params
->key_cfg_iova
= cpu_to_le64(cfg
->key_cfg_iova
);
1354 /* send command to mc*/
1355 return mc_send_command(mc_io
, &cmd
);
1359 * dpni_set_congestion_notification() - Set traffic class congestion
1360 * notification configuration
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 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported
1365 * @tc_id: Traffic class selection (0-7)
1366 * @cfg: Congestion notification configuration
1368 * Return: '0' on Success; error code otherwise.
1370 int dpni_set_congestion_notification(
1371 struct fsl_mc_io
*mc_io
,
1374 enum dpni_queue_type qtype
,
1376 const struct dpni_congestion_notification_cfg
*cfg
)
1378 struct dpni_cmd_set_congestion_notification
*cmd_params
;
1379 struct fsl_mc_command cmd
= { 0 };
1381 /* prepare command */
1383 mc_encode_cmd_header(DPNI_CMDID_SET_CONGESTION_NOTIFICATION
,
1386 cmd_params
= (struct dpni_cmd_set_congestion_notification
*)cmd
.params
;
1387 cmd_params
->qtype
= qtype
;
1388 cmd_params
->tc
= tc_id
;
1389 cmd_params
->dest_id
= cpu_to_le32(cfg
->dest_cfg
.dest_id
);
1390 cmd_params
->notification_mode
= cpu_to_le16(cfg
->notification_mode
);
1391 cmd_params
->dest_priority
= cfg
->dest_cfg
.priority
;
1392 dpni_set_field(cmd_params
->type_units
, DEST_TYPE
,
1393 cfg
->dest_cfg
.dest_type
);
1394 dpni_set_field(cmd_params
->type_units
, CONG_UNITS
, cfg
->units
);
1395 cmd_params
->message_iova
= cpu_to_le64(cfg
->message_iova
);
1396 cmd_params
->message_ctx
= cpu_to_le64(cfg
->message_ctx
);
1397 cmd_params
->threshold_entry
= cpu_to_le32(cfg
->threshold_entry
);
1398 cmd_params
->threshold_exit
= cpu_to_le32(cfg
->threshold_exit
);
1400 /* send command to mc*/
1401 return mc_send_command(mc_io
, &cmd
);
1405 * dpni_set_queue() - Set queue parameters
1406 * @mc_io: Pointer to MC portal's I/O object
1407 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1408 * @token: Token of DPNI object
1409 * @qtype: Type of queue - all queue types are supported, although
1410 * the command is ignored for Tx
1411 * @tc: Traffic class, in range 0 to NUM_TCS - 1
1412 * @index: Selects the specific queue out of the set allocated for the
1413 * same TC. Value must be in range 0 to NUM_QUEUES - 1
1414 * @options: A combination of DPNI_QUEUE_OPT_ values that control what
1415 * configuration options are set on the queue
1416 * @queue: Queue structure
1418 * Return: '0' on Success; Error code otherwise.
1420 int dpni_set_queue(struct fsl_mc_io
*mc_io
,
1423 enum dpni_queue_type qtype
,
1427 const struct dpni_queue
*queue
)
1429 struct fsl_mc_command cmd
= { 0 };
1430 struct dpni_cmd_set_queue
*cmd_params
;
1432 /* prepare command */
1433 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE
,
1436 cmd_params
= (struct dpni_cmd_set_queue
*)cmd
.params
;
1437 cmd_params
->qtype
= qtype
;
1438 cmd_params
->tc
= tc
;
1439 cmd_params
->index
= index
;
1440 cmd_params
->options
= options
;
1441 cmd_params
->dest_id
= cpu_to_le32(queue
->destination
.id
);
1442 cmd_params
->dest_prio
= queue
->destination
.priority
;
1443 dpni_set_field(cmd_params
->flags
, DEST_TYPE
, queue
->destination
.type
);
1444 dpni_set_field(cmd_params
->flags
, STASH_CTRL
, queue
->flc
.stash_control
);
1445 dpni_set_field(cmd_params
->flags
, HOLD_ACTIVE
,
1446 queue
->destination
.hold_active
);
1447 cmd_params
->flc
= cpu_to_le64(queue
->flc
.value
);
1448 cmd_params
->user_context
= cpu_to_le64(queue
->user_context
);
1450 /* send command to mc */
1451 return mc_send_command(mc_io
, &cmd
);
1455 * dpni_get_queue() - Get queue parameters
1456 * @mc_io: Pointer to MC portal's I/O object
1457 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1458 * @token: Token of DPNI object
1459 * @qtype: Type of queue - all queue types are supported
1460 * @tc: Traffic class, in range 0 to NUM_TCS - 1
1461 * @index: Selects the specific queue out of the set allocated for the
1462 * same TC. Value must be in range 0 to NUM_QUEUES - 1
1463 * @queue: Queue configuration structure
1464 * @qid: Queue identification
1466 * Return: '0' on Success; Error code otherwise.
1468 int dpni_get_queue(struct fsl_mc_io
*mc_io
,
1471 enum dpni_queue_type qtype
,
1474 struct dpni_queue
*queue
,
1475 struct dpni_queue_id
*qid
)
1477 struct fsl_mc_command cmd
= { 0 };
1478 struct dpni_cmd_get_queue
*cmd_params
;
1479 struct dpni_rsp_get_queue
*rsp_params
;
1482 /* prepare command */
1483 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE
,
1486 cmd_params
= (struct dpni_cmd_get_queue
*)cmd
.params
;
1487 cmd_params
->qtype
= qtype
;
1488 cmd_params
->tc
= tc
;
1489 cmd_params
->index
= index
;
1491 /* send command to mc */
1492 err
= mc_send_command(mc_io
, &cmd
);
1496 /* retrieve response parameters */
1497 rsp_params
= (struct dpni_rsp_get_queue
*)cmd
.params
;
1498 queue
->destination
.id
= le32_to_cpu(rsp_params
->dest_id
);
1499 queue
->destination
.priority
= rsp_params
->dest_prio
;
1500 queue
->destination
.type
= dpni_get_field(rsp_params
->flags
,
1502 queue
->flc
.stash_control
= dpni_get_field(rsp_params
->flags
,
1504 queue
->destination
.hold_active
= dpni_get_field(rsp_params
->flags
,
1506 queue
->flc
.value
= le64_to_cpu(rsp_params
->flc
);
1507 queue
->user_context
= le64_to_cpu(rsp_params
->user_context
);
1508 qid
->fqid
= le32_to_cpu(rsp_params
->fqid
);
1509 qid
->qdbin
= le16_to_cpu(rsp_params
->qdbin
);
1515 * dpni_get_statistics() - Get DPNI statistics
1516 * @mc_io: Pointer to MC portal's I/O object
1517 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1518 * @token: Token of DPNI object
1519 * @page: Selects the statistics page to retrieve, see
1520 * DPNI_GET_STATISTICS output. Pages are numbered 0 to 6.
1521 * @stat: Structure containing the statistics
1523 * Return: '0' on Success; Error code otherwise.
1525 int dpni_get_statistics(struct fsl_mc_io
*mc_io
,
1529 union dpni_statistics
*stat
)
1531 struct fsl_mc_command cmd
= { 0 };
1532 struct dpni_cmd_get_statistics
*cmd_params
;
1533 struct dpni_rsp_get_statistics
*rsp_params
;
1536 /* prepare command */
1537 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS
,
1540 cmd_params
= (struct dpni_cmd_get_statistics
*)cmd
.params
;
1541 cmd_params
->page_number
= page
;
1543 /* send command to mc */
1544 err
= mc_send_command(mc_io
, &cmd
);
1548 /* retrieve response parameters */
1549 rsp_params
= (struct dpni_rsp_get_statistics
*)cmd
.params
;
1550 for (i
= 0; i
< DPNI_STATISTICS_CNT
; i
++)
1551 stat
->raw
.counter
[i
] = le64_to_cpu(rsp_params
->counter
[i
]);
1557 * dpni_set_taildrop() - Set taildrop per queue or TC
1558 * @mc_io: Pointer to MC portal's I/O object
1559 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1560 * @token: Token of DPNI object
1561 * @cg_point: Congestion point
1562 * @qtype: Queue type on which the taildrop is configured.
1563 * Only Rx queues are supported for now
1564 * @tc: Traffic class to apply this taildrop to
1565 * @index: Index of the queue if the DPNI supports multiple queues for
1566 * traffic distribution. Ignored if CONGESTION_POINT is not 0.
1567 * @taildrop: Taildrop structure
1569 * Return: '0' on Success; Error code otherwise.
1571 int dpni_set_taildrop(struct fsl_mc_io
*mc_io
,
1574 enum dpni_congestion_point cg_point
,
1575 enum dpni_queue_type qtype
,
1578 struct dpni_taildrop
*taildrop
)
1580 struct fsl_mc_command cmd
= { 0 };
1581 struct dpni_cmd_set_taildrop
*cmd_params
;
1583 /* prepare command */
1584 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP
,
1587 cmd_params
= (struct dpni_cmd_set_taildrop
*)cmd
.params
;
1588 cmd_params
->congestion_point
= cg_point
;
1589 cmd_params
->qtype
= qtype
;
1590 cmd_params
->tc
= tc
;
1591 cmd_params
->index
= index
;
1592 dpni_set_field(cmd_params
->enable
, ENABLE
, taildrop
->enable
);
1593 cmd_params
->units
= taildrop
->units
;
1594 cmd_params
->threshold
= cpu_to_le32(taildrop
->threshold
);
1596 /* send command to mc */
1597 return mc_send_command(mc_io
, &cmd
);
1601 * dpni_get_taildrop() - Get taildrop information
1602 * @mc_io: Pointer to MC portal's I/O object
1603 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1604 * @token: Token of DPNI object
1605 * @cg_point: Congestion point
1606 * @qtype: Queue type on which the taildrop is configured.
1607 * Only Rx queues are supported for now
1608 * @tc: Traffic class to apply this taildrop to
1609 * @index: Index of the queue if the DPNI supports multiple queues for
1610 * traffic distribution. Ignored if CONGESTION_POINT is not 0.
1611 * @taildrop: Taildrop structure
1613 * Return: '0' on Success; Error code otherwise.
1615 int dpni_get_taildrop(struct fsl_mc_io
*mc_io
,
1618 enum dpni_congestion_point cg_point
,
1619 enum dpni_queue_type qtype
,
1622 struct dpni_taildrop
*taildrop
)
1624 struct fsl_mc_command cmd
= { 0 };
1625 struct dpni_cmd_get_taildrop
*cmd_params
;
1626 struct dpni_rsp_get_taildrop
*rsp_params
;
1629 /* prepare command */
1630 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP
,
1633 cmd_params
= (struct dpni_cmd_get_taildrop
*)cmd
.params
;
1634 cmd_params
->congestion_point
= cg_point
;
1635 cmd_params
->qtype
= qtype
;
1636 cmd_params
->tc
= tc
;
1637 cmd_params
->index
= index
;
1639 /* send command to mc */
1640 err
= mc_send_command(mc_io
, &cmd
);
1644 /* retrieve response parameters */
1645 rsp_params
= (struct dpni_rsp_get_taildrop
*)cmd
.params
;
1646 taildrop
->enable
= dpni_get_field(rsp_params
->enable
, ENABLE
);
1647 taildrop
->units
= rsp_params
->units
;
1648 taildrop
->threshold
= le32_to_cpu(rsp_params
->threshold
);
1654 * dpni_get_api_version() - Get Data Path Network Interface API version
1655 * @mc_io: Pointer to MC portal's I/O object
1656 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1657 * @major_ver: Major version of data path network interface API
1658 * @minor_ver: Minor version of data path network interface API
1660 * Return: '0' on Success; Error code otherwise.
1662 int dpni_get_api_version(struct fsl_mc_io
*mc_io
,
1667 struct dpni_rsp_get_api_version
*rsp_params
;
1668 struct fsl_mc_command cmd
= { 0 };
1671 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION
,
1674 err
= mc_send_command(mc_io
, &cmd
);
1678 rsp_params
= (struct dpni_rsp_get_api_version
*)cmd
.params
;
1679 *major_ver
= le16_to_cpu(rsp_params
->major
);
1680 *minor_ver
= le16_to_cpu(rsp_params
->minor
);
1686 * dpni_set_rx_fs_dist() - Set Rx flow steering distribution
1687 * @mc_io: Pointer to MC portal's I/O object
1688 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1689 * @token: Token of DPNI object
1690 * @cfg: Distribution configuration
1692 * If the FS is already enabled with a previous call the classification
1693 * key will be changed but all the table rules are kept. If the
1694 * existing rules do not match the key the results will not be
1695 * predictable. It is the user responsibility to keep key integrity.
1696 * If cfg.enable is set to 1 the command will create a flow steering table
1697 * and will classify packets according to this table. The packets that
1698 * miss all the table rules will be classified according to settings
1699 * made in dpni_set_rx_hash_dist()
1700 * If cfg.enable is set to 0 the command will clear flow steering table.
1701 * The packets will be classified according to settings made in
1702 * dpni_set_rx_hash_dist()
1704 int dpni_set_rx_fs_dist(struct fsl_mc_io
*mc_io
,
1707 const struct dpni_rx_dist_cfg
*cfg
)
1709 struct dpni_cmd_set_rx_fs_dist
*cmd_params
;
1710 struct fsl_mc_command cmd
= { 0 };
1712 /* prepare command */
1713 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_RX_FS_DIST
,
1716 cmd_params
= (struct dpni_cmd_set_rx_fs_dist
*)cmd
.params
;
1717 cmd_params
->dist_size
= cpu_to_le16(cfg
->dist_size
);
1718 dpni_set_field(cmd_params
->enable
, RX_FS_DIST_ENABLE
, cfg
->enable
);
1719 cmd_params
->tc
= cfg
->tc
;
1720 cmd_params
->miss_flow_id
= cpu_to_le16(cfg
->fs_miss_flow_id
);
1721 cmd_params
->key_cfg_iova
= cpu_to_le64(cfg
->key_cfg_iova
);
1723 /* send command to mc*/
1724 return mc_send_command(mc_io
, &cmd
);
1728 * dpni_set_rx_hash_dist() - Set Rx hash distribution
1729 * @mc_io: Pointer to MC portal's I/O object
1730 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1731 * @token: Token of DPNI object
1732 * @cfg: Distribution configuration
1733 * If cfg.enable is set to 1 the packets will be classified using a hash
1734 * function based on the key received in cfg.key_cfg_iova parameter.
1735 * If cfg.enable is set to 0 the packets will be sent to the default queue
1737 int dpni_set_rx_hash_dist(struct fsl_mc_io
*mc_io
,
1740 const struct dpni_rx_dist_cfg
*cfg
)
1742 struct dpni_cmd_set_rx_hash_dist
*cmd_params
;
1743 struct fsl_mc_command cmd
= { 0 };
1745 /* prepare command */
1746 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_RX_HASH_DIST
,
1749 cmd_params
= (struct dpni_cmd_set_rx_hash_dist
*)cmd
.params
;
1750 cmd_params
->dist_size
= cpu_to_le16(cfg
->dist_size
);
1751 dpni_set_field(cmd_params
->enable
, RX_HASH_DIST_ENABLE
, cfg
->enable
);
1752 cmd_params
->tc
= cfg
->tc
;
1753 cmd_params
->key_cfg_iova
= cpu_to_le64(cfg
->key_cfg_iova
);
1755 /* send command to mc*/
1756 return mc_send_command(mc_io
, &cmd
);
1760 * dpni_add_fs_entry() - Add Flow Steering entry for a specific traffic class
1761 * (to select a flow ID)
1762 * @mc_io: Pointer to MC portal's I/O object
1763 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1764 * @token: Token of DPNI object
1765 * @tc_id: Traffic class selection (0-7)
1766 * @index: Location in the FS table where to insert the entry.
1767 * Only relevant if MASKING is enabled for FS
1768 * classification on this DPNI, it is ignored for exact match.
1769 * @cfg: Flow steering rule to add
1770 * @action: Action to be taken as result of a classification hit
1772 * Return: '0' on Success; Error code otherwise.
1774 int dpni_add_fs_entry(struct fsl_mc_io
*mc_io
,
1779 const struct dpni_rule_cfg
*cfg
,
1780 const struct dpni_fs_action_cfg
*action
)
1782 struct dpni_cmd_add_fs_entry
*cmd_params
;
1783 struct fsl_mc_command cmd
= { 0 };
1785 /* prepare command */
1786 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_ADD_FS_ENT
,
1789 cmd_params
= (struct dpni_cmd_add_fs_entry
*)cmd
.params
;
1790 cmd_params
->tc_id
= tc_id
;
1791 cmd_params
->key_size
= cfg
->key_size
;
1792 cmd_params
->index
= cpu_to_le16(index
);
1793 cmd_params
->key_iova
= cpu_to_le64(cfg
->key_iova
);
1794 cmd_params
->mask_iova
= cpu_to_le64(cfg
->mask_iova
);
1795 cmd_params
->options
= cpu_to_le16(action
->options
);
1796 cmd_params
->flow_id
= cpu_to_le16(action
->flow_id
);
1797 cmd_params
->flc
= cpu_to_le64(action
->flc
);
1799 /* send command to mc*/
1800 return mc_send_command(mc_io
, &cmd
);
1804 * dpni_remove_fs_entry() - Remove Flow Steering entry from a specific
1806 * @mc_io: Pointer to MC portal's I/O object
1807 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1808 * @token: Token of DPNI object
1809 * @tc_id: Traffic class selection (0-7)
1810 * @cfg: Flow steering rule to remove
1812 * Return: '0' on Success; Error code otherwise.
1814 int dpni_remove_fs_entry(struct fsl_mc_io
*mc_io
,
1818 const struct dpni_rule_cfg
*cfg
)
1820 struct dpni_cmd_remove_fs_entry
*cmd_params
;
1821 struct fsl_mc_command cmd
= { 0 };
1823 /* prepare command */
1824 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_REMOVE_FS_ENT
,
1827 cmd_params
= (struct dpni_cmd_remove_fs_entry
*)cmd
.params
;
1828 cmd_params
->tc_id
= tc_id
;
1829 cmd_params
->key_size
= cfg
->key_size
;
1830 cmd_params
->key_iova
= cpu_to_le64(cfg
->key_iova
);
1831 cmd_params
->mask_iova
= cpu_to_le64(cfg
->mask_iova
);
1833 /* send command to mc*/
1834 return mc_send_command(mc_io
, &cmd
);
1838 * dpni_set_qos_table() - Set QoS mapping table
1839 * @mc_io: Pointer to MC portal's I/O object
1840 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1841 * @token: Token of DPNI object
1842 * @cfg: QoS table configuration
1844 * This function and all QoS-related functions require that
1845 *'max_tcs > 1' was set at DPNI creation.
1847 * warning: Before calling this function, call dpkg_prepare_key_cfg() to
1848 * prepare the key_cfg_iova parameter
1850 * Return: '0' on Success; Error code otherwise.
1852 int dpni_set_qos_table(struct fsl_mc_io
*mc_io
,
1855 const struct dpni_qos_tbl_cfg
*cfg
)
1857 struct dpni_cmd_set_qos_table
*cmd_params
;
1858 struct fsl_mc_command cmd
= { 0 };
1860 /* prepare command */
1861 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_QOS_TBL
,
1864 cmd_params
= (struct dpni_cmd_set_qos_table
*)cmd
.params
;
1865 cmd_params
->default_tc
= cfg
->default_tc
;
1866 cmd_params
->key_cfg_iova
= cpu_to_le64(cfg
->key_cfg_iova
);
1867 dpni_set_field(cmd_params
->discard_on_miss
, DISCARD_ON_MISS
,
1868 cfg
->discard_on_miss
);
1870 /* send command to mc*/
1871 return mc_send_command(mc_io
, &cmd
);
1875 * dpni_add_qos_entry() - Add QoS mapping entry (to select a traffic class)
1876 * @mc_io: Pointer to MC portal's I/O object
1877 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1878 * @token: Token of DPNI object
1879 * @cfg: QoS rule to add
1880 * @tc_id: Traffic class selection (0-7)
1881 * @index: Location in the QoS table where to insert the entry.
1882 * Only relevant if MASKING is enabled for QoS classification on
1883 * this DPNI, it is ignored for exact match.
1885 * Return: '0' on Success; Error code otherwise.
1887 int dpni_add_qos_entry(struct fsl_mc_io
*mc_io
,
1890 const struct dpni_rule_cfg
*cfg
,
1894 struct dpni_cmd_add_qos_entry
*cmd_params
;
1895 struct fsl_mc_command cmd
= { 0 };
1897 /* prepare command */
1898 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_ADD_QOS_ENT
,
1901 cmd_params
= (struct dpni_cmd_add_qos_entry
*)cmd
.params
;
1902 cmd_params
->tc_id
= tc_id
;
1903 cmd_params
->key_size
= cfg
->key_size
;
1904 cmd_params
->index
= cpu_to_le16(index
);
1905 cmd_params
->key_iova
= cpu_to_le64(cfg
->key_iova
);
1906 cmd_params
->mask_iova
= cpu_to_le64(cfg
->mask_iova
);
1908 /* send command to mc*/
1909 return mc_send_command(mc_io
, &cmd
);
1913 * dpni_remove_qos_entry() - Remove QoS mapping entry
1914 * @mc_io: Pointer to MC portal's I/O object
1915 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1916 * @token: Token of DPNI object
1917 * @cfg: QoS rule to remove
1919 * Return: '0' on Success; Error code otherwise.
1921 int dpni_remove_qos_entry(struct fsl_mc_io
*mc_io
,
1924 const struct dpni_rule_cfg
*cfg
)
1926 struct dpni_cmd_remove_qos_entry
*cmd_params
;
1927 struct fsl_mc_command cmd
= { 0 };
1929 /* prepare command */
1930 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_REMOVE_QOS_ENT
,
1933 cmd_params
= (struct dpni_cmd_remove_qos_entry
*)cmd
.params
;
1934 cmd_params
->key_size
= cfg
->key_size
;
1935 cmd_params
->key_iova
= cpu_to_le64(cfg
->key_iova
);
1936 cmd_params
->mask_iova
= cpu_to_le64(cfg
->mask_iova
);
1938 /* send command to mc*/
1939 return mc_send_command(mc_io
, &cmd
);
1943 * dpni_clear_qos_table() - Clear all QoS mapping entries
1944 * @mc_io: Pointer to MC portal's I/O object
1945 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1946 * @token: Token of DPNI object
1948 * Following this function call, all frames are directed to
1949 * the default traffic class (0)
1951 * Return: '0' on Success; Error code otherwise.
1953 int dpni_clear_qos_table(struct fsl_mc_io
*mc_io
,
1957 struct fsl_mc_command cmd
= { 0 };
1959 /* prepare command */
1960 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_CLR_QOS_TBL
,
1964 /* send command to mc*/
1965 return mc_send_command(mc_io
, &cmd
);
1969 * dpni_set_tx_shaping() - Set the transmit shaping
1970 * @mc_io: Pointer to MC portal's I/O object
1971 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1972 * @token: Token of DPNI object
1973 * @tx_cr_shaper: TX committed rate shaping configuration
1974 * @tx_er_shaper: TX excess rate shaping configuration
1975 * @coupled: Committed and excess rate shapers are coupled
1977 * Return: '0' on Success; Error code otherwise.
1979 int dpni_set_tx_shaping(struct fsl_mc_io
*mc_io
,
1982 const struct dpni_tx_shaping_cfg
*tx_cr_shaper
,
1983 const struct dpni_tx_shaping_cfg
*tx_er_shaper
,
1986 struct dpni_cmd_set_tx_shaping
*cmd_params
;
1987 struct fsl_mc_command cmd
= { 0 };
1989 /* prepare command */
1990 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_TX_SHAPING
,
1993 cmd_params
= (struct dpni_cmd_set_tx_shaping
*)cmd
.params
;
1994 cmd_params
->tx_cr_max_burst_size
= cpu_to_le16(tx_cr_shaper
->max_burst_size
);
1995 cmd_params
->tx_er_max_burst_size
= cpu_to_le16(tx_er_shaper
->max_burst_size
);
1996 cmd_params
->tx_cr_rate_limit
= cpu_to_le32(tx_cr_shaper
->rate_limit
);
1997 cmd_params
->tx_er_rate_limit
= cpu_to_le32(tx_er_shaper
->rate_limit
);
1998 dpni_set_field(cmd_params
->coupled
, COUPLED
, coupled
);
2000 /* send command to mc*/
2001 return mc_send_command(mc_io
, &cmd
);
2005 * dpni_get_single_step_cfg() - return current configuration for
2007 * @mc_io: Pointer to MC portal's I/O object
2008 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2009 * @token: Token of DPNI object
2010 * @ptp_cfg: ptp single step configuration
2012 * Return: '0' on Success; Error code otherwise.
2015 int dpni_get_single_step_cfg(struct fsl_mc_io
*mc_io
,
2018 struct dpni_single_step_cfg
*ptp_cfg
)
2020 struct dpni_rsp_single_step_cfg
*rsp_params
;
2021 struct fsl_mc_command cmd
= { 0 };
2024 /* prepare command */
2025 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_GET_SINGLE_STEP_CFG
,
2027 /* send command to mc*/
2028 err
= mc_send_command(mc_io
, &cmd
);
2032 /* read command response */
2033 rsp_params
= (struct dpni_rsp_single_step_cfg
*)cmd
.params
;
2034 ptp_cfg
->offset
= le16_to_cpu(rsp_params
->offset
);
2035 ptp_cfg
->en
= dpni_get_field(le16_to_cpu(rsp_params
->flags
),
2036 PTP_ENABLE
) ? 1 : 0;
2037 ptp_cfg
->ch_update
= dpni_get_field(le16_to_cpu(rsp_params
->flags
),
2038 PTP_CH_UPDATE
) ? 1 : 0;
2039 ptp_cfg
->peer_delay
= le32_to_cpu(rsp_params
->peer_delay
);
2045 * dpni_set_single_step_cfg() - enable/disable and configure single step PTP
2046 * @mc_io: Pointer to MC portal's I/O object
2047 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
2048 * @token: Token of DPNI object
2049 * @ptp_cfg: ptp single step configuration
2051 * Return: '0' on Success; Error code otherwise.
2053 * The function has effect only when dpni object is connected to a dpmac
2054 * object. If the dpni is not connected to a dpmac the configuration will
2055 * be stored inside and applied when connection is made.
2057 int dpni_set_single_step_cfg(struct fsl_mc_io
*mc_io
,
2060 struct dpni_single_step_cfg
*ptp_cfg
)
2062 struct dpni_cmd_single_step_cfg
*cmd_params
;
2063 struct fsl_mc_command cmd
= { 0 };
2066 /* prepare command */
2067 cmd
.header
= mc_encode_cmd_header(DPNI_CMDID_SET_SINGLE_STEP_CFG
,
2069 cmd_params
= (struct dpni_cmd_single_step_cfg
*)cmd
.params
;
2070 cmd_params
->offset
= cpu_to_le16(ptp_cfg
->offset
);
2071 cmd_params
->peer_delay
= cpu_to_le32(ptp_cfg
->peer_delay
);
2073 flags
= le16_to_cpu(cmd_params
->flags
);
2074 dpni_set_field(flags
, PTP_ENABLE
, !!ptp_cfg
->en
);
2075 dpni_set_field(flags
, PTP_CH_UPDATE
, !!ptp_cfg
->ch_update
);
2076 cmd_params
->flags
= cpu_to_le16(flags
);
2078 /* send command to mc*/
2079 return mc_send_command(mc_io
, &cmd
);