2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright 2013-2016 Freescale Semiconductor Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * * Neither the name of the above-listed copyright holders nor the
18 * names of any contributors may be used to endorse or promote products
19 * derived from this software without specific prior written permission.
23 * ALTERNATIVELY, this software may be distributed under the terms of the
24 * GNU General Public License ("GPL") as published by the Free Software
25 * Foundation, either version 2 of that License or (at your option) any
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
32 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
40 #include <fsl_mc_sys.h>
41 #include <fsl_mc_cmd.h>
42 #include <fsl_dpseci.h>
43 #include <fsl_dpseci_cmd.h>
46 * dpseci_open() - Open a control session for the specified object
47 * @mc_io: Pointer to MC portal's I/O object
48 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
49 * @dpseci_id: DPSECI unique ID
50 * @token: Returned token; use in subsequent API calls
52 * This function can be used to open a control session for an
53 * already created object; an object may have been declared in
54 * the DPL or by calling the dpseci_create() function.
55 * This function returns a unique authentication token,
56 * associated with the specific object ID and the specific MC
57 * portal; this token must be used in all subsequent commands for
58 * this specific object.
60 * Return: '0' on Success; Error code otherwise.
62 int dpseci_open(struct fsl_mc_io *mc_io,
67 struct dpseci_cmd_open *cmd_params;
68 struct mc_command cmd = { 0 };
72 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_OPEN,
75 cmd_params = (struct dpseci_cmd_open *)cmd.params;
76 cmd_params->dpseci_id = cpu_to_le32(dpseci_id);
78 /* send command to mc*/
79 err = mc_send_command(mc_io, &cmd);
83 /* retrieve response parameters */
84 *token = mc_cmd_hdr_read_token(&cmd);
90 * dpseci_close() - Close the control session of the object
91 * @mc_io: Pointer to MC portal's I/O object
92 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
93 * @token: Token of DPSECI object
95 * After this function is called, no further operations are
96 * allowed on the object without opening a new control session.
98 * Return: '0' on Success; Error code otherwise.
100 int dpseci_close(struct fsl_mc_io *mc_io,
104 struct mc_command cmd = { 0 };
106 /* prepare command */
107 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CLOSE,
111 /* send command to mc*/
112 return mc_send_command(mc_io, &cmd);
116 * dpseci_create() - Create the DPSECI object
117 * @mc_io: Pointer to MC portal's I/O object
118 * @dprc_token: Parent container token; '0' for default container
119 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
120 * @cfg: Configuration structure
121 * @obj_id: Returned object id
123 * Create the DPSECI object, allocate required resources and
124 * perform required initialization.
126 * The object can be created either by declaring it in the
127 * DPL file, or by calling this function.
129 * The function accepts an authentication token of a parent
130 * container that this object should be assigned to. The token
131 * can be '0' so the object will be assigned to the default container.
132 * The newly created object can be opened with the returned
133 * object id and using the container's associated tokens and MC portals.
135 * Return: '0' on Success; Error code otherwise.
137 int dpseci_create(struct fsl_mc_io *mc_io,
140 const struct dpseci_cfg *cfg,
143 struct dpseci_cmd_create *cmd_params;
144 struct mc_command cmd = { 0 };
147 /* prepare command */
148 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CREATE,
151 cmd_params = (struct dpseci_cmd_create *)cmd.params;
152 for (i = 0; i < DPSECI_PRIO_NUM; i++)
153 cmd_params->priorities[i] = cfg->priorities[i];
154 cmd_params->num_tx_queues = cfg->num_tx_queues;
155 cmd_params->num_rx_queues = cfg->num_rx_queues;
156 cmd_params->options = cfg->options;
158 /* send command to mc*/
159 err = mc_send_command(mc_io, &cmd);
163 /* retrieve response parameters */
164 *obj_id = mc_cmd_read_object_id(&cmd);
170 * dpseci_destroy() - Destroy the DPSECI object and release all its resources.
171 * @mc_io: Pointer to MC portal's I/O object
172 * @dprc_token: Parent container token; '0' for default container
173 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
174 * @object_id: The object id; it must be a valid id within the container that
175 * created this object;
177 * The function accepts the authentication token of the parent container that
178 * created the object (not the one that currently owns the object). The object
179 * is searched within parent using the provided 'object_id'.
180 * All tokens to the object must be closed before calling destroy.
182 * Return: '0' on Success; error code otherwise.
184 int dpseci_destroy(struct fsl_mc_io *mc_io,
189 struct dpseci_cmd_destroy *cmd_params;
190 struct mc_command cmd = { 0 };
192 /* prepare command */
193 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_DESTROY,
196 cmd_params = (struct dpseci_cmd_destroy *)cmd.params;
197 cmd_params->dpseci_id = cpu_to_le32(object_id);
199 /* send command to mc*/
200 return mc_send_command(mc_io, &cmd);
204 * dpseci_enable() - Enable the DPSECI, allow sending and receiving frames.
205 * @mc_io: Pointer to MC portal's I/O object
206 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
207 * @token: Token of DPSECI object
209 * Return: '0' on Success; Error code otherwise.
211 int dpseci_enable(struct fsl_mc_io *mc_io,
215 struct mc_command cmd = { 0 };
217 /* prepare command */
218 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_ENABLE,
222 /* send command to mc*/
223 return mc_send_command(mc_io, &cmd);
227 * dpseci_disable() - Disable the DPSECI, stop sending and receiving frames.
228 * @mc_io: Pointer to MC portal's I/O object
229 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
230 * @token: Token of DPSECI object
232 * Return: '0' on Success; Error code otherwise.
234 int dpseci_disable(struct fsl_mc_io *mc_io,
238 struct mc_command cmd = { 0 };
240 /* prepare command */
241 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_DISABLE,
245 /* send command to mc*/
246 return mc_send_command(mc_io, &cmd);
250 * dpseci_is_enabled() - Check if the DPSECI is enabled.
251 * @mc_io: Pointer to MC portal's I/O object
252 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
253 * @token: Token of DPSECI object
254 * @en: Returns '1' if object is enabled; '0' otherwise
256 * Return: '0' on Success; Error code otherwise.
258 int dpseci_is_enabled(struct fsl_mc_io *mc_io,
263 struct dpseci_rsp_is_enabled *rsp_params;
264 struct mc_command cmd = { 0 };
267 /* prepare command */
268 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_IS_ENABLED,
272 /* send command to mc*/
273 err = mc_send_command(mc_io, &cmd);
277 /* retrieve response parameters */
278 rsp_params = (struct dpseci_rsp_is_enabled *)cmd.params;
279 *en = dpseci_get_field(rsp_params->en, ENABLE);
285 * dpseci_reset() - Reset the DPSECI, returns the object to initial state.
286 * @mc_io: Pointer to MC portal's I/O object
287 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
288 * @token: Token of DPSECI object
290 * Return: '0' on Success; Error code otherwise.
292 int dpseci_reset(struct fsl_mc_io *mc_io,
296 struct mc_command cmd = { 0 };
298 /* prepare command */
299 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_RESET,
303 /* send command to mc*/
304 return mc_send_command(mc_io, &cmd);
308 * dpseci_get_attributes() - Retrieve DPSECI attributes.
309 * @mc_io: Pointer to MC portal's I/O object
310 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
311 * @token: Token of DPSECI object
312 * @attr: Returned object's attributes
314 * Return: '0' on Success; Error code otherwise.
316 int dpseci_get_attributes(struct fsl_mc_io *mc_io,
319 struct dpseci_attr *attr)
321 struct dpseci_rsp_get_attr *rsp_params;
322 struct mc_command cmd = { 0 };
325 /* prepare command */
326 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_ATTR,
330 /* send command to mc*/
331 err = mc_send_command(mc_io, &cmd);
335 /* retrieve response parameters */
336 rsp_params = (struct dpseci_rsp_get_attr *)cmd.params;
337 attr->id = le32_to_cpu(rsp_params->id);
338 attr->options = rsp_params->options;
339 attr->num_tx_queues = rsp_params->num_tx_queues;
340 attr->num_rx_queues = rsp_params->num_rx_queues;
346 * dpseci_set_rx_queue() - Set Rx queue configuration
347 * @mc_io: Pointer to MC portal's I/O object
348 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
349 * @token: Token of DPSECI object
350 * @queue: Select the queue relative to number of
351 * priorities configured at DPSECI creation; use
352 * DPSECI_ALL_QUEUES to configure all Rx queues identically.
353 * @cfg: Rx queue configuration
355 * Return: '0' on Success; Error code otherwise.
357 int dpseci_set_rx_queue(struct fsl_mc_io *mc_io,
361 const struct dpseci_rx_queue_cfg *cfg)
363 struct dpseci_cmd_set_rx_queue *cmd_params;
364 struct mc_command cmd = { 0 };
366 /* prepare command */
367 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_RX_QUEUE,
370 cmd_params = (struct dpseci_cmd_set_rx_queue *)cmd.params;
371 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
372 cmd_params->dest_priority = cfg->dest_cfg.priority;
373 cmd_params->queue = queue;
374 cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
375 cmd_params->options = cpu_to_le32(cfg->options);
376 dpseci_set_field(cmd_params->dest_type,
378 cfg->dest_cfg.dest_type);
379 dpseci_set_field(cmd_params->order_preservation_en,
381 cfg->order_preservation_en);
383 /* send command to mc*/
384 return mc_send_command(mc_io, &cmd);
388 * dpseci_get_rx_queue() - Retrieve Rx queue attributes.
389 * @mc_io: Pointer to MC portal's I/O object
390 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
391 * @token: Token of DPSECI object
392 * @queue: Select the queue relative to number of
393 * priorities configured at DPSECI creation
394 * @attr: Returned Rx queue attributes
396 * Return: '0' on Success; Error code otherwise.
398 int dpseci_get_rx_queue(struct fsl_mc_io *mc_io,
402 struct dpseci_rx_queue_attr *attr)
404 struct dpseci_rsp_get_rx_queue *rsp_params;
405 struct dpseci_cmd_get_queue *cmd_params;
406 struct mc_command cmd = { 0 };
409 /* prepare command */
410 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_RX_QUEUE,
413 cmd_params = (struct dpseci_cmd_get_queue *)cmd.params;
414 cmd_params->queue = queue;
416 /* send command to mc*/
417 err = mc_send_command(mc_io, &cmd);
421 /* retrieve response parameters */
422 rsp_params = (struct dpseci_rsp_get_rx_queue *)cmd.params;
423 attr->user_ctx = le64_to_cpu(rsp_params->user_ctx);
424 attr->fqid = le32_to_cpu(rsp_params->fqid);
425 attr->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
426 attr->dest_cfg.priority = rsp_params->dest_priority;
427 attr->dest_cfg.dest_type =
428 dpseci_get_field(rsp_params->dest_type,
430 attr->order_preservation_en =
431 dpseci_get_field(rsp_params->order_preservation_en,
438 * dpseci_get_tx_queue() - Retrieve Tx queue attributes.
439 * @mc_io: Pointer to MC portal's I/O object
440 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
441 * @token: Token of DPSECI object
442 * @queue: Select the queue relative to number of
443 * priorities configured at DPSECI creation
444 * @attr: Returned Tx queue attributes
446 * Return: '0' on Success; Error code otherwise.
448 int dpseci_get_tx_queue(struct fsl_mc_io *mc_io,
452 struct dpseci_tx_queue_attr *attr)
454 struct dpseci_rsp_get_tx_queue *rsp_params;
455 struct dpseci_cmd_get_queue *cmd_params;
456 struct mc_command cmd = { 0 };
459 /* prepare command */
460 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_TX_QUEUE,
463 cmd_params = (struct dpseci_cmd_get_queue *)cmd.params;
464 cmd_params->queue = queue;
466 /* send command to mc*/
467 err = mc_send_command(mc_io, &cmd);
471 /* retrieve response parameters */
472 rsp_params = (struct dpseci_rsp_get_tx_queue *)cmd.params;
473 attr->fqid = le32_to_cpu(rsp_params->fqid);
474 attr->priority = rsp_params->priority;
480 * dpseci_get_sec_attr() - Retrieve SEC accelerator attributes.
481 * @mc_io: Pointer to MC portal's I/O object
482 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
483 * @token: Token of DPSECI object
484 * @attr: Returned SEC attributes
486 * Return: '0' on Success; Error code otherwise.
488 int dpseci_get_sec_attr(struct fsl_mc_io *mc_io,
491 struct dpseci_sec_attr *attr)
493 struct dpseci_rsp_get_sec_attr *rsp_params;
494 struct mc_command cmd = { 0 };
497 /* prepare command */
498 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_SEC_ATTR,
502 /* send command to mc*/
503 err = mc_send_command(mc_io, &cmd);
507 /* retrieve response parameters */
508 rsp_params = (struct dpseci_rsp_get_sec_attr *)cmd.params;
509 attr->ip_id = le16_to_cpu(rsp_params->ip_id);
510 attr->major_rev = rsp_params->major_rev;
511 attr->minor_rev = rsp_params->minor_rev;
512 attr->era = rsp_params->era;
513 attr->deco_num = rsp_params->deco_num;
514 attr->zuc_auth_acc_num = rsp_params->zuc_auth_acc_num;
515 attr->zuc_enc_acc_num = rsp_params->zuc_enc_acc_num;
516 attr->snow_f8_acc_num = rsp_params->snow_f8_acc_num;
517 attr->snow_f9_acc_num = rsp_params->snow_f9_acc_num;
518 attr->crc_acc_num = rsp_params->crc_acc_num;
519 attr->pk_acc_num = rsp_params->pk_acc_num;
520 attr->kasumi_acc_num = rsp_params->kasumi_acc_num;
521 attr->rng_acc_num = rsp_params->rng_acc_num;
522 attr->md_acc_num = rsp_params->md_acc_num;
523 attr->arc4_acc_num = rsp_params->arc4_acc_num;
524 attr->des_acc_num = rsp_params->des_acc_num;
525 attr->aes_acc_num = rsp_params->aes_acc_num;
531 * dpseci_get_sec_counters() - Retrieve SEC accelerator counters.
532 * @mc_io: Pointer to MC portal's I/O object
533 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
534 * @token: Token of DPSECI object
535 * @counters: Returned SEC counters
537 * Return: '0' on Success; Error code otherwise.
539 int dpseci_get_sec_counters(struct fsl_mc_io *mc_io,
542 struct dpseci_sec_counters *counters)
544 struct dpseci_rsp_get_sec_counters *rsp_params;
545 struct mc_command cmd = { 0 };
548 /* prepare command */
549 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_SEC_COUNTERS,
553 /* send command to mc*/
554 err = mc_send_command(mc_io, &cmd);
558 /* retrieve response parameters */
559 rsp_params = (struct dpseci_rsp_get_sec_counters *)cmd.params;
560 counters->dequeued_requests =
561 le64_to_cpu(rsp_params->dequeued_requests);
562 counters->ob_enc_requests = le64_to_cpu(rsp_params->ob_enc_requests);
563 counters->ib_dec_requests = le64_to_cpu(rsp_params->ib_dec_requests);
564 counters->ob_enc_bytes = le64_to_cpu(rsp_params->ob_enc_bytes);
565 counters->ob_prot_bytes = le64_to_cpu(rsp_params->ob_prot_bytes);
566 counters->ib_dec_bytes = le64_to_cpu(rsp_params->ib_dec_bytes);
567 counters->ib_valid_bytes = le64_to_cpu(rsp_params->ib_valid_bytes);
573 * dpseci_get_api_version() - Get Data Path SEC Interface API version
574 * @mc_io: Pointer to MC portal's I/O object
575 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
576 * @major_ver: Major version of data path sec API
577 * @minor_ver: Minor version of data path sec API
579 * Return: '0' on Success; Error code otherwise.
581 int dpseci_get_api_version(struct fsl_mc_io *mc_io,
586 struct dpseci_rsp_get_api_version *rsp_params;
587 struct mc_command cmd = { 0 };
590 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_API_VERSION,
594 err = mc_send_command(mc_io, &cmd);
598 rsp_params = (struct dpseci_rsp_get_api_version *)cmd.params;
599 *major_ver = le16_to_cpu(rsp_params->major);
600 *minor_ver = le16_to_cpu(rsp_params->minor);
605 int dpseci_set_congestion_notification(
606 struct fsl_mc_io *mc_io,
609 const struct dpseci_congestion_notification_cfg *cfg)
611 struct dpseci_cmd_set_congestion_notification *cmd_params;
612 struct mc_command cmd = { 0 };
614 /* prepare command */
615 cmd.header = mc_encode_cmd_header(
616 DPSECI_CMDID_SET_CONGESTION_NOTIFICATION,
621 (struct dpseci_cmd_set_congestion_notification *)cmd.params;
622 cmd_params->dest_id = cfg->dest_cfg.dest_id;
623 cmd_params->dest_priority = cfg->dest_cfg.priority;
624 cmd_params->message_ctx = cfg->message_ctx;
625 cmd_params->message_iova = cfg->message_iova;
626 cmd_params->notification_mode = cfg->notification_mode;
627 cmd_params->threshold_entry = cfg->threshold_entry;
628 cmd_params->threshold_exit = cfg->threshold_exit;
629 dpseci_set_field(cmd_params->type_units,
631 cfg->dest_cfg.dest_type);
632 dpseci_set_field(cmd_params->type_units,
636 /* send command to mc*/
637 return mc_send_command(mc_io, &cmd);
640 int dpseci_get_congestion_notification(
641 struct fsl_mc_io *mc_io,
644 struct dpseci_congestion_notification_cfg *cfg)
646 struct dpseci_cmd_set_congestion_notification *rsp_params;
647 struct mc_command cmd = { 0 };
650 /* prepare command */
651 cmd.header = mc_encode_cmd_header(
652 DPSECI_CMDID_GET_CONGESTION_NOTIFICATION,
656 /* send command to mc*/
657 err = mc_send_command(mc_io, &cmd);
662 (struct dpseci_cmd_set_congestion_notification *)cmd.params;
664 cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
665 cfg->dest_cfg.priority = rsp_params->dest_priority;
666 cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
667 cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
668 cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
669 cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
670 cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
671 cfg->units = dpseci_get_field(rsp_params->type_units, CG_UNITS);
672 cfg->dest_cfg.dest_type = dpseci_get_field(rsp_params->type_units,