]> git.proxmox.com Git - ceph.git/blame - ceph/src/seastar/dpdk/drivers/crypto/dpaa2_sec/mc/dpseci.c
import 15.2.0 Octopus source
[ceph.git] / ceph / src / seastar / dpdk / drivers / crypto / dpaa2_sec / mc / dpseci.c
CommitLineData
9f95a23c 1/* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
11fdf7f2
TL
2 *
3 * Copyright 2013-2016 Freescale Semiconductor Inc.
9f95a23c 4 * Copyright 2016 NXP
11fdf7f2 5 *
11fdf7f2 6 */
11fdf7f2
TL
7#include <fsl_mc_sys.h>
8#include <fsl_mc_cmd.h>
9f95a23c 9#include <fsl_dpopr.h>
11fdf7f2
TL
10#include <fsl_dpseci.h>
11#include <fsl_dpseci_cmd.h>
12
9f95a23c
TL
13/**
14 * dpseci_open() - Open a control session for the specified object
15 * @mc_io: Pointer to MC portal's I/O object
16 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
17 * @dpseci_id: DPSECI unique ID
18 * @token: Returned token; use in subsequent API calls
19 *
20 * This function can be used to open a control session for an
21 * already created object; an object may have been declared in
22 * the DPL or by calling the dpseci_create() function.
23 * This function returns a unique authentication token,
24 * associated with the specific object ID and the specific MC
25 * portal; this token must be used in all subsequent commands for
26 * this specific object.
27 *
28 * Return: '0' on Success; Error code otherwise.
29 */
30int dpseci_open(struct fsl_mc_io *mc_io,
31 uint32_t cmd_flags,
32 int dpseci_id,
33 uint16_t *token)
11fdf7f2 34{
9f95a23c 35 struct dpseci_cmd_open *cmd_params;
11fdf7f2
TL
36 struct mc_command cmd = { 0 };
37 int err;
38
39 /* prepare command */
40 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_OPEN,
41 cmd_flags,
42 0);
9f95a23c
TL
43 cmd_params = (struct dpseci_cmd_open *)cmd.params;
44 cmd_params->dpseci_id = cpu_to_le32(dpseci_id);
11fdf7f2 45
9f95a23c 46 /* send command to mc*/
11fdf7f2
TL
47 err = mc_send_command(mc_io, &cmd);
48 if (err)
49 return err;
50
51 /* retrieve response parameters */
9f95a23c 52 *token = mc_cmd_hdr_read_token(&cmd);
11fdf7f2
TL
53
54 return 0;
55}
56
9f95a23c
TL
57/**
58 * dpseci_close() - Close the control session of the object
59 * @mc_io: Pointer to MC portal's I/O object
60 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
61 * @token: Token of DPSECI object
62 *
63 * After this function is called, no further operations are
64 * allowed on the object without opening a new control session.
65 *
66 * Return: '0' on Success; Error code otherwise.
67 */
68int dpseci_close(struct fsl_mc_io *mc_io,
69 uint32_t cmd_flags,
70 uint16_t token)
11fdf7f2
TL
71{
72 struct mc_command cmd = { 0 };
73
74 /* prepare command */
75 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CLOSE,
76 cmd_flags,
77 token);
78
9f95a23c 79 /* send command to mc*/
11fdf7f2
TL
80 return mc_send_command(mc_io, &cmd);
81}
82
9f95a23c
TL
83/**
84 * dpseci_create() - Create the DPSECI object
85 * @mc_io: Pointer to MC portal's I/O object
86 * @dprc_token: Parent container token; '0' for default container
87 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
88 * @cfg: Configuration structure
89 * @obj_id: Returned object id
90 *
91 * Create the DPSECI object, allocate required resources and
92 * perform required initialization.
93 *
94 * The object can be created either by declaring it in the
95 * DPL file, or by calling this function.
96 *
97 * The function accepts an authentication token of a parent
98 * container that this object should be assigned to. The token
99 * can be '0' so the object will be assigned to the default container.
100 * The newly created object can be opened with the returned
101 * object id and using the container's associated tokens and MC portals.
102 *
103 * Return: '0' on Success; Error code otherwise.
104 */
105int dpseci_create(struct fsl_mc_io *mc_io,
106 uint16_t dprc_token,
107 uint32_t cmd_flags,
108 const struct dpseci_cfg *cfg,
109 uint32_t *obj_id)
11fdf7f2 110{
9f95a23c 111 struct dpseci_cmd_create *cmd_params;
11fdf7f2 112 struct mc_command cmd = { 0 };
9f95a23c 113 int err, i;
11fdf7f2
TL
114
115 /* prepare command */
116 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CREATE,
117 cmd_flags,
118 dprc_token);
9f95a23c
TL
119 cmd_params = (struct dpseci_cmd_create *)cmd.params;
120 for (i = 0; i < 8; i++)
121 cmd_params->priorities[i] = cfg->priorities[i];
122 for (i = 0; i < 8; i++)
123 cmd_params->priorities2[i] = cfg->priorities[8 + i];
124 cmd_params->num_tx_queues = cfg->num_tx_queues;
125 cmd_params->num_rx_queues = cfg->num_rx_queues;
126 cmd_params->options = cpu_to_le32(cfg->options);
127
128 /* send command to mc*/
11fdf7f2
TL
129 err = mc_send_command(mc_io, &cmd);
130 if (err)
131 return err;
132
133 /* retrieve response parameters */
9f95a23c 134 *obj_id = mc_cmd_read_object_id(&cmd);
11fdf7f2
TL
135
136 return 0;
137}
138
9f95a23c
TL
139/**
140 * dpseci_destroy() - Destroy the DPSECI object and release all its resources.
141 * @mc_io: Pointer to MC portal's I/O object
142 * @dprc_token: Parent container token; '0' for default container
143 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
144 * @object_id: The object id; it must be a valid id within the container that
145 * created this object;
146 *
147 * The function accepts the authentication token of the parent container that
148 * created the object (not the one that currently owns the object). The object
149 * is searched within parent using the provided 'object_id'.
150 * All tokens to the object must be closed before calling destroy.
151 *
152 * Return: '0' on Success; error code otherwise.
153 */
154int dpseci_destroy(struct fsl_mc_io *mc_io,
155 uint16_t dprc_token,
156 uint32_t cmd_flags,
157 uint32_t object_id)
11fdf7f2 158{
9f95a23c 159 struct dpseci_cmd_destroy *cmd_params;
11fdf7f2
TL
160 struct mc_command cmd = { 0 };
161
162 /* prepare command */
163 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_DESTROY,
164 cmd_flags,
165 dprc_token);
9f95a23c
TL
166 cmd_params = (struct dpseci_cmd_destroy *)cmd.params;
167 cmd_params->dpseci_id = cpu_to_le32(object_id);
168
169 /* send command to mc*/
11fdf7f2
TL
170 return mc_send_command(mc_io, &cmd);
171}
172
9f95a23c
TL
173/**
174 * dpseci_enable() - Enable the DPSECI, allow sending and receiving frames.
175 * @mc_io: Pointer to MC portal's I/O object
176 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
177 * @token: Token of DPSECI object
178 *
179 * Return: '0' on Success; Error code otherwise.
180 */
181int dpseci_enable(struct fsl_mc_io *mc_io,
182 uint32_t cmd_flags,
183 uint16_t token)
11fdf7f2
TL
184{
185 struct mc_command cmd = { 0 };
186
187 /* prepare command */
188 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_ENABLE,
189 cmd_flags,
190 token);
191
9f95a23c 192 /* send command to mc*/
11fdf7f2
TL
193 return mc_send_command(mc_io, &cmd);
194}
195
9f95a23c
TL
196/**
197 * dpseci_disable() - Disable the DPSECI, stop sending and receiving frames.
198 * @mc_io: Pointer to MC portal's I/O object
199 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
200 * @token: Token of DPSECI object
201 *
202 * Return: '0' on Success; Error code otherwise.
203 */
204int dpseci_disable(struct fsl_mc_io *mc_io,
205 uint32_t cmd_flags,
206 uint16_t token)
11fdf7f2
TL
207{
208 struct mc_command cmd = { 0 };
209
210 /* prepare command */
211 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_DISABLE,
212 cmd_flags,
213 token);
214
9f95a23c 215 /* send command to mc*/
11fdf7f2
TL
216 return mc_send_command(mc_io, &cmd);
217}
218
9f95a23c
TL
219/**
220 * dpseci_is_enabled() - Check if the DPSECI is enabled.
221 * @mc_io: Pointer to MC portal's I/O object
222 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
223 * @token: Token of DPSECI object
224 * @en: Returns '1' if object is enabled; '0' otherwise
225 *
226 * Return: '0' on Success; Error code otherwise.
227 */
228int dpseci_is_enabled(struct fsl_mc_io *mc_io,
229 uint32_t cmd_flags,
230 uint16_t token,
231 int *en)
11fdf7f2 232{
9f95a23c 233 struct dpseci_rsp_is_enabled *rsp_params;
11fdf7f2
TL
234 struct mc_command cmd = { 0 };
235 int err;
9f95a23c 236
11fdf7f2
TL
237 /* prepare command */
238 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_IS_ENABLED,
239 cmd_flags,
240 token);
241
9f95a23c 242 /* send command to mc*/
11fdf7f2
TL
243 err = mc_send_command(mc_io, &cmd);
244 if (err)
245 return err;
246
247 /* retrieve response parameters */
9f95a23c
TL
248 rsp_params = (struct dpseci_rsp_is_enabled *)cmd.params;
249 *en = dpseci_get_field(rsp_params->en, ENABLE);
11fdf7f2
TL
250
251 return 0;
252}
253
9f95a23c
TL
254/**
255 * dpseci_reset() - Reset the DPSECI, returns the object to initial state.
256 * @mc_io: Pointer to MC portal's I/O object
257 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
258 * @token: Token of DPSECI object
259 *
260 * Return: '0' on Success; Error code otherwise.
261 */
262int dpseci_reset(struct fsl_mc_io *mc_io,
263 uint32_t cmd_flags,
264 uint16_t token)
11fdf7f2
TL
265{
266 struct mc_command cmd = { 0 };
267
268 /* prepare command */
269 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_RESET,
270 cmd_flags,
271 token);
272
9f95a23c 273 /* send command to mc*/
11fdf7f2
TL
274 return mc_send_command(mc_io, &cmd);
275}
276
9f95a23c
TL
277/**
278 * dpseci_get_attributes() - Retrieve DPSECI attributes.
279 * @mc_io: Pointer to MC portal's I/O object
280 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
281 * @token: Token of DPSECI object
282 * @attr: Returned object's attributes
283 *
284 * Return: '0' on Success; Error code otherwise.
285 */
286int dpseci_get_attributes(struct fsl_mc_io *mc_io,
287 uint32_t cmd_flags,
288 uint16_t token,
289 struct dpseci_attr *attr)
11fdf7f2 290{
9f95a23c 291 struct dpseci_rsp_get_attr *rsp_params;
11fdf7f2
TL
292 struct mc_command cmd = { 0 };
293 int err;
294
295 /* prepare command */
9f95a23c 296 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_ATTR,
11fdf7f2
TL
297 cmd_flags,
298 token);
11fdf7f2 299
9f95a23c 300 /* send command to mc*/
11fdf7f2
TL
301 err = mc_send_command(mc_io, &cmd);
302 if (err)
303 return err;
304
305 /* retrieve response parameters */
9f95a23c
TL
306 rsp_params = (struct dpseci_rsp_get_attr *)cmd.params;
307 attr->id = le32_to_cpu(rsp_params->id);
308 attr->options = le32_to_cpu(rsp_params->options);
309 attr->num_tx_queues = rsp_params->num_tx_queues;
310 attr->num_rx_queues = rsp_params->num_rx_queues;
11fdf7f2
TL
311
312 return 0;
313}
314
9f95a23c
TL
315/**
316 * dpseci_set_rx_queue() - Set Rx queue configuration
317 * @mc_io: Pointer to MC portal's I/O object
318 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
319 * @token: Token of DPSECI object
320 * @queue: Select the queue relative to number of
321 * priorities configured at DPSECI creation; use
322 * DPSECI_ALL_QUEUES to configure all Rx queues identically.
323 * @cfg: Rx queue configuration
324 *
325 * Return: '0' on Success; Error code otherwise.
326 */
327int dpseci_set_rx_queue(struct fsl_mc_io *mc_io,
328 uint32_t cmd_flags,
329 uint16_t token,
330 uint8_t queue,
331 const struct dpseci_rx_queue_cfg *cfg)
11fdf7f2 332{
9f95a23c 333 struct dpseci_cmd_set_rx_queue *cmd_params;
11fdf7f2
TL
334 struct mc_command cmd = { 0 };
335
336 /* prepare command */
9f95a23c 337 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_RX_QUEUE,
11fdf7f2
TL
338 cmd_flags,
339 token);
9f95a23c
TL
340 cmd_params = (struct dpseci_cmd_set_rx_queue *)cmd.params;
341 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
342 cmd_params->dest_priority = cfg->dest_cfg.priority;
343 cmd_params->queue = queue;
344 cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
345 cmd_params->options = cpu_to_le32(cfg->options);
346 dpseci_set_field(cmd_params->dest_type,
347 DEST_TYPE,
348 cfg->dest_cfg.dest_type);
349 dpseci_set_field(cmd_params->order_preservation_en,
350 ORDER_PRESERVATION,
351 cfg->order_preservation_en);
352
353 /* send command to mc*/
11fdf7f2
TL
354 return mc_send_command(mc_io, &cmd);
355}
356
9f95a23c
TL
357/**
358 * dpseci_get_rx_queue() - Retrieve Rx queue attributes.
359 * @mc_io: Pointer to MC portal's I/O object
360 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
361 * @token: Token of DPSECI object
362 * @queue: Select the queue relative to number of
363 * priorities configured at DPSECI creation
364 * @attr: Returned Rx queue attributes
365 *
366 * Return: '0' on Success; Error code otherwise.
367 */
368int dpseci_get_rx_queue(struct fsl_mc_io *mc_io,
369 uint32_t cmd_flags,
370 uint16_t token,
371 uint8_t queue,
372 struct dpseci_rx_queue_attr *attr)
11fdf7f2 373{
9f95a23c
TL
374 struct dpseci_rsp_get_rx_queue *rsp_params;
375 struct dpseci_cmd_get_queue *cmd_params;
11fdf7f2
TL
376 struct mc_command cmd = { 0 };
377 int err;
378
379 /* prepare command */
9f95a23c 380 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_RX_QUEUE,
11fdf7f2
TL
381 cmd_flags,
382 token);
9f95a23c
TL
383 cmd_params = (struct dpseci_cmd_get_queue *)cmd.params;
384 cmd_params->queue = queue;
11fdf7f2 385
9f95a23c 386 /* send command to mc*/
11fdf7f2
TL
387 err = mc_send_command(mc_io, &cmd);
388 if (err)
389 return err;
390
391 /* retrieve response parameters */
9f95a23c
TL
392 rsp_params = (struct dpseci_rsp_get_rx_queue *)cmd.params;
393 attr->user_ctx = le64_to_cpu(rsp_params->user_ctx);
394 attr->fqid = le32_to_cpu(rsp_params->fqid);
395 attr->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
396 attr->dest_cfg.priority = rsp_params->dest_priority;
397 attr->dest_cfg.dest_type =
398 dpseci_get_field(rsp_params->dest_type,
399 DEST_TYPE);
400 attr->order_preservation_en =
401 dpseci_get_field(rsp_params->order_preservation_en,
402 ORDER_PRESERVATION);
11fdf7f2
TL
403
404 return 0;
405}
406
9f95a23c
TL
407/**
408 * dpseci_get_tx_queue() - Retrieve Tx queue attributes.
409 * @mc_io: Pointer to MC portal's I/O object
410 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
411 * @token: Token of DPSECI object
412 * @queue: Select the queue relative to number of
413 * priorities configured at DPSECI creation
414 * @attr: Returned Tx queue attributes
415 *
416 * Return: '0' on Success; Error code otherwise.
417 */
418int dpseci_get_tx_queue(struct fsl_mc_io *mc_io,
419 uint32_t cmd_flags,
420 uint16_t token,
421 uint8_t queue,
422 struct dpseci_tx_queue_attr *attr)
11fdf7f2 423{
9f95a23c
TL
424 struct dpseci_rsp_get_tx_queue *rsp_params;
425 struct dpseci_cmd_get_queue *cmd_params;
11fdf7f2
TL
426 struct mc_command cmd = { 0 };
427 int err;
428
429 /* prepare command */
9f95a23c 430 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_TX_QUEUE,
11fdf7f2
TL
431 cmd_flags,
432 token);
9f95a23c
TL
433 cmd_params = (struct dpseci_cmd_get_queue *)cmd.params;
434 cmd_params->queue = queue;
11fdf7f2 435
9f95a23c 436 /* send command to mc*/
11fdf7f2
TL
437 err = mc_send_command(mc_io, &cmd);
438 if (err)
439 return err;
440
441 /* retrieve response parameters */
9f95a23c
TL
442 rsp_params = (struct dpseci_rsp_get_tx_queue *)cmd.params;
443 attr->fqid = le32_to_cpu(rsp_params->fqid);
444 attr->priority = rsp_params->priority;
11fdf7f2
TL
445
446 return 0;
447}
448
9f95a23c
TL
449/**
450 * dpseci_get_sec_attr() - Retrieve SEC accelerator attributes.
451 * @mc_io: Pointer to MC portal's I/O object
452 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
453 * @token: Token of DPSECI object
454 * @attr: Returned SEC attributes
455 *
456 * Return: '0' on Success; Error code otherwise.
457 */
458int dpseci_get_sec_attr(struct fsl_mc_io *mc_io,
459 uint32_t cmd_flags,
460 uint16_t token,
461 struct dpseci_sec_attr *attr)
11fdf7f2 462{
9f95a23c 463 struct dpseci_rsp_get_sec_attr *rsp_params;
11fdf7f2
TL
464 struct mc_command cmd = { 0 };
465 int err;
466
467 /* prepare command */
9f95a23c 468 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_SEC_ATTR,
11fdf7f2
TL
469 cmd_flags,
470 token);
11fdf7f2 471
9f95a23c 472 /* send command to mc*/
11fdf7f2
TL
473 err = mc_send_command(mc_io, &cmd);
474 if (err)
475 return err;
476
477 /* retrieve response parameters */
9f95a23c
TL
478 rsp_params = (struct dpseci_rsp_get_sec_attr *)cmd.params;
479 attr->ip_id = le16_to_cpu(rsp_params->ip_id);
480 attr->major_rev = rsp_params->major_rev;
481 attr->minor_rev = rsp_params->minor_rev;
482 attr->era = rsp_params->era;
483 attr->deco_num = rsp_params->deco_num;
484 attr->zuc_auth_acc_num = rsp_params->zuc_auth_acc_num;
485 attr->zuc_enc_acc_num = rsp_params->zuc_enc_acc_num;
486 attr->snow_f8_acc_num = rsp_params->snow_f8_acc_num;
487 attr->snow_f9_acc_num = rsp_params->snow_f9_acc_num;
488 attr->crc_acc_num = rsp_params->crc_acc_num;
489 attr->pk_acc_num = rsp_params->pk_acc_num;
490 attr->kasumi_acc_num = rsp_params->kasumi_acc_num;
491 attr->rng_acc_num = rsp_params->rng_acc_num;
492 attr->md_acc_num = rsp_params->md_acc_num;
493 attr->arc4_acc_num = rsp_params->arc4_acc_num;
494 attr->des_acc_num = rsp_params->des_acc_num;
495 attr->aes_acc_num = rsp_params->aes_acc_num;
496 attr->ccha_acc_num = rsp_params->ccha_acc_num;
497 attr->ptha_acc_num = rsp_params->ptha_acc_num;
11fdf7f2
TL
498
499 return 0;
500}
501
9f95a23c
TL
502/**
503 * dpseci_get_sec_counters() - Retrieve SEC accelerator counters.
504 * @mc_io: Pointer to MC portal's I/O object
505 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
506 * @token: Token of DPSECI object
507 * @counters: Returned SEC counters
508 *
509 * Return: '0' on Success; Error code otherwise.
510 */
511int dpseci_get_sec_counters(struct fsl_mc_io *mc_io,
512 uint32_t cmd_flags,
513 uint16_t token,
514 struct dpseci_sec_counters *counters)
11fdf7f2 515{
9f95a23c 516 struct dpseci_rsp_get_sec_counters *rsp_params;
11fdf7f2
TL
517 struct mc_command cmd = { 0 };
518 int err;
519
520 /* prepare command */
9f95a23c 521 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_SEC_COUNTERS,
11fdf7f2
TL
522 cmd_flags,
523 token);
524
9f95a23c 525 /* send command to mc*/
11fdf7f2
TL
526 err = mc_send_command(mc_io, &cmd);
527 if (err)
528 return err;
529
530 /* retrieve response parameters */
9f95a23c
TL
531 rsp_params = (struct dpseci_rsp_get_sec_counters *)cmd.params;
532 counters->dequeued_requests =
533 le64_to_cpu(rsp_params->dequeued_requests);
534 counters->ob_enc_requests = le64_to_cpu(rsp_params->ob_enc_requests);
535 counters->ib_dec_requests = le64_to_cpu(rsp_params->ib_dec_requests);
536 counters->ob_enc_bytes = le64_to_cpu(rsp_params->ob_enc_bytes);
537 counters->ob_prot_bytes = le64_to_cpu(rsp_params->ob_prot_bytes);
538 counters->ib_dec_bytes = le64_to_cpu(rsp_params->ib_dec_bytes);
539 counters->ib_valid_bytes = le64_to_cpu(rsp_params->ib_valid_bytes);
11fdf7f2
TL
540
541 return 0;
542}
543
9f95a23c
TL
544/**
545 * dpseci_get_api_version() - Get Data Path SEC Interface API version
546 * @mc_io: Pointer to MC portal's I/O object
547 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
548 * @major_ver: Major version of data path sec API
549 * @minor_ver: Minor version of data path sec API
550 *
551 * Return: '0' on Success; Error code otherwise.
552 */
553int dpseci_get_api_version(struct fsl_mc_io *mc_io,
554 uint32_t cmd_flags,
555 uint16_t *major_ver,
556 uint16_t *minor_ver)
11fdf7f2 557{
9f95a23c 558 struct dpseci_rsp_get_api_version *rsp_params;
11fdf7f2
TL
559 struct mc_command cmd = { 0 };
560 int err;
561
9f95a23c
TL
562 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_API_VERSION,
563 cmd_flags,
564 0);
11fdf7f2 565
11fdf7f2
TL
566 err = mc_send_command(mc_io, &cmd);
567 if (err)
568 return err;
569
9f95a23c
TL
570 rsp_params = (struct dpseci_rsp_get_api_version *)cmd.params;
571 *major_ver = le16_to_cpu(rsp_params->major);
572 *minor_ver = le16_to_cpu(rsp_params->minor);
11fdf7f2
TL
573
574 return 0;
575}
576
9f95a23c
TL
577/**
578 * dpseci_set_opr() - Set Order Restoration configuration.
579 * @mc_io: Pointer to MC portal's I/O object
580 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
581 * @token: Token of DPSECI object
582 * @index: The queue index
583 * @options: Configuration mode options
584 * can be OPR_OPT_CREATE or OPR_OPT_RETIRE
585 * @cfg: Configuration options for the OPR
586 *
587 * Return: '0' on Success; Error code otherwise.
588 */
589int dpseci_set_opr(struct fsl_mc_io *mc_io,
590 uint32_t cmd_flags,
591 uint16_t token,
592 uint8_t index,
593 uint8_t options,
594 struct opr_cfg *cfg)
11fdf7f2 595{
9f95a23c 596 struct dpseci_cmd_set_opr *cmd_params;
11fdf7f2 597 struct mc_command cmd = { 0 };
11fdf7f2
TL
598
599 /* prepare command */
9f95a23c 600 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_OPR,
11fdf7f2
TL
601 cmd_flags,
602 token);
9f95a23c
TL
603 cmd_params = (struct dpseci_cmd_set_opr *)cmd.params;
604 cmd_params->index = index;
605 cmd_params->options = options;
606 cmd_params->oloe = cfg->oloe;
607 cmd_params->oeane = cfg->oeane;
608 cmd_params->olws = cfg->olws;
609 cmd_params->oa = cfg->oa;
610 cmd_params->oprrws = cfg->oprrws;
611
612 /* send command to mc*/
613 return mc_send_command(mc_io, &cmd);
11fdf7f2
TL
614}
615
9f95a23c
TL
616/**
617 * dpseci_get_opr() - Retrieve Order Restoration config and query.
618 * @mc_io: Pointer to MC portal's I/O object
619 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
620 * @token: Token of DPSECI object
621 * @index: The queue index
622 * @cfg: Returned OPR configuration
623 * @qry: Returned OPR query
624 *
625 * Return: '0' on Success; Error code otherwise.
626 */
627int dpseci_get_opr(struct fsl_mc_io *mc_io,
628 uint32_t cmd_flags,
629 uint16_t token,
630 uint8_t index,
631 struct opr_cfg *cfg,
632 struct opr_qry *qry)
11fdf7f2 633{
9f95a23c
TL
634 struct dpseci_rsp_get_opr *rsp_params;
635 struct dpseci_cmd_get_opr *cmd_params;
11fdf7f2
TL
636 struct mc_command cmd = { 0 };
637 int err;
638
639 /* prepare command */
9f95a23c 640 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_OPR,
11fdf7f2
TL
641 cmd_flags,
642 token);
9f95a23c
TL
643 cmd_params = (struct dpseci_cmd_get_opr *)cmd.params;
644 cmd_params->index = index;
11fdf7f2 645
9f95a23c 646 /* send command to mc*/
11fdf7f2
TL
647 err = mc_send_command(mc_io, &cmd);
648 if (err)
649 return err;
650
651 /* retrieve response parameters */
9f95a23c
TL
652 rsp_params = (struct dpseci_rsp_get_opr *)cmd.params;
653 cfg->oloe = rsp_params->oloe;
654 cfg->oeane = rsp_params->oeane;
655 cfg->olws = rsp_params->olws;
656 cfg->oa = rsp_params->oa;
657 cfg->oprrws = rsp_params->oprrws;
658 qry->rip = dpseci_get_field(rsp_params->flags, RIP);
659 qry->enable = dpseci_get_field(rsp_params->flags, OPR_ENABLE);
660 qry->nesn = le16_to_cpu(rsp_params->nesn);
661 qry->ndsn = le16_to_cpu(rsp_params->ndsn);
662 qry->ea_tseq = le16_to_cpu(rsp_params->ea_tseq);
663 qry->tseq_nlis = dpseci_get_field(rsp_params->tseq_nlis, TSEQ_NLIS);
664 qry->ea_hseq = le16_to_cpu(rsp_params->ea_hseq);
665 qry->hseq_nlis = dpseci_get_field(rsp_params->hseq_nlis, HSEQ_NLIS);
666 qry->ea_hptr = le16_to_cpu(rsp_params->ea_hptr);
667 qry->ea_tptr = le16_to_cpu(rsp_params->ea_tptr);
668 qry->opr_vid = le16_to_cpu(rsp_params->opr_vid);
669 qry->opr_id = le16_to_cpu(rsp_params->opr_id);
11fdf7f2
TL
670
671 return 0;
672}
673
9f95a23c
TL
674/**
675 * dpseci_set_congestion_notification() - Set congestion group
676 * notification configuration
677 * @mc_io: Pointer to MC portal's I/O object
678 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
679 * @token: Token of DPSECI object
680 * @cfg: congestion notification configuration
681 *
682 * Return: '0' on success, error code otherwise
683 */
684int dpseci_set_congestion_notification(
685 struct fsl_mc_io *mc_io,
11fdf7f2
TL
686 uint32_t cmd_flags,
687 uint16_t token,
9f95a23c 688 const struct dpseci_congestion_notification_cfg *cfg)
11fdf7f2 689{
9f95a23c 690 struct dpseci_cmd_set_congestion_notification *cmd_params;
11fdf7f2 691 struct mc_command cmd = { 0 };
11fdf7f2
TL
692
693 /* prepare command */
9f95a23c
TL
694 cmd.header = mc_encode_cmd_header(
695 DPSECI_CMDID_SET_CONGESTION_NOTIFICATION,
696 cmd_flags,
697 token);
698
699 cmd_params =
700 (struct dpseci_cmd_set_congestion_notification *)cmd.params;
701 cmd_params->dest_id = cfg->dest_cfg.dest_id;
702 cmd_params->dest_priority = cfg->dest_cfg.priority;
703 cmd_params->message_ctx = cfg->message_ctx;
704 cmd_params->message_iova = cfg->message_iova;
705 cmd_params->notification_mode = cfg->notification_mode;
706 cmd_params->threshold_entry = cfg->threshold_entry;
707 cmd_params->threshold_exit = cfg->threshold_exit;
708 dpseci_set_field(cmd_params->type_units,
709 DEST_TYPE,
710 cfg->dest_cfg.dest_type);
711 dpseci_set_field(cmd_params->type_units,
712 CG_UNITS,
713 cfg->units);
714
715 /* send command to mc*/
716 return mc_send_command(mc_io, &cmd);
11fdf7f2
TL
717}
718
9f95a23c
TL
719/**
720 * dpseci_get_congestion_notification() - Get congestion group
721 * notification configuration
722 * @mc_io: Pointer to MC portal's I/O object
723 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
724 * @token: Token of DPSECI object
725 * @cfg: congestion notification configuration
726 *
727 * Return: '0' on success, error code otherwise
728 */
729int dpseci_get_congestion_notification(
730 struct fsl_mc_io *mc_io,
731 uint32_t cmd_flags,
732 uint16_t token,
733 struct dpseci_congestion_notification_cfg *cfg)
11fdf7f2 734{
9f95a23c 735 struct dpseci_cmd_set_congestion_notification *rsp_params;
11fdf7f2
TL
736 struct mc_command cmd = { 0 };
737 int err;
738
9f95a23c
TL
739 /* prepare command */
740 cmd.header = mc_encode_cmd_header(
741 DPSECI_CMDID_GET_CONGESTION_NOTIFICATION,
742 cmd_flags,
743 token);
11fdf7f2 744
9f95a23c 745 /* send command to mc*/
11fdf7f2
TL
746 err = mc_send_command(mc_io, &cmd);
747 if (err)
748 return err;
749
9f95a23c
TL
750 rsp_params =
751 (struct dpseci_cmd_set_congestion_notification *)cmd.params;
752
753 cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
754 cfg->dest_cfg.priority = rsp_params->dest_priority;
755 cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
756 cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
757 cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
758 cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
759 cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
760 cfg->units = dpseci_get_field(rsp_params->type_units, CG_UNITS);
761 cfg->dest_cfg.dest_type = dpseci_get_field(rsp_params->type_units,
762 DEST_TYPE);
11fdf7f2
TL
763
764 return 0;
765}