1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0) 2 * 3 * Copyright 2013-2016 Freescale Semiconductor Inc. 4 * Copyright 2016 NXP 5 * 6 */ 7 #include <fsl_mc_sys.h> 8 #include <fsl_mc_cmd.h> 9 #include <fsl_dpopr.h> 10 #include <fsl_dpseci.h> 11 #include <fsl_dpseci_cmd.h> 12 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 */ 30 int dpseci_open(struct fsl_mc_io *mc_io, 31 uint32_t cmd_flags, 32 int dpseci_id, 33 uint16_t *token) 34 { 35 struct dpseci_cmd_open *cmd_params; 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); 43 cmd_params = (struct dpseci_cmd_open *)cmd.params; 44 cmd_params->dpseci_id = cpu_to_le32(dpseci_id); 45 46 /* send command to mc*/ 47 err = mc_send_command(mc_io, &cmd); 48 if (err) 49 return err; 50 51 /* retrieve response parameters */ 52 *token = mc_cmd_hdr_read_token(&cmd); 53 54 return 0; 55 } 56 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 */ 68 int dpseci_close(struct fsl_mc_io *mc_io, 69 uint32_t cmd_flags, 70 uint16_t token) 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 79 /* send command to mc*/ 80 return mc_send_command(mc_io, &cmd); 81 } 82 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 */ 105 int 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) 110 { 111 struct dpseci_cmd_create *cmd_params; 112 struct mc_command cmd = { 0 }; 113 int err, i; 114 115 /* prepare command */ 116 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CREATE, 117 cmd_flags, 118 dprc_token); 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*/ 129 err = mc_send_command(mc_io, &cmd); 130 if (err) 131 return err; 132 133 /* retrieve response parameters */ 134 *obj_id = mc_cmd_read_object_id(&cmd); 135 136 return 0; 137 } 138 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 */ 154 int dpseci_destroy(struct fsl_mc_io *mc_io, 155 uint16_t dprc_token, 156 uint32_t cmd_flags, 157 uint32_t object_id) 158 { 159 struct dpseci_cmd_destroy *cmd_params; 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); 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*/ 170 return mc_send_command(mc_io, &cmd); 171 } 172 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 */ 181 int dpseci_enable(struct fsl_mc_io *mc_io, 182 uint32_t cmd_flags, 183 uint16_t token) 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 192 /* send command to mc*/ 193 return mc_send_command(mc_io, &cmd); 194 } 195 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 */ 204 int dpseci_disable(struct fsl_mc_io *mc_io, 205 uint32_t cmd_flags, 206 uint16_t token) 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 215 /* send command to mc*/ 216 return mc_send_command(mc_io, &cmd); 217 } 218 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 */ 228 int dpseci_is_enabled(struct fsl_mc_io *mc_io, 229 uint32_t cmd_flags, 230 uint16_t token, 231 int *en) 232 { 233 struct dpseci_rsp_is_enabled *rsp_params; 234 struct mc_command cmd = { 0 }; 235 int err; 236 237 /* prepare command */ 238 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_IS_ENABLED, 239 cmd_flags, 240 token); 241 242 /* send command to mc*/ 243 err = mc_send_command(mc_io, &cmd); 244 if (err) 245 return err; 246 247 /* retrieve response parameters */ 248 rsp_params = (struct dpseci_rsp_is_enabled *)cmd.params; 249 *en = dpseci_get_field(rsp_params->en, ENABLE); 250 251 return 0; 252 } 253 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 */ 262 int dpseci_reset(struct fsl_mc_io *mc_io, 263 uint32_t cmd_flags, 264 uint16_t token) 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 273 /* send command to mc*/ 274 return mc_send_command(mc_io, &cmd); 275 } 276 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 */ 286 int dpseci_get_attributes(struct fsl_mc_io *mc_io, 287 uint32_t cmd_flags, 288 uint16_t token, 289 struct dpseci_attr *attr) 290 { 291 struct dpseci_rsp_get_attr *rsp_params; 292 struct mc_command cmd = { 0 }; 293 int err; 294 295 /* prepare command */ 296 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_ATTR, 297 cmd_flags, 298 token); 299 300 /* send command to mc*/ 301 err = mc_send_command(mc_io, &cmd); 302 if (err) 303 return err; 304 305 /* retrieve response parameters */ 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; 311 312 return 0; 313 } 314 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 */ 327 int 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) 332 { 333 struct dpseci_cmd_set_rx_queue *cmd_params; 334 struct mc_command cmd = { 0 }; 335 336 /* prepare command */ 337 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_RX_QUEUE, 338 cmd_flags, 339 token); 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*/ 354 return mc_send_command(mc_io, &cmd); 355 } 356 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 */ 368 int 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) 373 { 374 struct dpseci_rsp_get_rx_queue *rsp_params; 375 struct dpseci_cmd_get_queue *cmd_params; 376 struct mc_command cmd = { 0 }; 377 int err; 378 379 /* prepare command */ 380 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_RX_QUEUE, 381 cmd_flags, 382 token); 383 cmd_params = (struct dpseci_cmd_get_queue *)cmd.params; 384 cmd_params->queue = queue; 385 386 /* send command to mc*/ 387 err = mc_send_command(mc_io, &cmd); 388 if (err) 389 return err; 390 391 /* retrieve response parameters */ 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); 403 404 return 0; 405 } 406 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 */ 418 int 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) 423 { 424 struct dpseci_rsp_get_tx_queue *rsp_params; 425 struct dpseci_cmd_get_queue *cmd_params; 426 struct mc_command cmd = { 0 }; 427 int err; 428 429 /* prepare command */ 430 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_TX_QUEUE, 431 cmd_flags, 432 token); 433 cmd_params = (struct dpseci_cmd_get_queue *)cmd.params; 434 cmd_params->queue = queue; 435 436 /* send command to mc*/ 437 err = mc_send_command(mc_io, &cmd); 438 if (err) 439 return err; 440 441 /* retrieve response parameters */ 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; 445 446 return 0; 447 } 448 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 */ 458 int 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) 462 { 463 struct dpseci_rsp_get_sec_attr *rsp_params; 464 struct mc_command cmd = { 0 }; 465 int err; 466 467 /* prepare command */ 468 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_SEC_ATTR, 469 cmd_flags, 470 token); 471 472 /* send command to mc*/ 473 err = mc_send_command(mc_io, &cmd); 474 if (err) 475 return err; 476 477 /* retrieve response parameters */ 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; 498 499 return 0; 500 } 501 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 */ 511 int 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) 515 { 516 struct dpseci_rsp_get_sec_counters *rsp_params; 517 struct mc_command cmd = { 0 }; 518 int err; 519 520 /* prepare command */ 521 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_SEC_COUNTERS, 522 cmd_flags, 523 token); 524 525 /* send command to mc*/ 526 err = mc_send_command(mc_io, &cmd); 527 if (err) 528 return err; 529 530 /* retrieve response parameters */ 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); 540 541 return 0; 542 } 543 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 */ 553 int 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) 557 { 558 struct dpseci_rsp_get_api_version *rsp_params; 559 struct mc_command cmd = { 0 }; 560 int err; 561 562 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_API_VERSION, 563 cmd_flags, 564 0); 565 566 err = mc_send_command(mc_io, &cmd); 567 if (err) 568 return err; 569 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); 573 574 return 0; 575 } 576 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 */ 589 int 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) 595 { 596 struct dpseci_cmd_set_opr *cmd_params; 597 struct mc_command cmd = { 0 }; 598 599 /* prepare command */ 600 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_OPR, 601 cmd_flags, 602 token); 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); 614 } 615 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 */ 627 int 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) 633 { 634 struct dpseci_rsp_get_opr *rsp_params; 635 struct dpseci_cmd_get_opr *cmd_params; 636 struct mc_command cmd = { 0 }; 637 int err; 638 639 /* prepare command */ 640 cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_OPR, 641 cmd_flags, 642 token); 643 cmd_params = (struct dpseci_cmd_get_opr *)cmd.params; 644 cmd_params->index = index; 645 646 /* send command to mc*/ 647 err = mc_send_command(mc_io, &cmd); 648 if (err) 649 return err; 650 651 /* retrieve response parameters */ 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); 670 671 return 0; 672 } 673 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 */ 684 int dpseci_set_congestion_notification( 685 struct fsl_mc_io *mc_io, 686 uint32_t cmd_flags, 687 uint16_t token, 688 const struct dpseci_congestion_notification_cfg *cfg) 689 { 690 struct dpseci_cmd_set_congestion_notification *cmd_params; 691 struct mc_command cmd = { 0 }; 692 693 /* prepare command */ 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); 717 } 718 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 */ 729 int 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) 734 { 735 struct dpseci_cmd_set_congestion_notification *rsp_params; 736 struct mc_command cmd = { 0 }; 737 int err; 738 739 /* prepare command */ 740 cmd.header = mc_encode_cmd_header( 741 DPSECI_CMDID_GET_CONGESTION_NOTIFICATION, 742 cmd_flags, 743 token); 744 745 /* send command to mc*/ 746 err = mc_send_command(mc_io, &cmd); 747 if (err) 748 return err; 749 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); 763 764 return 0; 765 } 766