1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
6 #include <fsl_mc_sys.h>
7 #include <fsl_mc_cmd.h>
9 #include <fsl_dpci_cmd.h>
12 * dpci_open() - Open a control session for the specified object
13 * @mc_io: Pointer to MC portal's I/O object
14 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
15 * @dpci_id: DPCI unique ID
16 * @token: Returned token; use in subsequent API calls
18 * This function can be used to open a control session for an
19 * already created object; an object may have been declared in
20 * the DPL or by calling the dpci_create() function.
21 * This function returns a unique authentication token,
22 * associated with the specific object ID and the specific MC
23 * portal; this token must be used in all subsequent commands for
24 * this specific object.
26 * Return: '0' on Success; Error code otherwise.
28 int dpci_open(struct fsl_mc_io
*mc_io
,
33 struct dpci_cmd_open
*cmd_params
;
34 struct mc_command cmd
= { 0 };
38 cmd
.header
= mc_encode_cmd_header(DPCI_CMDID_OPEN
,
41 cmd_params
= (struct dpci_cmd_open
*)cmd
.params
;
42 cmd_params
->dpci_id
= cpu_to_le32(dpci_id
);
44 /* send command to mc*/
45 err
= mc_send_command(mc_io
, &cmd
);
49 /* retrieve response parameters */
50 *token
= mc_cmd_hdr_read_token(&cmd
);
56 * dpci_close() - Close the control session of the object
57 * @mc_io: Pointer to MC portal's I/O object
58 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
59 * @token: Token of DPCI object
61 * After this function is called, no further operations are
62 * allowed on the object without opening a new control session.
64 * Return: '0' on Success; Error code otherwise.
66 int dpci_close(struct fsl_mc_io
*mc_io
,
70 struct mc_command cmd
= { 0 };
73 cmd
.header
= mc_encode_cmd_header(DPCI_CMDID_CLOSE
,
77 /* send command to mc*/
78 return mc_send_command(mc_io
, &cmd
);
82 * dpci_create() - Create the DPCI object.
83 * @mc_io: Pointer to MC portal's I/O object
84 * @dprc_token: Parent container token; '0' for default container
85 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
86 * @cfg: Configuration structure
87 * @obj_id: Returned object id
89 * Create the DPCI object, allocate required resources and perform required
92 * The object can be created either by declaring it in the
93 * DPL file, or by calling this function.
95 * The function accepts an authentication token of a parent
96 * container that this object should be assigned to. The token
97 * can be '0' so the object will be assigned to the default container.
98 * The newly created object can be opened with the returned
99 * object id and using the container's associated tokens and MC portals.
101 * Return: '0' on Success; Error code otherwise.
103 int dpci_create(struct fsl_mc_io
*mc_io
,
106 const struct dpci_cfg
*cfg
,
109 struct dpci_cmd_create
*cmd_params
;
110 struct mc_command cmd
= { 0 };
113 /* prepare command */
114 cmd
.header
= mc_encode_cmd_header(DPCI_CMDID_CREATE
,
117 cmd_params
= (struct dpci_cmd_create
*)cmd
.params
;
118 cmd_params
->num_of_priorities
= cfg
->num_of_priorities
;
120 /* send command to mc*/
121 err
= mc_send_command(mc_io
, &cmd
);
125 /* retrieve response parameters */
126 *obj_id
= mc_cmd_read_object_id(&cmd
);
132 * dpci_destroy() - Destroy the DPCI object and release all its resources.
133 * @mc_io: Pointer to MC portal's I/O object
134 * @dprc_token: Parent container token; '0' for default container
135 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
136 * @object_id: The object id; it must be a valid id within the container that
137 * created this object;
139 * The function accepts the authentication token of the parent container that
140 * created the object (not the one that currently owns the object). The object
141 * is searched within parent using the provided 'object_id'.
142 * All tokens to the object must be closed before calling destroy.
144 * Return: '0' on Success; error code otherwise.
146 int dpci_destroy(struct fsl_mc_io
*mc_io
,
151 struct dpci_cmd_destroy
*cmd_params
;
152 struct mc_command cmd
= { 0 };
154 /* prepare command */
155 cmd
.header
= mc_encode_cmd_header(DPCI_CMDID_DESTROY
,
158 cmd_params
= (struct dpci_cmd_destroy
*)cmd
.params
;
159 cmd_params
->dpci_id
= cpu_to_le32(object_id
);
161 /* send command to mc*/
162 return mc_send_command(mc_io
, &cmd
);
166 * dpci_enable() - Enable the DPCI, allow sending and receiving frames.
167 * @mc_io: Pointer to MC portal's I/O object
168 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
169 * @token: Token of DPCI object
171 * Return: '0' on Success; Error code otherwise.
173 int dpci_enable(struct fsl_mc_io
*mc_io
,
177 struct mc_command cmd
= { 0 };
179 /* prepare command */
180 cmd
.header
= mc_encode_cmd_header(DPCI_CMDID_ENABLE
,
184 /* send command to mc*/
185 return mc_send_command(mc_io
, &cmd
);
189 * dpci_disable() - Disable the DPCI, stop sending and receiving frames.
190 * @mc_io: Pointer to MC portal's I/O object
191 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
192 * @token: Token of DPCI object
194 * Return: '0' on Success; Error code otherwise.
196 int dpci_disable(struct fsl_mc_io
*mc_io
,
200 struct mc_command cmd
= { 0 };
202 /* prepare command */
203 cmd
.header
= mc_encode_cmd_header(DPCI_CMDID_DISABLE
,
207 /* send command to mc*/
208 return mc_send_command(mc_io
, &cmd
);
212 * dpci_is_enabled() - Check if the DPCI is enabled.
213 * @mc_io: Pointer to MC portal's I/O object
214 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
215 * @token: Token of DPCI object
216 * @en: Returns '1' if object is enabled; '0' otherwise
218 * Return: '0' on Success; Error code otherwise.
220 int dpci_is_enabled(struct fsl_mc_io
*mc_io
,
225 struct dpci_rsp_is_enabled
*rsp_params
;
226 struct mc_command cmd
= { 0 };
229 /* prepare command */
230 cmd
.header
= mc_encode_cmd_header(DPCI_CMDID_IS_ENABLED
, cmd_flags
,
233 /* send command to mc*/
234 err
= mc_send_command(mc_io
, &cmd
);
238 /* retrieve response parameters */
239 rsp_params
= (struct dpci_rsp_is_enabled
*)cmd
.params
;
240 *en
= dpci_get_field(rsp_params
->en
, ENABLE
);
246 * dpci_reset() - Reset the DPCI, returns the object to initial state.
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 DPCI object
251 * Return: '0' on Success; Error code otherwise.
253 int dpci_reset(struct fsl_mc_io
*mc_io
,
257 struct mc_command cmd
= { 0 };
259 /* prepare command */
260 cmd
.header
= mc_encode_cmd_header(DPCI_CMDID_RESET
,
264 /* send command to mc*/
265 return mc_send_command(mc_io
, &cmd
);
269 * dpci_get_attributes() - Retrieve DPCI attributes.
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 DPCI object
273 * @attr: Returned object's attributes
275 * Return: '0' on Success; Error code otherwise.
277 int dpci_get_attributes(struct fsl_mc_io
*mc_io
,
280 struct dpci_attr
*attr
)
282 struct dpci_rsp_get_attr
*rsp_params
;
283 struct mc_command cmd
= { 0 };
286 /* prepare command */
287 cmd
.header
= mc_encode_cmd_header(DPCI_CMDID_GET_ATTR
,
291 /* send command to mc*/
292 err
= mc_send_command(mc_io
, &cmd
);
296 /* retrieve response parameters */
297 rsp_params
= (struct dpci_rsp_get_attr
*)cmd
.params
;
298 attr
->id
= le32_to_cpu(rsp_params
->id
);
299 attr
->num_of_priorities
= rsp_params
->num_of_priorities
;
305 * dpci_set_rx_queue() - Set Rx queue configuration
306 * @mc_io: Pointer to MC portal's I/O object
307 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
308 * @token: Token of DPCI object
309 * @priority: Select the queue relative to number of
310 * priorities configured at DPCI creation; use
311 * DPCI_ALL_QUEUES to configure all Rx queues
313 * @cfg: Rx queue configuration
315 * Return: '0' on Success; Error code otherwise.
317 int dpci_set_rx_queue(struct fsl_mc_io
*mc_io
,
321 const struct dpci_rx_queue_cfg
*cfg
)
323 struct dpci_cmd_set_rx_queue
*cmd_params
;
324 struct mc_command cmd
= { 0 };
326 /* prepare command */
327 cmd
.header
= mc_encode_cmd_header(DPCI_CMDID_SET_RX_QUEUE
,
330 cmd_params
= (struct dpci_cmd_set_rx_queue
*)cmd
.params
;
331 cmd_params
->dest_id
= cpu_to_le32(cfg
->dest_cfg
.dest_id
);
332 cmd_params
->dest_priority
= cfg
->dest_cfg
.priority
;
333 cmd_params
->priority
= priority
;
334 cmd_params
->user_ctx
= cpu_to_le64(cfg
->user_ctx
);
335 cmd_params
->options
= cpu_to_le32(cfg
->options
);
336 dpci_set_field(cmd_params
->dest_type
,
338 cfg
->dest_cfg
.dest_type
);
339 dpci_set_field(cmd_params
->dest_type
,
341 cfg
->order_preservation_en
);
343 /* send command to mc*/
344 return mc_send_command(mc_io
, &cmd
);
348 * dpci_get_rx_queue() - Retrieve Rx queue attributes.
349 * @mc_io: Pointer to MC portal's I/O object
350 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
351 * @token: Token of DPCI object
352 * @priority: Select the queue relative to number of
353 * priorities configured at DPCI creation
354 * @attr: Returned Rx queue attributes
356 * Return: '0' on Success; Error code otherwise.
358 int dpci_get_rx_queue(struct fsl_mc_io
*mc_io
,
362 struct dpci_rx_queue_attr
*attr
)
364 struct dpci_cmd_get_queue
*cmd_params
;
365 struct dpci_rsp_get_rx_queue
*rsp_params
;
366 struct mc_command cmd
= { 0 };
369 /* prepare command */
370 cmd
.header
= mc_encode_cmd_header(DPCI_CMDID_GET_RX_QUEUE
,
373 cmd_params
= (struct dpci_cmd_get_queue
*)cmd
.params
;
374 cmd_params
->priority
= priority
;
376 /* send command to mc*/
377 err
= mc_send_command(mc_io
, &cmd
);
381 /* retrieve response parameters */
382 rsp_params
= (struct dpci_rsp_get_rx_queue
*)cmd
.params
;
383 attr
->user_ctx
= le64_to_cpu(rsp_params
->user_ctx
);
384 attr
->fqid
= le32_to_cpu(rsp_params
->fqid
);
385 attr
->dest_cfg
.dest_id
= le32_to_cpu(rsp_params
->dest_id
);
386 attr
->dest_cfg
.priority
= rsp_params
->dest_priority
;
387 attr
->dest_cfg
.dest_type
= dpci_get_field(rsp_params
->dest_type
,
394 * dpci_get_tx_queue() - Retrieve Tx queue attributes.
395 * @mc_io: Pointer to MC portal's I/O object
396 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
397 * @token: Token of DPCI object
398 * @priority: Select the queue relative to number of
399 * priorities of the peer DPCI object
400 * @attr: Returned Tx queue attributes
402 * Return: '0' on Success; Error code otherwise.
404 int dpci_get_tx_queue(struct fsl_mc_io
*mc_io
,
408 struct dpci_tx_queue_attr
*attr
)
410 struct dpci_cmd_get_queue
*cmd_params
;
411 struct dpci_rsp_get_tx_queue
*rsp_params
;
412 struct mc_command cmd
= { 0 };
415 /* prepare command */
416 cmd
.header
= mc_encode_cmd_header(DPCI_CMDID_GET_TX_QUEUE
,
419 cmd_params
= (struct dpci_cmd_get_queue
*)cmd
.params
;
420 cmd_params
->priority
= priority
;
422 /* send command to mc*/
423 err
= mc_send_command(mc_io
, &cmd
);
427 /* retrieve response parameters */
428 rsp_params
= (struct dpci_rsp_get_tx_queue
*)cmd
.params
;
429 attr
->fqid
= le32_to_cpu(rsp_params
->fqid
);
435 * dpci_get_api_version() - Get communication interface API version
436 * @mc_io: Pointer to MC portal's I/O object
437 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
438 * @major_ver: Major version of data path communication interface API
439 * @minor_ver: Minor version of data path communication interface API
441 * Return: '0' on Success; Error code otherwise.
443 int dpci_get_api_version(struct fsl_mc_io
*mc_io
,
448 struct dpci_rsp_get_api_version
*rsp_params
;
449 struct mc_command cmd
= { 0 };
452 cmd
.header
= mc_encode_cmd_header(DPCI_CMDID_GET_API_VERSION
,
456 err
= mc_send_command(mc_io
, &cmd
);
460 rsp_params
= (struct dpci_rsp_get_api_version
*)cmd
.params
;
461 *major_ver
= le16_to_cpu(rsp_params
->major
);
462 *minor_ver
= le16_to_cpu(rsp_params
->minor
);
468 * dpci_set_opr() - Set Order Restoration configuration.
469 * @mc_io: Pointer to MC portal's I/O object
470 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
471 * @token: Token of DPCI object
472 * @index: The queue index
473 * @options: Configuration mode options
474 * can be OPR_OPT_CREATE or OPR_OPT_RETIRE
475 * @cfg: Configuration options for the OPR
477 * Return: '0' on Success; Error code otherwise.
479 int dpci_set_opr(struct fsl_mc_io
*mc_io
,
486 struct dpci_cmd_set_opr
*cmd_params
;
487 struct mc_command cmd
= { 0 };
489 /* prepare command */
490 cmd
.header
= mc_encode_cmd_header(DPCI_CMDID_SET_OPR
,
493 cmd_params
= (struct dpci_cmd_set_opr
*)cmd
.params
;
494 cmd_params
->index
= index
;
495 cmd_params
->options
= options
;
496 cmd_params
->oloe
= cfg
->oloe
;
497 cmd_params
->oeane
= cfg
->oeane
;
498 cmd_params
->olws
= cfg
->olws
;
499 cmd_params
->oa
= cfg
->oa
;
500 cmd_params
->oprrws
= cfg
->oprrws
;
502 /* send command to mc*/
503 return mc_send_command(mc_io
, &cmd
);
507 * dpci_get_opr() - Retrieve Order Restoration config and query.
508 * @mc_io: Pointer to MC portal's I/O object
509 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
510 * @token: Token of DPCI object
511 * @index: The queue index
512 * @cfg: Returned OPR configuration
513 * @qry: Returned OPR query
515 * Return: '0' on Success; Error code otherwise.
517 int dpci_get_opr(struct fsl_mc_io
*mc_io
,
524 struct dpci_rsp_get_opr
*rsp_params
;
525 struct dpci_cmd_get_opr
*cmd_params
;
526 struct mc_command cmd
= { 0 };
529 /* prepare command */
530 cmd
.header
= mc_encode_cmd_header(DPCI_CMDID_GET_OPR
,
533 cmd_params
= (struct dpci_cmd_get_opr
*)cmd
.params
;
534 cmd_params
->index
= index
;
536 /* send command to mc*/
537 err
= mc_send_command(mc_io
, &cmd
);
541 /* retrieve response parameters */
542 rsp_params
= (struct dpci_rsp_get_opr
*)cmd
.params
;
543 cfg
->oloe
= rsp_params
->oloe
;
544 cfg
->oeane
= rsp_params
->oeane
;
545 cfg
->olws
= rsp_params
->olws
;
546 cfg
->oa
= rsp_params
->oa
;
547 cfg
->oprrws
= rsp_params
->oprrws
;
548 qry
->rip
= dpci_get_field(rsp_params
->flags
, RIP
);
549 qry
->enable
= dpci_get_field(rsp_params
->flags
, OPR_ENABLE
);
550 qry
->nesn
= le16_to_cpu(rsp_params
->nesn
);
551 qry
->ndsn
= le16_to_cpu(rsp_params
->ndsn
);
552 qry
->ea_tseq
= le16_to_cpu(rsp_params
->ea_tseq
);
553 qry
->tseq_nlis
= dpci_get_field(rsp_params
->tseq_nlis
, TSEQ_NLIS
);
554 qry
->ea_hseq
= le16_to_cpu(rsp_params
->ea_hseq
);
555 qry
->hseq_nlis
= dpci_get_field(rsp_params
->hseq_nlis
, HSEQ_NLIS
);
556 qry
->ea_hptr
= le16_to_cpu(rsp_params
->ea_hptr
);
557 qry
->ea_tptr
= le16_to_cpu(rsp_params
->ea_tptr
);
558 qry
->opr_vid
= le16_to_cpu(rsp_params
->opr_vid
);
559 qry
->opr_id
= le16_to_cpu(rsp_params
->opr_id
);