1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
4 * Copyright 2017-2019 NXP
7 #include <fsl_mc_sys.h>
8 #include <fsl_mc_cmd.h>
10 #include <fsl_dpci_cmd.h>
13 * dpci_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 * @dpci_id: DPCI unique ID
17 * @token: Returned token; use in subsequent API calls
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 dpci_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.
27 * Return: '0' on Success; Error code otherwise.
29 int dpci_open(struct fsl_mc_io *mc_io,
34 struct dpci_cmd_open *cmd_params;
35 struct mc_command cmd = { 0 };
39 cmd.header = mc_encode_cmd_header(DPCI_CMDID_OPEN,
42 cmd_params = (struct dpci_cmd_open *)cmd.params;
43 cmd_params->dpci_id = cpu_to_le32(dpci_id);
45 /* send command to mc*/
46 err = mc_send_command(mc_io, &cmd);
50 /* retrieve response parameters */
51 *token = mc_cmd_hdr_read_token(&cmd);
57 * dpci_close() - Close the control session of the object
58 * @mc_io: Pointer to MC portal's I/O object
59 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
60 * @token: Token of DPCI object
62 * After this function is called, no further operations are
63 * allowed on the object without opening a new control session.
65 * Return: '0' on Success; Error code otherwise.
67 int dpci_close(struct fsl_mc_io *mc_io,
71 struct mc_command cmd = { 0 };
74 cmd.header = mc_encode_cmd_header(DPCI_CMDID_CLOSE,
78 /* send command to mc*/
79 return mc_send_command(mc_io, &cmd);
83 * dpci_create() - Create the DPCI object.
84 * @mc_io: Pointer to MC portal's I/O object
85 * @dprc_token: Parent container token; '0' for default container
86 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
87 * @cfg: Configuration structure
88 * @obj_id: Returned object id
90 * Create the DPCI object, allocate required resources and perform required
93 * The object can be created either by declaring it in the
94 * DPL file, or by calling this function.
96 * The function accepts an authentication token of a parent
97 * container that this object should be assigned to. The token
98 * can be '0' so the object will be assigned to the default container.
99 * The newly created object can be opened with the returned
100 * object id and using the container's associated tokens and MC portals.
102 * Return: '0' on Success; Error code otherwise.
104 int dpci_create(struct fsl_mc_io *mc_io,
107 const struct dpci_cfg *cfg,
110 struct dpci_cmd_create *cmd_params;
111 struct mc_command cmd = { 0 };
114 /* prepare command */
115 cmd.header = mc_encode_cmd_header(DPCI_CMDID_CREATE,
118 cmd_params = (struct dpci_cmd_create *)cmd.params;
119 cmd_params->num_of_priorities = cfg->num_of_priorities;
121 /* send command to mc*/
122 err = mc_send_command(mc_io, &cmd);
126 /* retrieve response parameters */
127 *obj_id = mc_cmd_read_object_id(&cmd);
133 * dpci_destroy() - Destroy the DPCI object and release all its resources.
134 * @mc_io: Pointer to MC portal's I/O object
135 * @dprc_token: Parent container token; '0' for default container
136 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
137 * @object_id: The object id; it must be a valid id within the container that
138 * created this object;
140 * The function accepts the authentication token of the parent container that
141 * created the object (not the one that currently owns the object). The object
142 * is searched within parent using the provided 'object_id'.
143 * All tokens to the object must be closed before calling destroy.
145 * Return: '0' on Success; error code otherwise.
147 int dpci_destroy(struct fsl_mc_io *mc_io,
152 struct dpci_cmd_destroy *cmd_params;
153 struct mc_command cmd = { 0 };
155 /* prepare command */
156 cmd.header = mc_encode_cmd_header(DPCI_CMDID_DESTROY,
159 cmd_params = (struct dpci_cmd_destroy *)cmd.params;
160 cmd_params->dpci_id = cpu_to_le32(object_id);
162 /* send command to mc*/
163 return mc_send_command(mc_io, &cmd);
167 * dpci_enable() - Enable the DPCI, allow sending and receiving frames.
168 * @mc_io: Pointer to MC portal's I/O object
169 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
170 * @token: Token of DPCI object
172 * Return: '0' on Success; Error code otherwise.
174 int dpci_enable(struct fsl_mc_io *mc_io,
178 struct mc_command cmd = { 0 };
180 /* prepare command */
181 cmd.header = mc_encode_cmd_header(DPCI_CMDID_ENABLE,
185 /* send command to mc*/
186 return mc_send_command(mc_io, &cmd);
190 * dpci_disable() - Disable the DPCI, stop sending and receiving frames.
191 * @mc_io: Pointer to MC portal's I/O object
192 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
193 * @token: Token of DPCI object
195 * Return: '0' on Success; Error code otherwise.
197 int dpci_disable(struct fsl_mc_io *mc_io,
201 struct mc_command cmd = { 0 };
203 /* prepare command */
204 cmd.header = mc_encode_cmd_header(DPCI_CMDID_DISABLE,
208 /* send command to mc*/
209 return mc_send_command(mc_io, &cmd);
213 * dpci_is_enabled() - Check if the DPCI is enabled.
214 * @mc_io: Pointer to MC portal's I/O object
215 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
216 * @token: Token of DPCI object
217 * @en: Returns '1' if object is enabled; '0' otherwise
219 * Return: '0' on Success; Error code otherwise.
221 int dpci_is_enabled(struct fsl_mc_io *mc_io,
226 struct dpci_rsp_is_enabled *rsp_params;
227 struct mc_command cmd = { 0 };
230 /* prepare command */
231 cmd.header = mc_encode_cmd_header(DPCI_CMDID_IS_ENABLED, cmd_flags,
234 /* send command to mc*/
235 err = mc_send_command(mc_io, &cmd);
239 /* retrieve response parameters */
240 rsp_params = (struct dpci_rsp_is_enabled *)cmd.params;
241 *en = dpci_get_field(rsp_params->en, ENABLE);
247 * dpci_reset() - Reset the DPCI, returns the object to initial state.
248 * @mc_io: Pointer to MC portal's I/O object
249 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
250 * @token: Token of DPCI object
252 * Return: '0' on Success; Error code otherwise.
254 int dpci_reset(struct fsl_mc_io *mc_io,
258 struct mc_command cmd = { 0 };
260 /* prepare command */
261 cmd.header = mc_encode_cmd_header(DPCI_CMDID_RESET,
265 /* send command to mc*/
266 return mc_send_command(mc_io, &cmd);
270 * dpci_get_attributes() - Retrieve DPCI attributes.
271 * @mc_io: Pointer to MC portal's I/O object
272 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
273 * @token: Token of DPCI object
274 * @attr: Returned object's attributes
276 * Return: '0' on Success; Error code otherwise.
278 int dpci_get_attributes(struct fsl_mc_io *mc_io,
281 struct dpci_attr *attr)
283 struct dpci_rsp_get_attr *rsp_params;
284 struct mc_command cmd = { 0 };
287 /* prepare command */
288 cmd.header = mc_encode_cmd_header(DPCI_CMDID_GET_ATTR,
292 /* send command to mc*/
293 err = mc_send_command(mc_io, &cmd);
297 /* retrieve response parameters */
298 rsp_params = (struct dpci_rsp_get_attr *)cmd.params;
299 attr->id = le32_to_cpu(rsp_params->id);
300 attr->num_of_priorities = rsp_params->num_of_priorities;
306 * dpci_set_rx_queue() - Set Rx queue configuration
307 * @mc_io: Pointer to MC portal's I/O object
308 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
309 * @token: Token of DPCI object
310 * @priority: Select the queue relative to number of
311 * priorities configured at DPCI creation; use
312 * DPCI_ALL_QUEUES to configure all Rx queues
314 * @cfg: Rx queue configuration
316 * Return: '0' on Success; Error code otherwise.
318 int dpci_set_rx_queue(struct fsl_mc_io *mc_io,
322 const struct dpci_rx_queue_cfg *cfg)
324 struct dpci_cmd_set_rx_queue *cmd_params;
325 struct mc_command cmd = { 0 };
327 /* prepare command */
328 cmd.header = mc_encode_cmd_header(DPCI_CMDID_SET_RX_QUEUE,
331 cmd_params = (struct dpci_cmd_set_rx_queue *)cmd.params;
332 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
333 cmd_params->dest_priority = cfg->dest_cfg.priority;
334 cmd_params->priority = priority;
335 cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
336 cmd_params->options = cpu_to_le32(cfg->options);
337 dpci_set_field(cmd_params->dest_type,
339 cfg->dest_cfg.dest_type);
340 dpci_set_field(cmd_params->dest_type,
342 cfg->order_preservation_en);
344 /* send command to mc*/
345 return mc_send_command(mc_io, &cmd);
349 * dpci_get_rx_queue() - Retrieve Rx queue attributes.
350 * @mc_io: Pointer to MC portal's I/O object
351 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
352 * @token: Token of DPCI object
353 * @priority: Select the queue relative to number of
354 * priorities configured at DPCI creation
355 * @attr: Returned Rx queue attributes
357 * Return: '0' on Success; Error code otherwise.
359 int dpci_get_rx_queue(struct fsl_mc_io *mc_io,
363 struct dpci_rx_queue_attr *attr)
365 struct dpci_cmd_get_queue *cmd_params;
366 struct dpci_rsp_get_rx_queue *rsp_params;
367 struct mc_command cmd = { 0 };
370 /* prepare command */
371 cmd.header = mc_encode_cmd_header(DPCI_CMDID_GET_RX_QUEUE,
374 cmd_params = (struct dpci_cmd_get_queue *)cmd.params;
375 cmd_params->priority = priority;
377 /* send command to mc*/
378 err = mc_send_command(mc_io, &cmd);
382 /* retrieve response parameters */
383 rsp_params = (struct dpci_rsp_get_rx_queue *)cmd.params;
384 attr->user_ctx = le64_to_cpu(rsp_params->user_ctx);
385 attr->fqid = le32_to_cpu(rsp_params->fqid);
386 attr->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
387 attr->dest_cfg.priority = rsp_params->dest_priority;
388 attr->dest_cfg.dest_type = dpci_get_field(rsp_params->dest_type,
395 * dpci_get_tx_queue() - Retrieve Tx queue attributes.
396 * @mc_io: Pointer to MC portal's I/O object
397 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
398 * @token: Token of DPCI object
399 * @priority: Select the queue relative to number of
400 * priorities of the peer DPCI object
401 * @attr: Returned Tx queue attributes
403 * Return: '0' on Success; Error code otherwise.
405 int dpci_get_tx_queue(struct fsl_mc_io *mc_io,
409 struct dpci_tx_queue_attr *attr)
411 struct dpci_cmd_get_queue *cmd_params;
412 struct dpci_rsp_get_tx_queue *rsp_params;
413 struct mc_command cmd = { 0 };
416 /* prepare command */
417 cmd.header = mc_encode_cmd_header(DPCI_CMDID_GET_TX_QUEUE,
420 cmd_params = (struct dpci_cmd_get_queue *)cmd.params;
421 cmd_params->priority = priority;
423 /* send command to mc*/
424 err = mc_send_command(mc_io, &cmd);
428 /* retrieve response parameters */
429 rsp_params = (struct dpci_rsp_get_tx_queue *)cmd.params;
430 attr->fqid = le32_to_cpu(rsp_params->fqid);
436 * dpci_get_api_version() - Get communication interface API version
437 * @mc_io: Pointer to MC portal's I/O object
438 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
439 * @major_ver: Major version of data path communication interface API
440 * @minor_ver: Minor version of data path communication interface API
442 * Return: '0' on Success; Error code otherwise.
444 int dpci_get_api_version(struct fsl_mc_io *mc_io,
449 struct dpci_rsp_get_api_version *rsp_params;
450 struct mc_command cmd = { 0 };
453 cmd.header = mc_encode_cmd_header(DPCI_CMDID_GET_API_VERSION,
457 err = mc_send_command(mc_io, &cmd);
461 rsp_params = (struct dpci_rsp_get_api_version *)cmd.params;
462 *major_ver = le16_to_cpu(rsp_params->major);
463 *minor_ver = le16_to_cpu(rsp_params->minor);
469 * dpci_set_opr() - Set Order Restoration configuration.
470 * @mc_io: Pointer to MC portal's I/O object
471 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
472 * @token: Token of DPCI object
473 * @index: The queue index
474 * @options: Configuration mode options
475 * can be OPR_OPT_CREATE or OPR_OPT_RETIRE
476 * @cfg: Configuration options for the OPR
478 * Return: '0' on Success; Error code otherwise.
480 int dpci_set_opr(struct fsl_mc_io *mc_io,
487 struct dpci_cmd_set_opr *cmd_params;
488 struct mc_command cmd = { 0 };
490 /* prepare command */
491 cmd.header = mc_encode_cmd_header(DPCI_CMDID_SET_OPR,
494 cmd_params = (struct dpci_cmd_set_opr *)cmd.params;
495 cmd_params->index = index;
496 cmd_params->options = options;
497 cmd_params->oloe = cfg->oloe;
498 cmd_params->oeane = cfg->oeane;
499 cmd_params->olws = cfg->olws;
500 cmd_params->oa = cfg->oa;
501 cmd_params->oprrws = cfg->oprrws;
503 /* send command to mc*/
504 return mc_send_command(mc_io, &cmd);
508 * dpci_get_opr() - Retrieve Order Restoration config and query.
509 * @mc_io: Pointer to MC portal's I/O object
510 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
511 * @token: Token of DPCI object
512 * @index: The queue index
513 * @cfg: Returned OPR configuration
514 * @qry: Returned OPR query
516 * Return: '0' on Success; Error code otherwise.
518 int dpci_get_opr(struct fsl_mc_io *mc_io,
525 struct dpci_rsp_get_opr *rsp_params;
526 struct dpci_cmd_get_opr *cmd_params;
527 struct mc_command cmd = { 0 };
530 /* prepare command */
531 cmd.header = mc_encode_cmd_header(DPCI_CMDID_GET_OPR,
534 cmd_params = (struct dpci_cmd_get_opr *)cmd.params;
535 cmd_params->index = index;
537 /* send command to mc*/
538 err = mc_send_command(mc_io, &cmd);
542 /* retrieve response parameters */
543 rsp_params = (struct dpci_rsp_get_opr *)cmd.params;
544 cfg->oloe = rsp_params->oloe;
545 cfg->oeane = rsp_params->oeane;
546 cfg->olws = rsp_params->olws;
547 cfg->oa = rsp_params->oa;
548 cfg->oprrws = rsp_params->oprrws;
549 qry->rip = dpci_get_field(rsp_params->flags, RIP);
550 qry->enable = dpci_get_field(rsp_params->flags, OPR_ENABLE);
551 qry->nesn = le16_to_cpu(rsp_params->nesn);
552 qry->ndsn = le16_to_cpu(rsp_params->ndsn);
553 qry->ea_tseq = le16_to_cpu(rsp_params->ea_tseq);
554 qry->tseq_nlis = dpci_get_field(rsp_params->tseq_nlis, TSEQ_NLIS);
555 qry->ea_hseq = le16_to_cpu(rsp_params->ea_hseq);
556 qry->hseq_nlis = dpci_get_field(rsp_params->hseq_nlis, HSEQ_NLIS);
557 qry->ea_hptr = le16_to_cpu(rsp_params->ea_hptr);
558 qry->ea_tptr = le16_to_cpu(rsp_params->ea_tptr);
559 qry->opr_vid = le16_to_cpu(rsp_params->opr_vid);
560 qry->opr_id = le16_to_cpu(rsp_params->opr_id);