1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
7 #include <fsl_mc_sys.h>
8 #include <fsl_mc_cmd.h>
9 #include <fsl_dpseci.h>
10 #include <fsl_dpseci_cmd.h>
13 * dpseci_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 * @dpseci_id: DPSECI 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 dpseci_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 dpseci_open(struct fsl_mc_io *mc_io,
34 struct dpseci_cmd_open *cmd_params;
35 struct mc_command cmd = { 0 };
39 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_OPEN,
42 cmd_params = (struct dpseci_cmd_open *)cmd.params;
43 cmd_params->dpseci_id = cpu_to_le32(dpseci_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 * dpseci_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 DPSECI 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 dpseci_close(struct fsl_mc_io *mc_io,
71 struct mc_command cmd = { 0 };
74 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CLOSE,
78 /* send command to mc*/
79 return mc_send_command(mc_io, &cmd);
83 * dpseci_create() - Create the DPSECI 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 DPSECI object, allocate required resources and
91 * perform required initialization.
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 dpseci_create(struct fsl_mc_io *mc_io,
107 const struct dpseci_cfg *cfg,
110 struct dpseci_cmd_create *cmd_params;
111 struct mc_command cmd = { 0 };
114 /* prepare command */
115 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CREATE,
118 cmd_params = (struct dpseci_cmd_create *)cmd.params;
119 for (i = 0; i < DPSECI_PRIO_NUM; i++)
120 cmd_params->priorities[i] = cfg->priorities[i];
121 cmd_params->num_tx_queues = cfg->num_tx_queues;
122 cmd_params->num_rx_queues = cfg->num_rx_queues;
123 cmd_params->options = cfg->options;
125 /* send command to mc*/
126 err = mc_send_command(mc_io, &cmd);
130 /* retrieve response parameters */
131 *obj_id = mc_cmd_read_object_id(&cmd);
137 * dpseci_destroy() - Destroy the DPSECI object and release all its resources.
138 * @mc_io: Pointer to MC portal's I/O object
139 * @dprc_token: Parent container token; '0' for default container
140 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
141 * @object_id: The object id; it must be a valid id within the container that
142 * created this object;
144 * The function accepts the authentication token of the parent container that
145 * created the object (not the one that currently owns the object). The object
146 * is searched within parent using the provided 'object_id'.
147 * All tokens to the object must be closed before calling destroy.
149 * Return: '0' on Success; error code otherwise.
151 int dpseci_destroy(struct fsl_mc_io *mc_io,
156 struct dpseci_cmd_destroy *cmd_params;
157 struct mc_command cmd = { 0 };
159 /* prepare command */
160 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_DESTROY,
163 cmd_params = (struct dpseci_cmd_destroy *)cmd.params;
164 cmd_params->dpseci_id = cpu_to_le32(object_id);
166 /* send command to mc*/
167 return mc_send_command(mc_io, &cmd);
171 * dpseci_enable() - Enable the DPSECI, allow sending and receiving frames.
172 * @mc_io: Pointer to MC portal's I/O object
173 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
174 * @token: Token of DPSECI object
176 * Return: '0' on Success; Error code otherwise.
178 int dpseci_enable(struct fsl_mc_io *mc_io,
182 struct mc_command cmd = { 0 };
184 /* prepare command */
185 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_ENABLE,
189 /* send command to mc*/
190 return mc_send_command(mc_io, &cmd);
194 * dpseci_disable() - Disable the DPSECI, stop sending and receiving frames.
195 * @mc_io: Pointer to MC portal's I/O object
196 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
197 * @token: Token of DPSECI object
199 * Return: '0' on Success; Error code otherwise.
201 int dpseci_disable(struct fsl_mc_io *mc_io,
205 struct mc_command cmd = { 0 };
207 /* prepare command */
208 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_DISABLE,
212 /* send command to mc*/
213 return mc_send_command(mc_io, &cmd);
217 * dpseci_is_enabled() - Check if the DPSECI is enabled.
218 * @mc_io: Pointer to MC portal's I/O object
219 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
220 * @token: Token of DPSECI object
221 * @en: Returns '1' if object is enabled; '0' otherwise
223 * Return: '0' on Success; Error code otherwise.
225 int dpseci_is_enabled(struct fsl_mc_io *mc_io,
230 struct dpseci_rsp_is_enabled *rsp_params;
231 struct mc_command cmd = { 0 };
234 /* prepare command */
235 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_IS_ENABLED,
239 /* send command to mc*/
240 err = mc_send_command(mc_io, &cmd);
244 /* retrieve response parameters */
245 rsp_params = (struct dpseci_rsp_is_enabled *)cmd.params;
246 *en = dpseci_get_field(rsp_params->en, ENABLE);
252 * dpseci_reset() - Reset the DPSECI, returns the object to initial state.
253 * @mc_io: Pointer to MC portal's I/O object
254 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
255 * @token: Token of DPSECI object
257 * Return: '0' on Success; Error code otherwise.
259 int dpseci_reset(struct fsl_mc_io *mc_io,
263 struct mc_command cmd = { 0 };
265 /* prepare command */
266 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_RESET,
270 /* send command to mc*/
271 return mc_send_command(mc_io, &cmd);
275 * dpseci_get_attributes() - Retrieve DPSECI attributes.
276 * @mc_io: Pointer to MC portal's I/O object
277 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
278 * @token: Token of DPSECI object
279 * @attr: Returned object's attributes
281 * Return: '0' on Success; Error code otherwise.
283 int dpseci_get_attributes(struct fsl_mc_io *mc_io,
286 struct dpseci_attr *attr)
288 struct dpseci_rsp_get_attr *rsp_params;
289 struct mc_command cmd = { 0 };
292 /* prepare command */
293 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_ATTR,
297 /* send command to mc*/
298 err = mc_send_command(mc_io, &cmd);
302 /* retrieve response parameters */
303 rsp_params = (struct dpseci_rsp_get_attr *)cmd.params;
304 attr->id = le32_to_cpu(rsp_params->id);
305 attr->options = rsp_params->options;
306 attr->num_tx_queues = rsp_params->num_tx_queues;
307 attr->num_rx_queues = rsp_params->num_rx_queues;
313 * dpseci_set_rx_queue() - Set Rx queue configuration
314 * @mc_io: Pointer to MC portal's I/O object
315 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
316 * @token: Token of DPSECI object
317 * @queue: Select the queue relative to number of
318 * priorities configured at DPSECI creation; use
319 * DPSECI_ALL_QUEUES to configure all Rx queues identically.
320 * @cfg: Rx queue configuration
322 * Return: '0' on Success; Error code otherwise.
324 int dpseci_set_rx_queue(struct fsl_mc_io *mc_io,
328 const struct dpseci_rx_queue_cfg *cfg)
330 struct dpseci_cmd_set_rx_queue *cmd_params;
331 struct mc_command cmd = { 0 };
333 /* prepare command */
334 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_RX_QUEUE,
337 cmd_params = (struct dpseci_cmd_set_rx_queue *)cmd.params;
338 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
339 cmd_params->dest_priority = cfg->dest_cfg.priority;
340 cmd_params->queue = queue;
341 cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
342 cmd_params->options = cpu_to_le32(cfg->options);
343 dpseci_set_field(cmd_params->dest_type,
345 cfg->dest_cfg.dest_type);
346 dpseci_set_field(cmd_params->order_preservation_en,
348 cfg->order_preservation_en);
350 /* send command to mc*/
351 return mc_send_command(mc_io, &cmd);
355 * dpseci_get_rx_queue() - Retrieve Rx queue attributes.
356 * @mc_io: Pointer to MC portal's I/O object
357 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
358 * @token: Token of DPSECI object
359 * @queue: Select the queue relative to number of
360 * priorities configured at DPSECI creation
361 * @attr: Returned Rx queue attributes
363 * Return: '0' on Success; Error code otherwise.
365 int dpseci_get_rx_queue(struct fsl_mc_io *mc_io,
369 struct dpseci_rx_queue_attr *attr)
371 struct dpseci_rsp_get_rx_queue *rsp_params;
372 struct dpseci_cmd_get_queue *cmd_params;
373 struct mc_command cmd = { 0 };
376 /* prepare command */
377 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_RX_QUEUE,
380 cmd_params = (struct dpseci_cmd_get_queue *)cmd.params;
381 cmd_params->queue = queue;
383 /* send command to mc*/
384 err = mc_send_command(mc_io, &cmd);
388 /* retrieve response parameters */
389 rsp_params = (struct dpseci_rsp_get_rx_queue *)cmd.params;
390 attr->user_ctx = le64_to_cpu(rsp_params->user_ctx);
391 attr->fqid = le32_to_cpu(rsp_params->fqid);
392 attr->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
393 attr->dest_cfg.priority = rsp_params->dest_priority;
394 attr->dest_cfg.dest_type =
395 dpseci_get_field(rsp_params->dest_type,
397 attr->order_preservation_en =
398 dpseci_get_field(rsp_params->order_preservation_en,
405 * dpseci_get_tx_queue() - Retrieve Tx queue attributes.
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 DPSECI object
409 * @queue: Select the queue relative to number of
410 * priorities configured at DPSECI creation
411 * @attr: Returned Tx queue attributes
413 * Return: '0' on Success; Error code otherwise.
415 int dpseci_get_tx_queue(struct fsl_mc_io *mc_io,
419 struct dpseci_tx_queue_attr *attr)
421 struct dpseci_rsp_get_tx_queue *rsp_params;
422 struct dpseci_cmd_get_queue *cmd_params;
423 struct mc_command cmd = { 0 };
426 /* prepare command */
427 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_TX_QUEUE,
430 cmd_params = (struct dpseci_cmd_get_queue *)cmd.params;
431 cmd_params->queue = queue;
433 /* send command to mc*/
434 err = mc_send_command(mc_io, &cmd);
438 /* retrieve response parameters */
439 rsp_params = (struct dpseci_rsp_get_tx_queue *)cmd.params;
440 attr->fqid = le32_to_cpu(rsp_params->fqid);
441 attr->priority = rsp_params->priority;
447 * dpseci_get_sec_attr() - Retrieve SEC accelerator attributes.
448 * @mc_io: Pointer to MC portal's I/O object
449 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
450 * @token: Token of DPSECI object
451 * @attr: Returned SEC attributes
453 * Return: '0' on Success; Error code otherwise.
455 int dpseci_get_sec_attr(struct fsl_mc_io *mc_io,
458 struct dpseci_sec_attr *attr)
460 struct dpseci_rsp_get_sec_attr *rsp_params;
461 struct mc_command cmd = { 0 };
464 /* prepare command */
465 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_SEC_ATTR,
469 /* send command to mc*/
470 err = mc_send_command(mc_io, &cmd);
474 /* retrieve response parameters */
475 rsp_params = (struct dpseci_rsp_get_sec_attr *)cmd.params;
476 attr->ip_id = le16_to_cpu(rsp_params->ip_id);
477 attr->major_rev = rsp_params->major_rev;
478 attr->minor_rev = rsp_params->minor_rev;
479 attr->era = rsp_params->era;
480 attr->deco_num = rsp_params->deco_num;
481 attr->zuc_auth_acc_num = rsp_params->zuc_auth_acc_num;
482 attr->zuc_enc_acc_num = rsp_params->zuc_enc_acc_num;
483 attr->snow_f8_acc_num = rsp_params->snow_f8_acc_num;
484 attr->snow_f9_acc_num = rsp_params->snow_f9_acc_num;
485 attr->crc_acc_num = rsp_params->crc_acc_num;
486 attr->pk_acc_num = rsp_params->pk_acc_num;
487 attr->kasumi_acc_num = rsp_params->kasumi_acc_num;
488 attr->rng_acc_num = rsp_params->rng_acc_num;
489 attr->md_acc_num = rsp_params->md_acc_num;
490 attr->arc4_acc_num = rsp_params->arc4_acc_num;
491 attr->des_acc_num = rsp_params->des_acc_num;
492 attr->aes_acc_num = rsp_params->aes_acc_num;
498 * dpseci_get_sec_counters() - Retrieve SEC accelerator counters.
499 * @mc_io: Pointer to MC portal's I/O object
500 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
501 * @token: Token of DPSECI object
502 * @counters: Returned SEC counters
504 * Return: '0' on Success; Error code otherwise.
506 int dpseci_get_sec_counters(struct fsl_mc_io *mc_io,
509 struct dpseci_sec_counters *counters)
511 struct dpseci_rsp_get_sec_counters *rsp_params;
512 struct mc_command cmd = { 0 };
515 /* prepare command */
516 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_SEC_COUNTERS,
520 /* send command to mc*/
521 err = mc_send_command(mc_io, &cmd);
525 /* retrieve response parameters */
526 rsp_params = (struct dpseci_rsp_get_sec_counters *)cmd.params;
527 counters->dequeued_requests =
528 le64_to_cpu(rsp_params->dequeued_requests);
529 counters->ob_enc_requests = le64_to_cpu(rsp_params->ob_enc_requests);
530 counters->ib_dec_requests = le64_to_cpu(rsp_params->ib_dec_requests);
531 counters->ob_enc_bytes = le64_to_cpu(rsp_params->ob_enc_bytes);
532 counters->ob_prot_bytes = le64_to_cpu(rsp_params->ob_prot_bytes);
533 counters->ib_dec_bytes = le64_to_cpu(rsp_params->ib_dec_bytes);
534 counters->ib_valid_bytes = le64_to_cpu(rsp_params->ib_valid_bytes);
540 * dpseci_get_api_version() - Get Data Path SEC Interface API version
541 * @mc_io: Pointer to MC portal's I/O object
542 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
543 * @major_ver: Major version of data path sec API
544 * @minor_ver: Minor version of data path sec API
546 * Return: '0' on Success; Error code otherwise.
548 int dpseci_get_api_version(struct fsl_mc_io *mc_io,
553 struct dpseci_rsp_get_api_version *rsp_params;
554 struct mc_command cmd = { 0 };
557 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_API_VERSION,
561 err = mc_send_command(mc_io, &cmd);
565 rsp_params = (struct dpseci_rsp_get_api_version *)cmd.params;
566 *major_ver = le16_to_cpu(rsp_params->major);
567 *minor_ver = le16_to_cpu(rsp_params->minor);
572 int dpseci_set_congestion_notification(
573 struct fsl_mc_io *mc_io,
576 const struct dpseci_congestion_notification_cfg *cfg)
578 struct dpseci_cmd_set_congestion_notification *cmd_params;
579 struct mc_command cmd = { 0 };
581 /* prepare command */
582 cmd.header = mc_encode_cmd_header(
583 DPSECI_CMDID_SET_CONGESTION_NOTIFICATION,
588 (struct dpseci_cmd_set_congestion_notification *)cmd.params;
589 cmd_params->dest_id = cfg->dest_cfg.dest_id;
590 cmd_params->dest_priority = cfg->dest_cfg.priority;
591 cmd_params->message_ctx = cfg->message_ctx;
592 cmd_params->message_iova = cfg->message_iova;
593 cmd_params->notification_mode = cfg->notification_mode;
594 cmd_params->threshold_entry = cfg->threshold_entry;
595 cmd_params->threshold_exit = cfg->threshold_exit;
596 dpseci_set_field(cmd_params->type_units,
598 cfg->dest_cfg.dest_type);
599 dpseci_set_field(cmd_params->type_units,
603 /* send command to mc*/
604 return mc_send_command(mc_io, &cmd);
607 int dpseci_get_congestion_notification(
608 struct fsl_mc_io *mc_io,
611 struct dpseci_congestion_notification_cfg *cfg)
613 struct dpseci_cmd_set_congestion_notification *rsp_params;
614 struct mc_command cmd = { 0 };
617 /* prepare command */
618 cmd.header = mc_encode_cmd_header(
619 DPSECI_CMDID_GET_CONGESTION_NOTIFICATION,
623 /* send command to mc*/
624 err = mc_send_command(mc_io, &cmd);
629 (struct dpseci_cmd_set_congestion_notification *)cmd.params;
631 cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
632 cfg->dest_cfg.priority = rsp_params->dest_priority;
633 cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
634 cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
635 cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
636 cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
637 cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
638 cfg->units = dpseci_get_field(rsp_params->type_units, CG_UNITS);
639 cfg->dest_cfg.dest_type = dpseci_get_field(rsp_params->type_units,