1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0) 2 * 3 * Copyright 2013-2016 Freescale Semiconductor Inc. 4 * Copyright 2016-2023 NXP 5 * 6 */ 7 #include <fsl_mc_sys.h> 8 #include <fsl_mc_cmd.h> 9 #include <fsl_dpni.h> 10 #include <fsl_dpni_cmd.h> 11 12 /** 13 * dpni_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 * @dpni_id: DPNI unique ID 17 * @token: Returned token; use in subsequent API calls 18 * 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 dpni_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. 26 * 27 * Return: '0' on Success; Error code otherwise. 28 */ 29 int dpni_open(struct fsl_mc_io *mc_io, 30 uint32_t cmd_flags, 31 int dpni_id, 32 uint16_t *token) 33 { 34 struct mc_command cmd = { 0 }; 35 struct dpni_cmd_open *cmd_params; 36 37 int err; 38 39 /* prepare command */ 40 cmd.header = mc_encode_cmd_header(DPNI_CMDID_OPEN, 41 cmd_flags, 42 0); 43 cmd_params = (struct dpni_cmd_open *)cmd.params; 44 cmd_params->dpni_id = cpu_to_le32(dpni_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 * dpni_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 DPNI 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 dpni_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(DPNI_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 * dpni_create() - Create the DPNI 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 DPNI 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 dpni_create(struct fsl_mc_io *mc_io, 106 uint16_t dprc_token, 107 uint32_t cmd_flags, 108 const struct dpni_cfg *cfg, 109 uint32_t *obj_id) 110 { 111 struct dpni_cmd_create *cmd_params; 112 struct mc_command cmd = { 0 }; 113 int err; 114 115 /* prepare command */ 116 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CREATE, 117 cmd_flags, 118 dprc_token); 119 cmd_params = (struct dpni_cmd_create *)cmd.params; 120 cmd_params->options = cpu_to_le32(cfg->options); 121 cmd_params->num_queues = cfg->num_queues; 122 cmd_params->num_tcs = cfg->num_tcs; 123 cmd_params->mac_filter_entries = cfg->mac_filter_entries; 124 cmd_params->num_rx_tcs = cfg->num_rx_tcs; 125 cmd_params->vlan_filter_entries = cfg->vlan_filter_entries; 126 cmd_params->qos_entries = cfg->qos_entries; 127 cmd_params->fs_entries = cpu_to_le16(cfg->fs_entries); 128 cmd_params->num_cgs = cfg->num_cgs; 129 cmd_params->num_opr = cfg->num_opr; 130 cmd_params->dist_key_size = cfg->dist_key_size; 131 cmd_params->num_channels = cfg->num_channels; 132 133 /* send command to mc*/ 134 err = mc_send_command(mc_io, &cmd); 135 if (err) 136 return err; 137 138 /* retrieve response parameters */ 139 *obj_id = mc_cmd_read_object_id(&cmd); 140 141 return 0; 142 } 143 144 /** 145 * dpni_destroy() - Destroy the DPNI object and release all its resources. 146 * @mc_io: Pointer to MC portal's I/O object 147 * @dprc_token: Parent container token; '0' for default container 148 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 149 * @object_id: The object id; it must be a valid id within the container that 150 * created this object; 151 * 152 * The function accepts the authentication token of the parent container that 153 * created the object (not the one that currently owns the object). The object 154 * is searched within parent using the provided 'object_id'. 155 * All tokens to the object must be closed before calling destroy. 156 * 157 * Return: '0' on Success; error code otherwise. 158 */ 159 int dpni_destroy(struct fsl_mc_io *mc_io, 160 uint16_t dprc_token, 161 uint32_t cmd_flags, 162 uint32_t object_id) 163 { 164 struct dpni_cmd_destroy *cmd_params; 165 struct mc_command cmd = { 0 }; 166 167 /* prepare command */ 168 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DESTROY, 169 cmd_flags, 170 dprc_token); 171 /* set object id to destroy */ 172 cmd_params = (struct dpni_cmd_destroy *)cmd.params; 173 cmd_params->dpsw_id = cpu_to_le32(object_id); 174 175 /* send command to mc*/ 176 return mc_send_command(mc_io, &cmd); 177 } 178 179 /** 180 * dpni_set_pools() - Set buffer pools configuration 181 * @mc_io: Pointer to MC portal's I/O object 182 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 183 * @token: Token of DPNI object 184 * @cfg: Buffer pools configuration 185 * 186 * mandatory for DPNI operation 187 * warning:Allowed only when DPNI is disabled 188 * 189 * Return: '0' on Success; Error code otherwise. 190 */ 191 int dpni_set_pools(struct fsl_mc_io *mc_io, 192 uint32_t cmd_flags, 193 uint16_t token, 194 const struct dpni_pools_cfg *cfg) 195 { 196 struct mc_command cmd = { 0 }; 197 struct dpni_cmd_set_pools *cmd_params; 198 int i; 199 200 /* prepare command */ 201 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS, 202 cmd_flags, 203 token); 204 cmd_params = (struct dpni_cmd_set_pools *)cmd.params; 205 cmd_params->num_dpbp = cfg->num_dpbp; 206 cmd_params->pool_options = cfg->pool_options; 207 for (i = 0; i < DPNI_MAX_DPBP; i++) { 208 cmd_params->pool[i].dpbp_id = 209 cpu_to_le16(cfg->pools[i].dpbp_id); 210 cmd_params->pool[i].priority_mask = 211 cfg->pools[i].priority_mask; 212 cmd_params->buffer_size[i] = 213 cpu_to_le16(cfg->pools[i].buffer_size); 214 cmd_params->backup_pool_mask |= 215 DPNI_BACKUP_POOL(cfg->pools[i].backup_pool, i); 216 } 217 218 /* send command to mc*/ 219 return mc_send_command(mc_io, &cmd); 220 } 221 222 /** 223 * dpni_enable() - Enable the DPNI, allow sending and receiving frames. 224 * @mc_io: Pointer to MC portal's I/O object 225 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 226 * @token: Token of DPNI object 227 * 228 * Return: '0' on Success; Error code otherwise. 229 */ 230 int dpni_enable(struct fsl_mc_io *mc_io, 231 uint32_t cmd_flags, 232 uint16_t token) 233 { 234 struct mc_command cmd = { 0 }; 235 236 /* prepare command */ 237 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE, 238 cmd_flags, 239 token); 240 241 /* send command to mc*/ 242 return mc_send_command(mc_io, &cmd); 243 } 244 245 /** 246 * dpni_disable() - Disable the DPNI, stop sending and receiving frames. 247 * @mc_io: Pointer to MC portal's I/O object 248 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 249 * @token: Token of DPNI object 250 * 251 * Return: '0' on Success; Error code otherwise. 252 */ 253 int dpni_disable(struct fsl_mc_io *mc_io, 254 uint32_t cmd_flags, 255 uint16_t token) 256 { 257 struct mc_command cmd = { 0 }; 258 259 /* prepare command */ 260 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE, 261 cmd_flags, 262 token); 263 264 /* send command to mc*/ 265 return mc_send_command(mc_io, &cmd); 266 } 267 268 /** 269 * dpni_is_enabled() - Check if the DPNI is enabled. 270 * @mc_io: Pointer to MC portal's I/O object 271 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 272 * @token: Token of DPNI object 273 * @en: Returns '1' if object is enabled; '0' otherwise 274 * 275 * Return: '0' on Success; Error code otherwise. 276 */ 277 int dpni_is_enabled(struct fsl_mc_io *mc_io, 278 uint32_t cmd_flags, 279 uint16_t token, 280 int *en) 281 { 282 struct mc_command cmd = { 0 }; 283 struct dpni_rsp_is_enabled *rsp_params; 284 int err; 285 286 /* prepare command */ 287 cmd.header = mc_encode_cmd_header(DPNI_CMDID_IS_ENABLED, 288 cmd_flags, 289 token); 290 291 /* send command to mc*/ 292 err = mc_send_command(mc_io, &cmd); 293 if (err) 294 return err; 295 296 /* retrieve response parameters */ 297 rsp_params = (struct dpni_rsp_is_enabled *)cmd.params; 298 *en = dpni_get_field(rsp_params->enabled, ENABLE); 299 300 return 0; 301 } 302 303 /** 304 * dpni_reset() - Reset the DPNI, returns the object to initial state. 305 * @mc_io: Pointer to MC portal's I/O object 306 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 307 * @token: Token of DPNI object 308 * 309 * Return: '0' on Success; Error code otherwise. 310 */ 311 int dpni_reset(struct fsl_mc_io *mc_io, 312 uint32_t cmd_flags, 313 uint16_t token) 314 { 315 struct mc_command cmd = { 0 }; 316 317 /* prepare command */ 318 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET, 319 cmd_flags, 320 token); 321 322 /* send command to mc*/ 323 return mc_send_command(mc_io, &cmd); 324 } 325 326 /** 327 * dpni_set_irq_enable() - Set overall interrupt state. 328 * @mc_io: Pointer to MC portal's I/O object 329 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 330 * @token: Token of DPNI object 331 * @irq_index: The interrupt index to configure 332 * @en: Interrupt state: - enable = 1, disable = 0 333 * 334 * Allows GPP software to control when interrupts are generated. 335 * Each interrupt can have up to 32 causes. The enable/disable control's the 336 * overall interrupt state. if the interrupt is disabled no causes will cause 337 * an interrupt. 338 * 339 * Return: '0' on Success; Error code otherwise. 340 */ 341 int dpni_set_irq_enable(struct fsl_mc_io *mc_io, 342 uint32_t cmd_flags, 343 uint16_t token, 344 uint8_t irq_index, 345 uint8_t en) 346 { 347 struct mc_command cmd = { 0 }; 348 struct dpni_cmd_set_irq_enable *cmd_params; 349 350 /* prepare command */ 351 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_ENABLE, 352 cmd_flags, 353 token); 354 cmd_params = (struct dpni_cmd_set_irq_enable *)cmd.params; 355 dpni_set_field(cmd_params->enable, ENABLE, en); 356 cmd_params->irq_index = irq_index; 357 358 /* send command to mc*/ 359 return mc_send_command(mc_io, &cmd); 360 } 361 362 /** 363 * dpni_get_irq_enable() - Get overall interrupt state 364 * @mc_io: Pointer to MC portal's I/O object 365 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 366 * @token: Token of DPNI object 367 * @irq_index: The interrupt index to configure 368 * @en: Returned interrupt state - enable = 1, disable = 0 369 * 370 * Return: '0' on Success; Error code otherwise. 371 */ 372 int dpni_get_irq_enable(struct fsl_mc_io *mc_io, 373 uint32_t cmd_flags, 374 uint16_t token, 375 uint8_t irq_index, 376 uint8_t *en) 377 { 378 struct mc_command cmd = { 0 }; 379 struct dpni_cmd_get_irq_enable *cmd_params; 380 struct dpni_rsp_get_irq_enable *rsp_params; 381 382 int err; 383 384 /* prepare command */ 385 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_ENABLE, 386 cmd_flags, 387 token); 388 cmd_params = (struct dpni_cmd_get_irq_enable *)cmd.params; 389 cmd_params->irq_index = irq_index; 390 391 /* send command to mc*/ 392 err = mc_send_command(mc_io, &cmd); 393 if (err) 394 return err; 395 396 /* retrieve response parameters */ 397 rsp_params = (struct dpni_rsp_get_irq_enable *)cmd.params; 398 *en = dpni_get_field(rsp_params->enabled, ENABLE); 399 400 return 0; 401 } 402 403 /** 404 * dpni_set_irq_mask() - Set interrupt mask. 405 * @mc_io: Pointer to MC portal's I/O object 406 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 407 * @token: Token of DPNI object 408 * @irq_index: The interrupt index to configure 409 * @mask: Event mask to trigger interrupt; 410 * each bit: 411 * 0 = ignore event 412 * 1 = consider event for asserting IRQ 413 * 414 * Every interrupt can have up to 32 causes and the interrupt model supports 415 * masking/unmasking each cause independently 416 * 417 * Return: '0' on Success; Error code otherwise. 418 */ 419 int dpni_set_irq_mask(struct fsl_mc_io *mc_io, 420 uint32_t cmd_flags, 421 uint16_t token, 422 uint8_t irq_index, 423 uint32_t mask) 424 { 425 struct mc_command cmd = { 0 }; 426 struct dpni_cmd_set_irq_mask *cmd_params; 427 428 /* prepare command */ 429 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_MASK, 430 cmd_flags, 431 token); 432 cmd_params = (struct dpni_cmd_set_irq_mask *)cmd.params; 433 cmd_params->mask = cpu_to_le32(mask); 434 cmd_params->irq_index = irq_index; 435 436 /* send command to mc*/ 437 return mc_send_command(mc_io, &cmd); 438 } 439 440 /** 441 * dpni_get_irq_mask() - Get interrupt mask. 442 * @mc_io: Pointer to MC portal's I/O object 443 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 444 * @token: Token of DPNI object 445 * @irq_index: The interrupt index to configure 446 * @mask: Returned event mask to trigger interrupt 447 * 448 * Every interrupt can have up to 32 causes and the interrupt model supports 449 * masking/unmasking each cause independently 450 * 451 * Return: '0' on Success; Error code otherwise. 452 */ 453 int dpni_get_irq_mask(struct fsl_mc_io *mc_io, 454 uint32_t cmd_flags, 455 uint16_t token, 456 uint8_t irq_index, 457 uint32_t *mask) 458 { 459 struct mc_command cmd = { 0 }; 460 struct dpni_cmd_get_irq_mask *cmd_params; 461 struct dpni_rsp_get_irq_mask *rsp_params; 462 int err; 463 464 /* prepare command */ 465 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_MASK, 466 cmd_flags, 467 token); 468 cmd_params = (struct dpni_cmd_get_irq_mask *)cmd.params; 469 cmd_params->irq_index = irq_index; 470 471 /* send command to mc*/ 472 err = mc_send_command(mc_io, &cmd); 473 if (err) 474 return err; 475 476 /* retrieve response parameters */ 477 rsp_params = (struct dpni_rsp_get_irq_mask *)cmd.params; 478 *mask = le32_to_cpu(rsp_params->mask); 479 480 return 0; 481 } 482 483 /** 484 * dpni_get_irq_status() - Get the current status of any pending interrupts. 485 * @mc_io: Pointer to MC portal's I/O object 486 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 487 * @token: Token of DPNI object 488 * @irq_index: The interrupt index to configure 489 * @status: Returned interrupts status - one bit per cause: 490 * 0 = no interrupt pending 491 * 1 = interrupt pending 492 * 493 * Return: '0' on Success; Error code otherwise. 494 */ 495 int dpni_get_irq_status(struct fsl_mc_io *mc_io, 496 uint32_t cmd_flags, 497 uint16_t token, 498 uint8_t irq_index, 499 uint32_t *status) 500 { 501 struct mc_command cmd = { 0 }; 502 struct dpni_cmd_get_irq_status *cmd_params; 503 struct dpni_rsp_get_irq_status *rsp_params; 504 int err; 505 506 /* prepare command */ 507 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_STATUS, 508 cmd_flags, 509 token); 510 cmd_params = (struct dpni_cmd_get_irq_status *)cmd.params; 511 cmd_params->status = cpu_to_le32(*status); 512 cmd_params->irq_index = irq_index; 513 514 /* send command to mc*/ 515 err = mc_send_command(mc_io, &cmd); 516 if (err) 517 return err; 518 519 /* retrieve response parameters */ 520 rsp_params = (struct dpni_rsp_get_irq_status *)cmd.params; 521 *status = le32_to_cpu(rsp_params->status); 522 523 return 0; 524 } 525 526 /** 527 * dpni_clear_irq_status() - Clear a pending interrupt's status 528 * @mc_io: Pointer to MC portal's I/O object 529 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 530 * @token: Token of DPNI object 531 * @irq_index: The interrupt index to configure 532 * @status: bits to clear (W1C) - one bit per cause: 533 * 0 = don't change 534 * 1 = clear status bit 535 * 536 * Return: '0' on Success; Error code otherwise. 537 */ 538 int dpni_clear_irq_status(struct fsl_mc_io *mc_io, 539 uint32_t cmd_flags, 540 uint16_t token, 541 uint8_t irq_index, 542 uint32_t status) 543 { 544 struct mc_command cmd = { 0 }; 545 struct dpni_cmd_clear_irq_status *cmd_params; 546 547 /* prepare command */ 548 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLEAR_IRQ_STATUS, 549 cmd_flags, 550 token); 551 cmd_params = (struct dpni_cmd_clear_irq_status *)cmd.params; 552 cmd_params->irq_index = irq_index; 553 cmd_params->status = cpu_to_le32(status); 554 555 /* send command to mc*/ 556 return mc_send_command(mc_io, &cmd); 557 } 558 559 /** 560 * dpni_get_attributes() - Retrieve DPNI attributes. 561 * @mc_io: Pointer to MC portal's I/O object 562 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 563 * @token: Token of DPNI object 564 * @attr: Object's attributes 565 * 566 * Return: '0' on Success; Error code otherwise. 567 */ 568 int dpni_get_attributes(struct fsl_mc_io *mc_io, 569 uint32_t cmd_flags, 570 uint16_t token, 571 struct dpni_attr *attr) 572 { 573 struct mc_command cmd = { 0 }; 574 struct dpni_rsp_get_attr *rsp_params; 575 576 int err; 577 578 /* prepare command */ 579 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR, 580 cmd_flags, 581 token); 582 583 /* send command to mc*/ 584 err = mc_send_command(mc_io, &cmd); 585 if (err) 586 return err; 587 588 /* retrieve response parameters */ 589 rsp_params = (struct dpni_rsp_get_attr *)cmd.params; 590 attr->options = le32_to_cpu(rsp_params->options); 591 attr->num_queues = rsp_params->num_queues; 592 attr->num_rx_tcs = rsp_params->num_rx_tcs; 593 attr->num_tx_tcs = rsp_params->num_tx_tcs; 594 attr->mac_filter_entries = rsp_params->mac_filter_entries; 595 attr->vlan_filter_entries = rsp_params->vlan_filter_entries; 596 attr->num_channels = rsp_params->num_channels; 597 attr->qos_entries = rsp_params->qos_entries; 598 attr->fs_entries = le16_to_cpu(rsp_params->fs_entries); 599 attr->num_opr = le16_to_cpu(rsp_params->num_opr); 600 attr->qos_key_size = rsp_params->qos_key_size; 601 attr->fs_key_size = rsp_params->fs_key_size; 602 attr->wriop_version = le16_to_cpu(rsp_params->wriop_version); 603 attr->num_cgs = rsp_params->num_cgs; 604 605 return 0; 606 } 607 608 /** 609 * dpni_set_errors_behavior() - Set errors behavior 610 * @mc_io: Pointer to MC portal's I/O object 611 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 612 * @token: Token of DPNI object 613 * @cfg: Errors configuration 614 * 615 * This function may be called numerous times with different 616 * error masks 617 * 618 * Return: '0' on Success; Error code otherwise. 619 */ 620 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io, 621 uint32_t cmd_flags, 622 uint16_t token, 623 struct dpni_error_cfg *cfg) 624 { 625 struct mc_command cmd = { 0 }; 626 struct dpni_cmd_set_errors_behavior *cmd_params; 627 628 /* prepare command */ 629 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR, 630 cmd_flags, 631 token); 632 cmd_params = (struct dpni_cmd_set_errors_behavior *)cmd.params; 633 cmd_params->errors = cpu_to_le32(cfg->errors); 634 dpni_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action); 635 dpni_set_field(cmd_params->flags, FRAME_ANN, cfg->set_frame_annotation); 636 637 /* send command to mc*/ 638 return mc_send_command(mc_io, &cmd); 639 } 640 641 /** 642 * dpni_get_buffer_layout() - Retrieve buffer layout attributes. 643 * @mc_io: Pointer to MC portal's I/O object 644 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 645 * @token: Token of DPNI object 646 * @qtype: Type of queue to retrieve configuration for 647 * @layout: Returns buffer layout attributes 648 * 649 * Return: '0' on Success; Error code otherwise. 650 */ 651 int dpni_get_buffer_layout(struct fsl_mc_io *mc_io, 652 uint32_t cmd_flags, 653 uint16_t token, 654 enum dpni_queue_type qtype, 655 struct dpni_buffer_layout *layout) 656 { 657 struct mc_command cmd = { 0 }; 658 struct dpni_cmd_get_buffer_layout *cmd_params; 659 struct dpni_rsp_get_buffer_layout *rsp_params; 660 int err; 661 662 /* prepare command */ 663 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_BUFFER_LAYOUT, 664 cmd_flags, 665 token); 666 cmd_params = (struct dpni_cmd_get_buffer_layout *)cmd.params; 667 cmd_params->qtype = qtype; 668 669 /* send command to mc*/ 670 err = mc_send_command(mc_io, &cmd); 671 if (err) 672 return err; 673 674 /* retrieve response parameters */ 675 rsp_params = (struct dpni_rsp_get_buffer_layout *)cmd.params; 676 layout->pass_timestamp = 677 (int)dpni_get_field(rsp_params->flags, PASS_TS); 678 layout->pass_parser_result = 679 (int)dpni_get_field(rsp_params->flags, PASS_PR); 680 layout->pass_frame_status = 681 (int)dpni_get_field(rsp_params->flags, PASS_FS); 682 layout->pass_sw_opaque = 683 (int)dpni_get_field(rsp_params->flags, PASS_SWO); 684 layout->private_data_size = le16_to_cpu(rsp_params->private_data_size); 685 layout->data_align = le16_to_cpu(rsp_params->data_align); 686 layout->data_head_room = le16_to_cpu(rsp_params->head_room); 687 layout->data_tail_room = le16_to_cpu(rsp_params->tail_room); 688 689 return 0; 690 } 691 692 /** 693 * dpni_set_buffer_layout() - Set buffer layout configuration. 694 * @mc_io: Pointer to MC portal's I/O object 695 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 696 * @token: Token of DPNI object 697 * @qtype: Type of queue this configuration applies to 698 * @layout: Buffer layout configuration 699 * 700 * Return: '0' on Success; Error code otherwise. 701 * 702 * @warning Allowed only when DPNI is disabled 703 */ 704 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io, 705 uint32_t cmd_flags, 706 uint16_t token, 707 enum dpni_queue_type qtype, 708 const struct dpni_buffer_layout *layout) 709 { 710 struct mc_command cmd = { 0 }; 711 struct dpni_cmd_set_buffer_layout *cmd_params; 712 713 /* prepare command */ 714 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT, 715 cmd_flags, 716 token); 717 cmd_params = (struct dpni_cmd_set_buffer_layout *)cmd.params; 718 cmd_params->qtype = qtype; 719 cmd_params->options = cpu_to_le16((uint16_t)layout->options); 720 dpni_set_field(cmd_params->flags, PASS_TS, layout->pass_timestamp); 721 dpni_set_field(cmd_params->flags, PASS_PR, layout->pass_parser_result); 722 dpni_set_field(cmd_params->flags, PASS_FS, layout->pass_frame_status); 723 dpni_set_field(cmd_params->flags, PASS_SWO, layout->pass_sw_opaque); 724 cmd_params->private_data_size = cpu_to_le16(layout->private_data_size); 725 cmd_params->data_align = cpu_to_le16(layout->data_align); 726 cmd_params->head_room = cpu_to_le16(layout->data_head_room); 727 cmd_params->tail_room = cpu_to_le16(layout->data_tail_room); 728 729 /* send command to mc*/ 730 return mc_send_command(mc_io, &cmd); 731 } 732 733 /** 734 * dpni_set_offload() - Set DPNI offload configuration. 735 * @mc_io: Pointer to MC portal's I/O object 736 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 737 * @token: Token of DPNI object 738 * @type: Type of DPNI offload 739 * @config: Offload configuration. 740 * For checksum offloads, non-zero value enables the offload 741 * 742 * Return: '0' on Success; Error code otherwise. 743 * 744 * @warning Allowed only when DPNI is disabled 745 */ 746 747 int dpni_set_offload(struct fsl_mc_io *mc_io, 748 uint32_t cmd_flags, 749 uint16_t token, 750 enum dpni_offload type, 751 uint32_t config) 752 { 753 struct mc_command cmd = { 0 }; 754 struct dpni_cmd_set_offload *cmd_params; 755 756 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD, 757 cmd_flags, 758 token); 759 cmd_params = (struct dpni_cmd_set_offload *)cmd.params; 760 cmd_params->dpni_offload = type; 761 cmd_params->config = cpu_to_le32(config); 762 763 return mc_send_command(mc_io, &cmd); 764 } 765 766 /** 767 * dpni_get_offload() - Get DPNI offload configuration. 768 * @mc_io: Pointer to MC portal's I/O object 769 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 770 * @token: Token of DPNI object 771 * @type: Type of DPNI offload 772 * @config: Offload configuration. 773 * For checksum offloads, a value of 1 indicates that the 774 * offload is enabled. 775 * 776 * Return: '0' on Success; Error code otherwise. 777 * 778 * @warning Allowed only when DPNI is disabled 779 */ 780 int dpni_get_offload(struct fsl_mc_io *mc_io, 781 uint32_t cmd_flags, 782 uint16_t token, 783 enum dpni_offload type, 784 uint32_t *config) 785 { 786 struct mc_command cmd = { 0 }; 787 struct dpni_cmd_get_offload *cmd_params; 788 struct dpni_rsp_get_offload *rsp_params; 789 int err; 790 791 /* prepare command */ 792 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OFFLOAD, 793 cmd_flags, 794 token); 795 cmd_params = (struct dpni_cmd_get_offload *)cmd.params; 796 cmd_params->dpni_offload = type; 797 798 /* send command to mc*/ 799 err = mc_send_command(mc_io, &cmd); 800 if (err) 801 return err; 802 803 /* retrieve response parameters */ 804 rsp_params = (struct dpni_rsp_get_offload *)cmd.params; 805 *config = le32_to_cpu(rsp_params->config); 806 807 return 0; 808 } 809 810 /** 811 * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used 812 * for enqueue operations 813 * @mc_io: Pointer to MC portal's I/O object 814 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 815 * @token: Token of DPNI object 816 * @qtype: Type of queue to receive QDID for 817 * @qdid: Returned virtual QDID value that should be used as an argument 818 * in all enqueue operations 819 * 820 * Return: '0' on Success; Error code otherwise. 821 * 822 * If dpni object is created using multiple Tc channels this function will return 823 * qdid value for the first channel 824 */ 825 int dpni_get_qdid(struct fsl_mc_io *mc_io, 826 uint32_t cmd_flags, 827 uint16_t token, 828 enum dpni_queue_type qtype, 829 uint16_t *qdid) 830 { 831 struct mc_command cmd = { 0 }; 832 struct dpni_cmd_get_qdid *cmd_params; 833 struct dpni_rsp_get_qdid *rsp_params; 834 int err; 835 836 /* prepare command */ 837 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID, 838 cmd_flags, 839 token); 840 cmd_params = (struct dpni_cmd_get_qdid *)cmd.params; 841 cmd_params->qtype = qtype; 842 843 /* send command to mc*/ 844 err = mc_send_command(mc_io, &cmd); 845 if (err) 846 return err; 847 848 /* retrieve response parameters */ 849 rsp_params = (struct dpni_rsp_get_qdid *)cmd.params; 850 *qdid = le16_to_cpu(rsp_params->qdid); 851 852 return 0; 853 } 854 855 /** 856 * dpni_get_qdid_ex() - Extension for the function to get the Queuing Destination ID (QDID) 857 * that should be used for enqueue operations. 858 * @mc_io: Pointer to MC portal's I/O object 859 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 860 * @token: Token of DPNI object 861 * @qtype: Type of queue to receive QDID for 862 * @qdid: Array of virtual QDID value that should be used as an argument 863 * in all enqueue operations. 864 * 865 * Return: '0' on Success; Error code otherwise. 866 * 867 * This function must be used when dpni is created using multiple Tx channels to return one 868 * qdid for each channel. 869 */ 870 int dpni_get_qdid_ex(struct fsl_mc_io *mc_io, 871 uint32_t cmd_flags, 872 uint16_t token, 873 enum dpni_queue_type qtype, 874 uint16_t *qdid) 875 { 876 struct mc_command cmd = { 0 }; 877 struct dpni_cmd_get_qdid *cmd_params; 878 struct dpni_rsp_get_qdid_ex *rsp_params; 879 int i; 880 int err; 881 882 /* prepare command */ 883 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID_EX, 884 cmd_flags, 885 token); 886 cmd_params = (struct dpni_cmd_get_qdid *)cmd.params; 887 cmd_params->qtype = qtype; 888 889 /* send command to mc*/ 890 err = mc_send_command(mc_io, &cmd); 891 if (err) 892 return err; 893 894 /* retrieve response parameters */ 895 rsp_params = (struct dpni_rsp_get_qdid_ex *)cmd.params; 896 for (i = 0; i < DPNI_MAX_CHANNELS; i++) 897 qdid[i] = le16_to_cpu(rsp_params->qdid[i]); 898 899 return 0; 900 } 901 902 /** 903 * dpni_get_sp_info() - Get the AIOP storage profile IDs associated 904 * with the DPNI 905 * @mc_io: Pointer to MC portal's I/O object 906 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 907 * @token: Token of DPNI object 908 * @sp_info: Returned AIOP storage-profile information 909 * 910 * Return: '0' on Success; Error code otherwise. 911 * 912 * @warning Only relevant for DPNI that belongs to AIOP container. 913 */ 914 int dpni_get_sp_info(struct fsl_mc_io *mc_io, 915 uint32_t cmd_flags, 916 uint16_t token, 917 struct dpni_sp_info *sp_info) 918 { 919 struct dpni_rsp_get_sp_info *rsp_params; 920 struct mc_command cmd = { 0 }; 921 int err, i; 922 923 /* prepare command */ 924 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_SP_INFO, 925 cmd_flags, 926 token); 927 928 /* send command to mc*/ 929 err = mc_send_command(mc_io, &cmd); 930 if (err) 931 return err; 932 933 /* retrieve response parameters */ 934 rsp_params = (struct dpni_rsp_get_sp_info *)cmd.params; 935 for (i = 0; i < DPNI_MAX_SP; i++) 936 sp_info->spids[i] = le16_to_cpu(rsp_params->spids[i]); 937 938 return 0; 939 } 940 941 /** 942 * dpni_get_tx_data_offset() - Get the Tx data offset (from start of buffer) 943 * @mc_io: Pointer to MC portal's I/O object 944 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 945 * @token: Token of DPNI object 946 * @data_offset: Tx data offset (from start of buffer) 947 * 948 * Return: '0' on Success; Error code otherwise. 949 */ 950 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io, 951 uint32_t cmd_flags, 952 uint16_t token, 953 uint16_t *data_offset) 954 { 955 struct mc_command cmd = { 0 }; 956 struct dpni_rsp_get_tx_data_offset *rsp_params; 957 int err; 958 959 /* prepare command */ 960 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET, 961 cmd_flags, 962 token); 963 964 /* send command to mc*/ 965 err = mc_send_command(mc_io, &cmd); 966 if (err) 967 return err; 968 969 /* retrieve response parameters */ 970 rsp_params = (struct dpni_rsp_get_tx_data_offset *)cmd.params; 971 *data_offset = le16_to_cpu(rsp_params->data_offset); 972 973 return 0; 974 } 975 976 /** 977 * dpni_set_link_cfg() - set the link configuration. 978 * @mc_io: Pointer to MC portal's I/O object 979 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 980 * @token: Token of DPNI object 981 * @cfg: Link configuration 982 * 983 * Return: '0' on Success; Error code otherwise. 984 */ 985 int dpni_set_link_cfg(struct fsl_mc_io *mc_io, 986 uint32_t cmd_flags, 987 uint16_t token, 988 const struct dpni_link_cfg *cfg) 989 { 990 struct mc_command cmd = { 0 }; 991 struct dpni_cmd_set_link_cfg *cmd_params; 992 993 /* prepare command */ 994 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG, 995 cmd_flags, 996 token); 997 cmd_params = (struct dpni_cmd_set_link_cfg *)cmd.params; 998 cmd_params->rate = cpu_to_le32(cfg->rate); 999 cmd_params->options = cpu_to_le64(cfg->options); 1000 cmd_params->advertising = cpu_to_le64(cfg->advertising); 1001 1002 /* send command to mc*/ 1003 return mc_send_command(mc_io, &cmd); 1004 } 1005 1006 /** 1007 * dpni_get_link_cfg() - return the link configuration configured by 1008 * dpni_set_link_cfg(). 1009 * @mc_io: Pointer to MC portal's I/O object 1010 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1011 * @token: Token of DPNI object 1012 * @cfg: Link configuration from dpni object 1013 * 1014 * Return: '0' on Success; Error code otherwise. 1015 */ 1016 int dpni_get_link_cfg(struct fsl_mc_io *mc_io, 1017 uint32_t cmd_flags, 1018 uint16_t token, 1019 struct dpni_link_cfg *cfg) 1020 { 1021 struct mc_command cmd = { 0 }; 1022 struct dpni_cmd_set_link_cfg *rsp_params; 1023 int err; 1024 1025 /* prepare command */ 1026 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_CFG, 1027 cmd_flags, 1028 token); 1029 1030 /* send command to mc*/ 1031 err = mc_send_command(mc_io, &cmd); 1032 if (err) 1033 return err; 1034 1035 /* retrieve response parameters */ 1036 rsp_params = (struct dpni_cmd_set_link_cfg *)cmd.params; 1037 cfg->advertising = le64_to_cpu(rsp_params->advertising); 1038 cfg->options = le64_to_cpu(rsp_params->options); 1039 cfg->rate = le32_to_cpu(rsp_params->rate); 1040 1041 return err; 1042 } 1043 1044 /** 1045 * dpni_get_link_state() - Return the link state (either up or down) 1046 * @mc_io: Pointer to MC portal's I/O object 1047 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1048 * @token: Token of DPNI object 1049 * @state: Returned link state; 1050 * 1051 * Return: '0' on Success; Error code otherwise. 1052 */ 1053 int dpni_get_link_state(struct fsl_mc_io *mc_io, 1054 uint32_t cmd_flags, 1055 uint16_t token, 1056 struct dpni_link_state *state) 1057 { 1058 struct mc_command cmd = { 0 }; 1059 struct dpni_rsp_get_link_state *rsp_params; 1060 int err; 1061 1062 /* prepare command */ 1063 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE, 1064 cmd_flags, 1065 token); 1066 1067 /* send command to mc*/ 1068 err = mc_send_command(mc_io, &cmd); 1069 if (err) 1070 return err; 1071 1072 /* retrieve response parameters */ 1073 rsp_params = (struct dpni_rsp_get_link_state *)cmd.params; 1074 state->up = dpni_get_field(rsp_params->flags, LINK_STATE); 1075 state->state_valid = dpni_get_field(rsp_params->flags, STATE_VALID); 1076 state->rate = le32_to_cpu(rsp_params->rate); 1077 state->options = le64_to_cpu(rsp_params->options); 1078 state->supported = le64_to_cpu(rsp_params->supported); 1079 state->advertising = le64_to_cpu(rsp_params->advertising); 1080 1081 return 0; 1082 } 1083 1084 /** 1085 * dpni_set_tx_shaping() - Set the transmit shaping 1086 * @mc_io: Pointer to MC portal's I/O object 1087 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1088 * @token: Token of DPNI object 1089 * @tx_cr_shaper: TX committed rate shaping configuration 1090 * @tx_er_shaper: TX excess rate shaping configuration 1091 * @param: Special parameters 1092 * bit0: Committed and excess rates are coupled 1093 * bit1: 1 modify LNI shaper, 0 modify channel shaper 1094 * bit8-15: Tx channel to be shaped. Used only if bit1 is set to zero 1095 * bits16-26: OAL (Overhead accounting length 11bit value). Used only 1096 * when bit1 is set. 1097 * 1098 * Return: '0' on Success; Error code otherwise. 1099 */ 1100 int dpni_set_tx_shaping(struct fsl_mc_io *mc_io, 1101 uint32_t cmd_flags, 1102 uint16_t token, 1103 const struct dpni_tx_shaping_cfg *tx_cr_shaper, 1104 const struct dpni_tx_shaping_cfg *tx_er_shaper, 1105 uint32_t param) 1106 { 1107 struct dpni_cmd_set_tx_shaping *cmd_params; 1108 struct mc_command cmd = { 0 }; 1109 int coupled, lni_shaper; 1110 uint8_t channel_id; 1111 uint16_t oal; 1112 1113 /* prepare command */ 1114 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_SHAPING, 1115 cmd_flags, 1116 token); 1117 cmd_params = (struct dpni_cmd_set_tx_shaping *)cmd.params; 1118 cmd_params->tx_cr_max_burst_size = 1119 cpu_to_le16(tx_cr_shaper->max_burst_size); 1120 cmd_params->tx_er_max_burst_size = 1121 cpu_to_le16(tx_er_shaper->max_burst_size); 1122 cmd_params->tx_cr_rate_limit = 1123 cpu_to_le32(tx_cr_shaper->rate_limit); 1124 cmd_params->tx_er_rate_limit = 1125 cpu_to_le32(tx_er_shaper->rate_limit); 1126 1127 coupled = !!(param & 0x01); 1128 dpni_set_field(cmd_params->options, COUPLED, coupled); 1129 1130 lni_shaper = !!((param >> 1) & 0x01); 1131 dpni_set_field(cmd_params->options, LNI_SHAPER, lni_shaper); 1132 1133 channel_id = (param >> 8) & 0xff; 1134 cmd_params->channel_id = channel_id; 1135 1136 oal = (param >> 16) & 0x7FF; 1137 cmd_params->oal = cpu_to_le16(oal); 1138 1139 /* send command to mc*/ 1140 return mc_send_command(mc_io, &cmd); 1141 } 1142 1143 /** 1144 * dpni_set_max_frame_length() - Set the maximum received frame length. 1145 * @mc_io: Pointer to MC portal's I/O object 1146 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1147 * @token: Token of DPNI object 1148 * @max_frame_length: Maximum received frame length (in bytes); 1149 * frame is discarded if its length exceeds this value 1150 * 1151 * Return: '0' on Success; Error code otherwise. 1152 */ 1153 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io, 1154 uint32_t cmd_flags, 1155 uint16_t token, 1156 uint16_t max_frame_length) 1157 { 1158 struct mc_command cmd = { 0 }; 1159 struct dpni_cmd_set_max_frame_length *cmd_params; 1160 1161 /* prepare command */ 1162 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH, 1163 cmd_flags, 1164 token); 1165 cmd_params = (struct dpni_cmd_set_max_frame_length *)cmd.params; 1166 cmd_params->max_frame_length = cpu_to_le16(max_frame_length); 1167 1168 /* send command to mc*/ 1169 return mc_send_command(mc_io, &cmd); 1170 } 1171 1172 /** 1173 * dpni_get_max_frame_length() - Get the maximum received frame length. 1174 * @mc_io: Pointer to MC portal's I/O object 1175 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1176 * @token: Token of DPNI object 1177 * @max_frame_length: Maximum received frame length (in bytes); 1178 * frame is discarded if its length exceeds this value 1179 * 1180 * Return: '0' on Success; Error code otherwise. 1181 */ 1182 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io, 1183 uint32_t cmd_flags, 1184 uint16_t token, 1185 uint16_t *max_frame_length) 1186 { 1187 struct mc_command cmd = { 0 }; 1188 struct dpni_rsp_get_max_frame_length *rsp_params; 1189 int err; 1190 1191 /* prepare command */ 1192 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH, 1193 cmd_flags, 1194 token); 1195 1196 /* send command to mc*/ 1197 err = mc_send_command(mc_io, &cmd); 1198 if (err) 1199 return err; 1200 1201 /* retrieve response parameters */ 1202 rsp_params = (struct dpni_rsp_get_max_frame_length *)cmd.params; 1203 *max_frame_length = le16_to_cpu(rsp_params->max_frame_length); 1204 1205 return 0; 1206 } 1207 1208 /** 1209 * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode 1210 * @mc_io: Pointer to MC portal's I/O object 1211 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1212 * @token: Token of DPNI object 1213 * @en: Set to '1' to enable; '0' to disable 1214 * 1215 * Return: '0' on Success; Error code otherwise. 1216 */ 1217 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io, 1218 uint32_t cmd_flags, 1219 uint16_t token, 1220 int en) 1221 { 1222 struct mc_command cmd = { 0 }; 1223 struct dpni_cmd_set_multicast_promisc *cmd_params; 1224 1225 /* prepare command */ 1226 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC, 1227 cmd_flags, 1228 token); 1229 cmd_params = (struct dpni_cmd_set_multicast_promisc *)cmd.params; 1230 dpni_set_field(cmd_params->enable, ENABLE, en); 1231 1232 /* send command to mc*/ 1233 return mc_send_command(mc_io, &cmd); 1234 } 1235 1236 /** 1237 * dpni_get_multicast_promisc() - Get multicast promiscuous mode 1238 * @mc_io: Pointer to MC portal's I/O object 1239 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1240 * @token: Token of DPNI object 1241 * @en: Returns '1' if enabled; '0' otherwise 1242 * 1243 * Return: '0' on Success; Error code otherwise. 1244 */ 1245 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io, 1246 uint32_t cmd_flags, 1247 uint16_t token, 1248 int *en) 1249 { 1250 struct mc_command cmd = { 0 }; 1251 struct dpni_rsp_get_multicast_promisc *rsp_params; 1252 int err; 1253 1254 /* prepare command */ 1255 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC, 1256 cmd_flags, 1257 token); 1258 1259 /* send command to mc*/ 1260 err = mc_send_command(mc_io, &cmd); 1261 if (err) 1262 return err; 1263 1264 /* retrieve response parameters */ 1265 rsp_params = (struct dpni_rsp_get_multicast_promisc *)cmd.params; 1266 *en = dpni_get_field(rsp_params->enabled, ENABLE); 1267 1268 return 0; 1269 } 1270 1271 /** 1272 * dpni_set_unicast_promisc() - Enable/disable unicast promiscuous mode 1273 * @mc_io: Pointer to MC portal's I/O object 1274 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1275 * @token: Token of DPNI object 1276 * @en: Set to '1' to enable; '0' to disable 1277 * 1278 * Return: '0' on Success; Error code otherwise. 1279 */ 1280 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io, 1281 uint32_t cmd_flags, 1282 uint16_t token, 1283 int en) 1284 { 1285 struct mc_command cmd = { 0 }; 1286 struct dpni_cmd_set_unicast_promisc *cmd_params; 1287 1288 /* prepare command */ 1289 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC, 1290 cmd_flags, 1291 token); 1292 cmd_params = (struct dpni_cmd_set_unicast_promisc *)cmd.params; 1293 dpni_set_field(cmd_params->enable, ENABLE, en); 1294 1295 /* send command to mc*/ 1296 return mc_send_command(mc_io, &cmd); 1297 } 1298 1299 /** 1300 * dpni_get_unicast_promisc() - Get unicast promiscuous mode 1301 * @mc_io: Pointer to MC portal's I/O object 1302 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1303 * @token: Token of DPNI object 1304 * @en: Returns '1' if enabled; '0' otherwise 1305 * 1306 * Return: '0' on Success; Error code otherwise. 1307 */ 1308 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io, 1309 uint32_t cmd_flags, 1310 uint16_t token, 1311 int *en) 1312 { 1313 struct mc_command cmd = { 0 }; 1314 struct dpni_rsp_get_unicast_promisc *rsp_params; 1315 int err; 1316 1317 /* prepare command */ 1318 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC, 1319 cmd_flags, 1320 token); 1321 1322 /* send command to mc*/ 1323 err = mc_send_command(mc_io, &cmd); 1324 if (err) 1325 return err; 1326 1327 /* retrieve response parameters */ 1328 rsp_params = (struct dpni_rsp_get_unicast_promisc *)cmd.params; 1329 *en = dpni_get_field(rsp_params->enabled, ENABLE); 1330 1331 return 0; 1332 } 1333 1334 /** 1335 * dpni_set_primary_mac_addr() - Set the primary MAC address 1336 * @mc_io: Pointer to MC portal's I/O object 1337 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1338 * @token: Token of DPNI object 1339 * @mac_addr: MAC address to set as primary address 1340 * 1341 * Return: '0' on Success; Error code otherwise. 1342 */ 1343 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io, 1344 uint32_t cmd_flags, 1345 uint16_t token, 1346 const uint8_t mac_addr[6]) 1347 { 1348 struct mc_command cmd = { 0 }; 1349 struct dpni_cmd_set_primary_mac_addr *cmd_params; 1350 int i; 1351 1352 /* prepare command */ 1353 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC, 1354 cmd_flags, 1355 token); 1356 cmd_params = (struct dpni_cmd_set_primary_mac_addr *)cmd.params; 1357 for (i = 0; i < 6; i++) 1358 cmd_params->mac_addr[i] = mac_addr[5 - i]; 1359 1360 /* send command to mc*/ 1361 return mc_send_command(mc_io, &cmd); 1362 } 1363 1364 /** 1365 * dpni_get_primary_mac_addr() - Get the primary MAC address 1366 * @mc_io: Pointer to MC portal's I/O object 1367 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1368 * @token: Token of DPNI object 1369 * @mac_addr: Returned MAC address 1370 * 1371 * Return: '0' on Success; Error code otherwise. 1372 */ 1373 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io, 1374 uint32_t cmd_flags, 1375 uint16_t token, 1376 uint8_t mac_addr[6]) 1377 { 1378 struct mc_command cmd = { 0 }; 1379 struct dpni_rsp_get_primary_mac_addr *rsp_params; 1380 int i, err; 1381 1382 /* prepare command */ 1383 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC, 1384 cmd_flags, 1385 token); 1386 1387 /* send command to mc*/ 1388 err = mc_send_command(mc_io, &cmd); 1389 if (err) 1390 return err; 1391 1392 /* retrieve response parameters */ 1393 rsp_params = (struct dpni_rsp_get_primary_mac_addr *)cmd.params; 1394 for (i = 0; i < 6; i++) 1395 mac_addr[5 - i] = rsp_params->mac_addr[i]; 1396 1397 return 0; 1398 } 1399 1400 /** 1401 * dpni_add_mac_addr() - Add MAC address filter 1402 * @mc_io: Pointer to MC portal's I/O object 1403 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1404 * @token: Token of DPNI object 1405 * @mac_addr: MAC address to add 1406 * @flags : 0 - tc_id and flow_id will be ignored. 1407 * Pkt with this mac_id will be passed to the next 1408 * classification stages 1409 * DPNI_MAC_SET_QUEUE_ACTION 1410 * Pkt with this mac will be forward directly to 1411 * queue defined by the tc_id and flow_id 1412 * @tc_id : Traffic class selection (0-7) 1413 * @flow_id : Selects the specific queue out of the set allocated for the 1414 * same as tc_id. Value must be in range 0 to NUM_QUEUES - 1 1415 * Return: '0' on Success; Error code otherwise. 1416 */ 1417 int dpni_add_mac_addr(struct fsl_mc_io *mc_io, 1418 uint32_t cmd_flags, 1419 uint16_t token, 1420 const uint8_t mac_addr[6], 1421 uint8_t flags, 1422 uint8_t tc_id, 1423 uint8_t flow_id) 1424 { 1425 struct mc_command cmd = { 0 }; 1426 struct dpni_cmd_add_mac_addr *cmd_params; 1427 int i; 1428 1429 /* prepare command */ 1430 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR, 1431 cmd_flags, 1432 token); 1433 cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params; 1434 cmd_params->flags = flags; 1435 cmd_params->tc_id = tc_id; 1436 cmd_params->fq_id = flow_id; 1437 1438 for (i = 0; i < 6; i++) 1439 cmd_params->mac_addr[i] = mac_addr[5 - i]; 1440 1441 /* send command to mc*/ 1442 return mc_send_command(mc_io, &cmd); 1443 } 1444 1445 /** 1446 * dpni_remove_mac_addr() - Remove MAC address filter 1447 * @mc_io: Pointer to MC portal's I/O object 1448 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1449 * @token: Token of DPNI object 1450 * @mac_addr: MAC address to remove 1451 * 1452 * Return: '0' on Success; Error code otherwise. 1453 */ 1454 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io, 1455 uint32_t cmd_flags, 1456 uint16_t token, 1457 const uint8_t mac_addr[6]) 1458 { 1459 struct mc_command cmd = { 0 }; 1460 struct dpni_cmd_remove_mac_addr *cmd_params; 1461 int i; 1462 1463 /* prepare command */ 1464 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR, 1465 cmd_flags, 1466 token); 1467 cmd_params = (struct dpni_cmd_remove_mac_addr *)cmd.params; 1468 for (i = 0; i < 6; i++) 1469 cmd_params->mac_addr[i] = mac_addr[5 - i]; 1470 1471 /* send command to mc*/ 1472 return mc_send_command(mc_io, &cmd); 1473 } 1474 1475 /** 1476 * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters 1477 * @mc_io: Pointer to MC portal's I/O object 1478 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1479 * @token: Token of DPNI object 1480 * @unicast: Set to '1' to clear unicast addresses 1481 * @multicast: Set to '1' to clear multicast addresses 1482 * 1483 * The primary MAC address is not cleared by this operation. 1484 * 1485 * Return: '0' on Success; Error code otherwise. 1486 */ 1487 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io, 1488 uint32_t cmd_flags, 1489 uint16_t token, 1490 int unicast, 1491 int multicast) 1492 { 1493 struct mc_command cmd = { 0 }; 1494 struct dpni_cmd_clear_mac_filters *cmd_params; 1495 1496 /* prepare command */ 1497 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS, 1498 cmd_flags, 1499 token); 1500 cmd_params = (struct dpni_cmd_clear_mac_filters *)cmd.params; 1501 dpni_set_field(cmd_params->flags, UNICAST_FILTERS, unicast); 1502 dpni_set_field(cmd_params->flags, MULTICAST_FILTERS, multicast); 1503 1504 /* send command to mc*/ 1505 return mc_send_command(mc_io, &cmd); 1506 } 1507 1508 /** 1509 * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical 1510 * port the DPNI is attached to 1511 * @mc_io: Pointer to MC portal's I/O object 1512 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1513 * @token: Token of DPNI object 1514 * @mac_addr: MAC address of the physical port, if any, otherwise 0 1515 * 1516 * The primary MAC address is not cleared by this operation. 1517 * 1518 * Return: '0' on Success; Error code otherwise. 1519 */ 1520 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io, 1521 uint32_t cmd_flags, 1522 uint16_t token, 1523 uint8_t mac_addr[6]) 1524 { 1525 struct mc_command cmd = { 0 }; 1526 struct dpni_rsp_get_port_mac_addr *rsp_params; 1527 int i, err; 1528 1529 /* prepare command */ 1530 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR, 1531 cmd_flags, 1532 token); 1533 1534 /* send command to mc*/ 1535 err = mc_send_command(mc_io, &cmd); 1536 if (err) 1537 return err; 1538 1539 /* retrieve response parameters */ 1540 rsp_params = (struct dpni_rsp_get_port_mac_addr *)cmd.params; 1541 for (i = 0; i < 6; i++) 1542 mac_addr[5 - i] = rsp_params->mac_addr[i]; 1543 1544 return 0; 1545 } 1546 1547 /** 1548 * dpni_enable_vlan_filter() - Enable/disable VLAN filtering mode 1549 * @mc_io: Pointer to MC portal's I/O object 1550 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1551 * @token: Token of DPNI object 1552 * @en: Set to '1' to enable; '0' to disable 1553 * 1554 * Return: '0' on Success; Error code otherwise. 1555 */ 1556 int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io, 1557 uint32_t cmd_flags, 1558 uint16_t token, 1559 int en) 1560 { 1561 struct dpni_cmd_enable_vlan_filter *cmd_params; 1562 struct mc_command cmd = { 0 }; 1563 1564 /* prepare command */ 1565 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_VLAN_FILTER, 1566 cmd_flags, 1567 token); 1568 cmd_params = (struct dpni_cmd_enable_vlan_filter *)cmd.params; 1569 dpni_set_field(cmd_params->en, ENABLE, en); 1570 1571 /* send command to mc*/ 1572 return mc_send_command(mc_io, &cmd); 1573 } 1574 1575 /** 1576 * dpni_add_vlan_id() - Add VLAN ID filter 1577 * @mc_io: Pointer to MC portal's I/O object 1578 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1579 * @token: Token of DPNI object 1580 * @vlan_id: VLAN ID to add 1581 * @flags: 0 - tc_id and flow_id will be ignored. 1582 * Pkt with this vlan_id will be passed to the next 1583 * classification stages 1584 * DPNI_VLAN_SET_QUEUE_ACTION 1585 * Pkt with this vlan_id will be forward directly to 1586 * queue defined by the tc_id and flow_id 1587 * 1588 * @tc_id: Traffic class selection (0-7) 1589 * @flow_id: Selects the specific queue out of the set allocated for the 1590 * same as tc_id. Value must be in range 0 to NUM_QUEUES - 1 1591 * 1592 * Return: '0' on Success; Error code otherwise. 1593 */ 1594 int dpni_add_vlan_id(struct fsl_mc_io *mc_io, 1595 uint32_t cmd_flags, 1596 uint16_t token, 1597 uint16_t vlan_id, 1598 uint8_t flags, 1599 uint8_t tc_id, 1600 uint8_t flow_id) 1601 { 1602 struct dpni_cmd_vlan_id *cmd_params; 1603 struct mc_command cmd = { 0 }; 1604 1605 /* prepare command */ 1606 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_VLAN_ID, 1607 cmd_flags, 1608 token); 1609 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params; 1610 cmd_params->flags = flags; 1611 cmd_params->tc_id = tc_id; 1612 cmd_params->flow_id = flow_id; 1613 cmd_params->vlan_id = cpu_to_le16(vlan_id); 1614 1615 /* send command to mc*/ 1616 return mc_send_command(mc_io, &cmd); 1617 } 1618 1619 /** 1620 * dpni_remove_vlan_id() - Remove VLAN ID filter 1621 * @mc_io: Pointer to MC portal's I/O object 1622 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1623 * @token: Token of DPNI object 1624 * @vlan_id: VLAN ID to remove 1625 * 1626 * Return: '0' on Success; Error code otherwise. 1627 */ 1628 int dpni_remove_vlan_id(struct fsl_mc_io *mc_io, 1629 uint32_t cmd_flags, 1630 uint16_t token, 1631 uint16_t vlan_id) 1632 { 1633 struct dpni_cmd_vlan_id *cmd_params; 1634 struct mc_command cmd = { 0 }; 1635 1636 /* prepare command */ 1637 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_VLAN_ID, 1638 cmd_flags, 1639 token); 1640 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params; 1641 cmd_params->vlan_id = cpu_to_le16(vlan_id); 1642 1643 /* send command to mc*/ 1644 return mc_send_command(mc_io, &cmd); 1645 } 1646 1647 /** 1648 * dpni_clear_vlan_filters() - Clear all VLAN filters 1649 * @mc_io: Pointer to MC portal's I/O object 1650 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1651 * @token: Token of DPNI object 1652 * 1653 * Return: '0' on Success; Error code otherwise. 1654 */ 1655 int dpni_clear_vlan_filters(struct fsl_mc_io *mc_io, 1656 uint32_t cmd_flags, 1657 uint16_t token) 1658 { 1659 struct mc_command cmd = { 0 }; 1660 1661 /* prepare command */ 1662 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_VLAN_FILTERS, 1663 cmd_flags, 1664 token); 1665 1666 /* send command to mc*/ 1667 return mc_send_command(mc_io, &cmd); 1668 } 1669 1670 /** 1671 * dpni_set_tx_priorities() - Set transmission TC priority configuration 1672 * @mc_io: Pointer to MC portal's I/O object 1673 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1674 * @token: Token of DPNI object 1675 * @cfg: Transmission selection configuration 1676 * 1677 * warning: Allowed only when DPNI is disabled 1678 * 1679 * Return: '0' on Success; Error code otherwise. 1680 */ 1681 int dpni_set_tx_priorities(struct fsl_mc_io *mc_io, 1682 uint32_t cmd_flags, 1683 uint16_t token, 1684 const struct dpni_tx_priorities_cfg *cfg) 1685 { 1686 struct dpni_cmd_set_tx_priorities *cmd_params; 1687 struct mc_command cmd = { 0 }; 1688 int i; 1689 1690 /* prepare command */ 1691 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_PRIORITIES, 1692 cmd_flags, 1693 token); 1694 cmd_params = (struct dpni_cmd_set_tx_priorities *)cmd.params; 1695 cmd_params->channel_idx = cfg->channel_idx; 1696 dpni_set_field(cmd_params->flags, 1697 SEPARATE_GRP, 1698 cfg->separate_groups); 1699 cmd_params->prio_group_A = cfg->prio_group_A; 1700 cmd_params->prio_group_B = cfg->prio_group_B; 1701 1702 for (i = 0; i + 1 < DPNI_MAX_TC; i = i + 2) { 1703 dpni_set_field(cmd_params->modes[i / 2], 1704 MODE_1, 1705 cfg->tc_sched[i].mode); 1706 dpni_set_field(cmd_params->modes[i / 2], 1707 MODE_2, 1708 cfg->tc_sched[i + 1].mode); 1709 } 1710 1711 for (i = 0; i < DPNI_MAX_TC; i++) { 1712 cmd_params->delta_bandwidth[i] = 1713 cpu_to_le16(cfg->tc_sched[i].delta_bandwidth); 1714 } 1715 1716 /* send command to mc*/ 1717 return mc_send_command(mc_io, &cmd); 1718 } 1719 1720 /** 1721 * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration 1722 * @mc_io: Pointer to MC portal's I/O object 1723 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1724 * @token: Token of DPNI object 1725 * @tc_id: Traffic class selection (0-7) 1726 * @cfg: Traffic class distribution configuration 1727 * 1728 * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpkg_prepare_key_cfg() 1729 * first to prepare the key_cfg_iova parameter 1730 * 1731 * Return: '0' on Success; error code otherwise. 1732 */ 1733 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io, 1734 uint32_t cmd_flags, 1735 uint16_t token, 1736 uint8_t tc_id, 1737 const struct dpni_rx_tc_dist_cfg *cfg) 1738 { 1739 struct mc_command cmd = { 0 }; 1740 struct dpni_cmd_set_rx_tc_dist *cmd_params; 1741 1742 /* prepare command */ 1743 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST, 1744 cmd_flags, 1745 token); 1746 cmd_params = (struct dpni_cmd_set_rx_tc_dist *)cmd.params; 1747 cmd_params->dist_size = cpu_to_le16(cfg->dist_size); 1748 cmd_params->tc_id = tc_id; 1749 cmd_params->default_flow_id = cpu_to_le16(cfg->fs_cfg.default_flow_id); 1750 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova); 1751 dpni_set_field(cmd_params->flags, 1752 DIST_MODE, 1753 cfg->dist_mode); 1754 dpni_set_field(cmd_params->flags, 1755 MISS_ACTION, 1756 cfg->fs_cfg.miss_action); 1757 dpni_set_field(cmd_params->keep_hash_key, 1758 KEEP_HASH_KEY, 1759 cfg->fs_cfg.keep_hash_key); 1760 dpni_set_field(cmd_params->keep_hash_key, 1761 KEEP_ENTRIES, 1762 cfg->fs_cfg.keep_entries); 1763 1764 /* send command to mc*/ 1765 return mc_send_command(mc_io, &cmd); 1766 } 1767 1768 /** 1769 * dpni_set_tx_confirmation_mode() - Tx confirmation mode 1770 * @mc_io: Pointer to MC portal's I/O object 1771 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1772 * @token: Token of DPNI object 1773 * @ceetm_ch_idx: ceetm channel index 1774 * @mode: Tx confirmation mode 1775 * 1776 * This function is useful only when 'DPNI_OPT_TX_CONF_DISABLED' is not 1777 * selected at DPNI creation. 1778 * Calling this function with 'mode' set to DPNI_CONF_DISABLE disables all 1779 * transmit confirmation (including the private confirmation queues), regardless 1780 * of previous settings; Note that in this case, Tx error frames are still 1781 * enqueued to the general transmit errors queue. 1782 * Calling this function with 'mode' set to DPNI_CONF_SINGLE switches all 1783 * Tx confirmations to a shared Tx conf queue. 'index' field in dpni_get_queue 1784 * command will be ignored. 1785 * 1786 * Return: '0' on Success; Error code otherwise. 1787 */ 1788 int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io, 1789 uint32_t cmd_flags, 1790 uint16_t token, 1791 uint8_t ceetm_ch_idx, 1792 enum dpni_confirmation_mode mode) 1793 { 1794 struct dpni_tx_confirmation_mode *cmd_params; 1795 struct mc_command cmd = { 0 }; 1796 1797 /* prepare command */ 1798 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONFIRMATION_MODE, 1799 cmd_flags, 1800 token); 1801 cmd_params = (struct dpni_tx_confirmation_mode *)cmd.params; 1802 cmd_params->ceetm_ch_idx = ceetm_ch_idx; 1803 cmd_params->confirmation_mode = mode; 1804 1805 /* send command to mc*/ 1806 return mc_send_command(mc_io, &cmd); 1807 } 1808 1809 /** 1810 * dpni_get_tx_confirmation_mode() - Get Tx confirmation mode 1811 * @mc_io: Pointer to MC portal's I/O object 1812 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1813 * @token: Token of DPNI object 1814 * @ceetm_ch_idx: ceetm channel index 1815 * @mode: Tx confirmation mode 1816 * 1817 * Return: '0' on Success; Error code otherwise. 1818 */ 1819 int dpni_get_tx_confirmation_mode(struct fsl_mc_io *mc_io, 1820 uint32_t cmd_flags, 1821 uint16_t token, 1822 uint8_t ceetm_ch_idx, 1823 enum dpni_confirmation_mode *mode) 1824 { 1825 struct dpni_tx_confirmation_mode *cmd_params; 1826 struct dpni_tx_confirmation_mode *rsp_params; 1827 struct mc_command cmd = { 0 }; 1828 int err; 1829 1830 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_CONFIRMATION_MODE, 1831 cmd_flags, 1832 token); 1833 cmd_params = (struct dpni_tx_confirmation_mode *)cmd.params; 1834 cmd_params->ceetm_ch_idx = ceetm_ch_idx; 1835 1836 err = mc_send_command(mc_io, &cmd); 1837 if (err) 1838 return err; 1839 1840 rsp_params = (struct dpni_tx_confirmation_mode *)cmd.params; 1841 *mode = rsp_params->confirmation_mode; 1842 1843 return 0; 1844 } 1845 1846 /** 1847 * dpni_set_queue_tx_confirmation_mode() - Set Tx confirmation mode 1848 * @mc_io: Pointer to MC portal's I/O object 1849 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1850 * @token: Token of DPNI object 1851 * @ceetm_ch_idx: ceetm channel index 1852 * @index: queue index 1853 * @mode: Tx confirmation mode 1854 * 1855 * Return: '0' on Success; Error code otherwise. 1856 */ 1857 int dpni_set_queue_tx_confirmation_mode(struct fsl_mc_io *mc_io, 1858 uint32_t cmd_flags, 1859 uint16_t token, 1860 uint8_t ceetm_ch_idx, uint8_t index, 1861 enum dpni_confirmation_mode mode) 1862 { 1863 struct dpni_queue_tx_confirmation_mode *cmd_params; 1864 struct mc_command cmd = { 0 }; 1865 1866 /* prepare command */ 1867 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE_TX_CONFIRMATION_MODE, 1868 cmd_flags, 1869 token); 1870 cmd_params = (struct dpni_queue_tx_confirmation_mode *)cmd.params; 1871 cmd_params->ceetm_ch_idx = ceetm_ch_idx; 1872 cmd_params->index = index; 1873 cmd_params->confirmation_mode = mode; 1874 1875 /* send command to mc*/ 1876 return mc_send_command(mc_io, &cmd); 1877 } 1878 1879 /** 1880 * dpni_get_queue_tx_confirmation_mode() - Get Tx confirmation mode 1881 * @mc_io: Pointer to MC portal's I/O object 1882 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1883 * @token: Token of DPNI object 1884 * @ceetm_ch_idx: ceetm channel index 1885 * @index: queue index 1886 * @mode: Tx confirmation mode 1887 * 1888 * Return: '0' on Success; Error code otherwise. 1889 */ 1890 int dpni_get_queue_tx_confirmation_mode(struct fsl_mc_io *mc_io, 1891 uint32_t cmd_flags, 1892 uint16_t token, 1893 uint8_t ceetm_ch_idx, uint8_t index, 1894 enum dpni_confirmation_mode *mode) 1895 { 1896 struct dpni_queue_tx_confirmation_mode *cmd_params; 1897 struct dpni_queue_tx_confirmation_mode *rsp_params; 1898 struct mc_command cmd = { 0 }; 1899 int err; 1900 1901 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE_TX_CONFIRMATION_MODE, 1902 cmd_flags, 1903 token); 1904 cmd_params = (struct dpni_queue_tx_confirmation_mode *)cmd.params; 1905 cmd_params->ceetm_ch_idx = ceetm_ch_idx; 1906 cmd_params->index = index; 1907 1908 err = mc_send_command(mc_io, &cmd); 1909 if (err) 1910 return err; 1911 1912 rsp_params = (struct dpni_queue_tx_confirmation_mode *)cmd.params; 1913 *mode = rsp_params->confirmation_mode; 1914 1915 return 0; 1916 } 1917 1918 /** 1919 * dpni_set_qos_table() - Set QoS mapping table 1920 * @mc_io: Pointer to MC portal's I/O object 1921 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1922 * @token: Token of DPNI object 1923 * @cfg: QoS table configuration 1924 * 1925 * This function and all QoS-related functions require that 1926 *'max_tcs > 1' was set at DPNI creation. 1927 * 1928 * warning: Before calling this function, call dpkg_prepare_key_cfg() to 1929 * prepare the key_cfg_iova parameter 1930 * 1931 * Return: '0' on Success; Error code otherwise. 1932 */ 1933 int dpni_set_qos_table(struct fsl_mc_io *mc_io, 1934 uint32_t cmd_flags, 1935 uint16_t token, 1936 const struct dpni_qos_tbl_cfg *cfg) 1937 { 1938 struct dpni_cmd_set_qos_table *cmd_params; 1939 struct mc_command cmd = { 0 }; 1940 1941 /* prepare command */ 1942 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QOS_TBL, 1943 cmd_flags, 1944 token); 1945 cmd_params = (struct dpni_cmd_set_qos_table *)cmd.params; 1946 cmd_params->default_tc = cfg->default_tc; 1947 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova); 1948 dpni_set_field(cmd_params->discard_on_miss, 1949 ENABLE, 1950 cfg->discard_on_miss); 1951 dpni_set_field(cmd_params->discard_on_miss, 1952 KEEP_QOS_ENTRIES, 1953 cfg->keep_entries); 1954 1955 /* send command to mc*/ 1956 return mc_send_command(mc_io, &cmd); 1957 } 1958 1959 /** 1960 * dpni_add_qos_entry() - Add QoS mapping entry (to select a traffic class) 1961 * @mc_io: Pointer to MC portal's I/O object 1962 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1963 * @token: Token of DPNI object 1964 * @cfg: QoS rule to add 1965 * @tc_id: Traffic class selection (0-7) 1966 * @index: Location in the QoS table where to insert the entry. 1967 * Only relevant if MASKING is enabled for QoS classification on 1968 * this DPNI, it is ignored for exact match. 1969 * 1970 * Return: '0' on Success; Error code otherwise. 1971 */ 1972 int dpni_add_qos_entry(struct fsl_mc_io *mc_io, 1973 uint32_t cmd_flags, 1974 uint16_t token, 1975 const struct dpni_rule_cfg *cfg, 1976 uint8_t tc_id, 1977 uint16_t index, 1978 uint8_t flags, 1979 uint8_t flow_id) 1980 { 1981 struct dpni_cmd_add_qos_entry *cmd_params; 1982 struct mc_command cmd = { 0 }; 1983 1984 /* prepare command */ 1985 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_QOS_ENT, 1986 cmd_flags, 1987 token); 1988 cmd_params = (struct dpni_cmd_add_qos_entry *)cmd.params; 1989 cmd_params->flags = flags; 1990 cmd_params->flow_id = flow_id; 1991 cmd_params->tc_id = tc_id; 1992 cmd_params->key_size = cfg->key_size; 1993 cmd_params->index = cpu_to_le16(index); 1994 cmd_params->key_iova = cpu_to_le64(cfg->key_iova); 1995 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova); 1996 1997 /* send command to mc*/ 1998 return mc_send_command(mc_io, &cmd); 1999 } 2000 2001 /** 2002 * dpni_remove_qos_entry() - Remove QoS mapping entry 2003 * @mc_io: Pointer to MC portal's I/O object 2004 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2005 * @token: Token of DPNI object 2006 * @cfg: QoS rule to remove 2007 * 2008 * Return: '0' on Success; Error code otherwise. 2009 */ 2010 int dpni_remove_qos_entry(struct fsl_mc_io *mc_io, 2011 uint32_t cmd_flags, 2012 uint16_t token, 2013 const struct dpni_rule_cfg *cfg) 2014 { 2015 struct dpni_cmd_remove_qos_entry *cmd_params; 2016 struct mc_command cmd = { 0 }; 2017 2018 /* prepare command */ 2019 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_QOS_ENT, 2020 cmd_flags, 2021 token); 2022 cmd_params = (struct dpni_cmd_remove_qos_entry *)cmd.params; 2023 cmd_params->key_size = cfg->key_size; 2024 cmd_params->key_iova = cpu_to_le64(cfg->key_iova); 2025 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova); 2026 2027 /* send command to mc*/ 2028 return mc_send_command(mc_io, &cmd); 2029 } 2030 2031 /** 2032 * dpni_clear_qos_table() - Clear all QoS mapping entries 2033 * @mc_io: Pointer to MC portal's I/O object 2034 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2035 * @token: Token of DPNI object 2036 * 2037 * Following this function call, all frames are directed to 2038 * the default traffic class (0) 2039 * 2040 * Return: '0' on Success; Error code otherwise. 2041 */ 2042 int dpni_clear_qos_table(struct fsl_mc_io *mc_io, 2043 uint32_t cmd_flags, 2044 uint16_t token) 2045 { 2046 struct mc_command cmd = { 0 }; 2047 2048 /* prepare command */ 2049 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_QOS_TBL, 2050 cmd_flags, 2051 token); 2052 2053 /* send command to mc*/ 2054 return mc_send_command(mc_io, &cmd); 2055 } 2056 2057 /** 2058 * dpni_add_fs_entry() - Add Flow Steering entry for a specific traffic class 2059 * (to select a flow ID) 2060 * @mc_io: Pointer to MC portal's I/O object 2061 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2062 * @token: Token of DPNI object 2063 * @tc_id: Traffic class selection (0-7) 2064 * @index: Location in the QoS table where to insert the entry. 2065 * Only relevant if MASKING is enabled for QoS classification 2066 * on this DPNI, it is ignored for exact match. 2067 * @cfg: Flow steering rule to add 2068 * @action: Action to be taken as result of a classification hit 2069 * 2070 * Return: '0' on Success; Error code otherwise. 2071 */ 2072 int dpni_add_fs_entry(struct fsl_mc_io *mc_io, 2073 uint32_t cmd_flags, 2074 uint16_t token, 2075 uint8_t tc_id, 2076 uint16_t index, 2077 const struct dpni_rule_cfg *cfg, 2078 const struct dpni_fs_action_cfg *action) 2079 { 2080 struct dpni_cmd_add_fs_entry *cmd_params; 2081 struct mc_command cmd = { 0 }; 2082 2083 /* prepare command */ 2084 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_FS_ENT, 2085 cmd_flags, 2086 token); 2087 cmd_params = (struct dpni_cmd_add_fs_entry *)cmd.params; 2088 cmd_params->tc_id = tc_id; 2089 cmd_params->key_size = cfg->key_size; 2090 cmd_params->index = cpu_to_le16(index); 2091 cmd_params->key_iova = cpu_to_le64(cfg->key_iova); 2092 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova); 2093 cmd_params->options = cpu_to_le16(action->options); 2094 cmd_params->flow_id = cpu_to_le16(action->flow_id); 2095 cmd_params->flc = cpu_to_le64(action->flc); 2096 cmd_params->redir_token = cpu_to_le16(action->redirect_obj_token); 2097 2098 /* send command to mc*/ 2099 return mc_send_command(mc_io, &cmd); 2100 } 2101 2102 /** 2103 * dpni_remove_fs_entry() - Remove Flow Steering entry from a specific 2104 * traffic class 2105 * @mc_io: Pointer to MC portal's I/O object 2106 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2107 * @token: Token of DPNI object 2108 * @tc_id: Traffic class selection (0-7) 2109 * @cfg: Flow steering rule to remove 2110 * 2111 * Return: '0' on Success; Error code otherwise. 2112 */ 2113 int dpni_remove_fs_entry(struct fsl_mc_io *mc_io, 2114 uint32_t cmd_flags, 2115 uint16_t token, 2116 uint8_t tc_id, 2117 const struct dpni_rule_cfg *cfg) 2118 { 2119 struct dpni_cmd_remove_fs_entry *cmd_params; 2120 struct mc_command cmd = { 0 }; 2121 2122 /* prepare command */ 2123 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_FS_ENT, 2124 cmd_flags, 2125 token); 2126 cmd_params = (struct dpni_cmd_remove_fs_entry *)cmd.params; 2127 cmd_params->tc_id = tc_id; 2128 cmd_params->key_size = cfg->key_size; 2129 cmd_params->key_iova = cpu_to_le64(cfg->key_iova); 2130 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova); 2131 2132 /* send command to mc*/ 2133 return mc_send_command(mc_io, &cmd); 2134 } 2135 2136 /** 2137 * dpni_clear_fs_entries() - Clear all Flow Steering entries of a specific 2138 * traffic class 2139 * @mc_io: Pointer to MC portal's I/O object 2140 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2141 * @token: Token of DPNI object 2142 * @tc_id: Traffic class selection (0-7) 2143 * 2144 * Return: '0' on Success; Error code otherwise. 2145 */ 2146 int dpni_clear_fs_entries(struct fsl_mc_io *mc_io, 2147 uint32_t cmd_flags, 2148 uint16_t token, 2149 uint8_t tc_id) 2150 { 2151 struct dpni_cmd_clear_fs_entries *cmd_params; 2152 struct mc_command cmd = { 0 }; 2153 2154 /* prepare command */ 2155 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_FS_ENT, 2156 cmd_flags, 2157 token); 2158 cmd_params = (struct dpni_cmd_clear_fs_entries *)cmd.params; 2159 cmd_params->tc_id = tc_id; 2160 2161 /* send command to mc*/ 2162 return mc_send_command(mc_io, &cmd); 2163 } 2164 2165 /** 2166 * dpni_set_rx_tc_policing() - Set Rx traffic class policing configuration 2167 * @mc_io: Pointer to MC portal's I/O object 2168 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2169 * @token: Token of DPNI object 2170 * @tc_id: Traffic class selection (0-7) 2171 * @cfg: Traffic class policing configuration 2172 * 2173 * Return: '0' on Success; error code otherwise. 2174 */ 2175 int dpni_set_rx_tc_policing(struct fsl_mc_io *mc_io, 2176 uint32_t cmd_flags, 2177 uint16_t token, 2178 uint8_t tc_id, 2179 const struct dpni_rx_tc_policing_cfg *cfg) 2180 { 2181 struct dpni_cmd_set_rx_tc_policing *cmd_params; 2182 struct mc_command cmd = { 0 }; 2183 2184 /* prepare command */ 2185 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_POLICING, 2186 cmd_flags, 2187 token); 2188 cmd_params = (struct dpni_cmd_set_rx_tc_policing *)cmd.params; 2189 dpni_set_field(cmd_params->mode_color, COLOR, cfg->default_color); 2190 dpni_set_field(cmd_params->mode_color, MODE, cfg->mode); 2191 dpni_set_field(cmd_params->units, UNITS, cfg->units); 2192 cmd_params->options = cpu_to_le32(cfg->options); 2193 cmd_params->cir = cpu_to_le32(cfg->cir); 2194 cmd_params->cbs = cpu_to_le32(cfg->cbs); 2195 cmd_params->eir = cpu_to_le32(cfg->eir); 2196 cmd_params->ebs = cpu_to_le32(cfg->ebs); 2197 cmd_params->tc_id = tc_id; 2198 2199 /* send command to mc*/ 2200 return mc_send_command(mc_io, &cmd); 2201 } 2202 2203 /** 2204 * dpni_get_rx_tc_policing() - Get Rx traffic class policing configuration 2205 * @mc_io: Pointer to MC portal's I/O object 2206 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2207 * @token: Token of DPNI object 2208 * @tc_id: Traffic class selection (0-7) 2209 * @cfg: Traffic class policing configuration 2210 * 2211 * Return: '0' on Success; error code otherwise. 2212 */ 2213 int dpni_get_rx_tc_policing(struct fsl_mc_io *mc_io, 2214 uint32_t cmd_flags, 2215 uint16_t token, 2216 uint8_t tc_id, 2217 struct dpni_rx_tc_policing_cfg *cfg) 2218 { 2219 struct dpni_rsp_get_rx_tc_policing *rsp_params; 2220 struct dpni_cmd_get_rx_tc_policing *cmd_params; 2221 struct mc_command cmd = { 0 }; 2222 int err; 2223 2224 /* prepare command */ 2225 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_RX_TC_POLICING, 2226 cmd_flags, 2227 token); 2228 cmd_params = (struct dpni_cmd_get_rx_tc_policing *)cmd.params; 2229 cmd_params->tc_id = tc_id; 2230 2231 2232 /* send command to mc*/ 2233 err = mc_send_command(mc_io, &cmd); 2234 if (err) 2235 return err; 2236 2237 rsp_params = (struct dpni_rsp_get_rx_tc_policing *)cmd.params; 2238 cfg->options = le32_to_cpu(rsp_params->options); 2239 cfg->cir = le32_to_cpu(rsp_params->cir); 2240 cfg->cbs = le32_to_cpu(rsp_params->cbs); 2241 cfg->eir = le32_to_cpu(rsp_params->eir); 2242 cfg->ebs = le32_to_cpu(rsp_params->ebs); 2243 cfg->units = dpni_get_field(rsp_params->units, UNITS); 2244 cfg->mode = dpni_get_field(rsp_params->mode_color, MODE); 2245 cfg->default_color = dpni_get_field(rsp_params->mode_color, COLOR); 2246 2247 return 0; 2248 } 2249 2250 /** 2251 * dpni_prepare_early_drop() - prepare an early drop. 2252 * @cfg: Early-drop configuration 2253 * @early_drop_buf: Zeroed 256 bytes of memory before mapping it to DMA 2254 * 2255 * This function has to be called before dpni_set_rx_tc_early_drop or 2256 * dpni_set_tx_tc_early_drop 2257 * 2258 */ 2259 void dpni_prepare_early_drop(const struct dpni_early_drop_cfg *cfg, 2260 uint8_t *early_drop_buf) 2261 { 2262 struct dpni_early_drop *ext_params; 2263 2264 ext_params = (struct dpni_early_drop *)early_drop_buf; 2265 2266 dpni_set_field(ext_params->flags, DROP_ENABLE, cfg->enable); 2267 dpni_set_field(ext_params->flags, DROP_UNITS, cfg->units); 2268 ext_params->green_drop_probability = cfg->green.drop_probability; 2269 ext_params->green_max_threshold = cpu_to_le64(cfg->green.max_threshold); 2270 ext_params->green_min_threshold = cpu_to_le64(cfg->green.min_threshold); 2271 ext_params->yellow_drop_probability = cfg->yellow.drop_probability; 2272 ext_params->yellow_max_threshold = 2273 cpu_to_le64(cfg->yellow.max_threshold); 2274 ext_params->yellow_min_threshold = 2275 cpu_to_le64(cfg->yellow.min_threshold); 2276 ext_params->red_drop_probability = cfg->red.drop_probability; 2277 ext_params->red_max_threshold = cpu_to_le64(cfg->red.max_threshold); 2278 ext_params->red_min_threshold = cpu_to_le64(cfg->red.min_threshold); 2279 } 2280 2281 /** 2282 * dpni_extract_early_drop() - extract the early drop configuration. 2283 * @cfg: Early-drop configuration 2284 * @early_drop_buf: Zeroed 256 bytes of memory before mapping it to DMA 2285 * 2286 * This function has to be called after dpni_get_rx_tc_early_drop or 2287 * dpni_get_tx_tc_early_drop 2288 * 2289 */ 2290 void dpni_extract_early_drop(struct dpni_early_drop_cfg *cfg, 2291 const uint8_t *early_drop_buf) 2292 { 2293 const struct dpni_early_drop *ext_params; 2294 2295 ext_params = (const struct dpni_early_drop *)early_drop_buf; 2296 2297 cfg->enable = dpni_get_field(ext_params->flags, DROP_ENABLE); 2298 cfg->units = dpni_get_field(ext_params->flags, DROP_UNITS); 2299 cfg->green.drop_probability = ext_params->green_drop_probability; 2300 cfg->green.max_threshold = le64_to_cpu(ext_params->green_max_threshold); 2301 cfg->green.min_threshold = le64_to_cpu(ext_params->green_min_threshold); 2302 cfg->yellow.drop_probability = ext_params->yellow_drop_probability; 2303 cfg->yellow.max_threshold = 2304 le64_to_cpu(ext_params->yellow_max_threshold); 2305 cfg->yellow.min_threshold = 2306 le64_to_cpu(ext_params->yellow_min_threshold); 2307 cfg->red.drop_probability = ext_params->red_drop_probability; 2308 cfg->red.max_threshold = le64_to_cpu(ext_params->red_max_threshold); 2309 cfg->red.min_threshold = le64_to_cpu(ext_params->red_min_threshold); 2310 } 2311 2312 /** 2313 * dpni_set_early_drop() - Set traffic class early-drop configuration 2314 * @mc_io: Pointer to MC portal's I/O object 2315 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2316 * @token: Token of DPNI object 2317 * @qtype: Type of queue - only Rx and Tx types are supported 2318 * @param: Traffic class and channel ID. 2319 * MSB - channel id; used only for DPNI_QUEUE_TX and DPNI_QUEUE_TX_CONFIRM, 2320 * ignored for the rest 2321 * LSB - traffic class 2322 * Use macro DPNI_BUILD_PARAM() to build correct value. 2323 * If dpni uses a single channel (uses only channel zero) the parameter can receive 2324 * traffic class directly. 2325 * @early_drop_iova: I/O virtual address of 256 bytes DMA-able memory filled 2326 * with the early-drop configuration by calling dpni_prepare_early_drop() 2327 * 2328 * warning: Before calling this function, call dpni_prepare_early_drop() to 2329 * prepare the early_drop_iova parameter 2330 * 2331 * Return: '0' on Success; error code otherwise. 2332 */ 2333 int dpni_set_early_drop(struct fsl_mc_io *mc_io, 2334 uint32_t cmd_flags, 2335 uint16_t token, 2336 enum dpni_queue_type qtype, 2337 uint16_t param, 2338 uint64_t early_drop_iova) 2339 { 2340 struct dpni_cmd_early_drop *cmd_params; 2341 struct mc_command cmd = { 0 }; 2342 2343 /* prepare command */ 2344 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_EARLY_DROP, 2345 cmd_flags, 2346 token); 2347 cmd_params = (struct dpni_cmd_early_drop *)cmd.params; 2348 cmd_params->qtype = qtype; 2349 cmd_params->tc = (uint8_t)(param & 0xff); 2350 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff); 2351 cmd_params->early_drop_iova = cpu_to_le64(early_drop_iova); 2352 2353 /* send command to mc*/ 2354 return mc_send_command(mc_io, &cmd); 2355 } 2356 2357 /** 2358 * dpni_get_early_drop() - Get Rx traffic class early-drop configuration 2359 * @mc_io: Pointer to MC portal's I/O object 2360 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2361 * @token: Token of DPNI object 2362 * @qtype: Type of queue - only Rx and Tx types are supported 2363 * @param: Traffic class and channel ID. 2364 * MSB - channel id; used only for DPNI_QUEUE_TX and DPNI_QUEUE_TX_CONFIRM, 2365 * ignored for the rest 2366 * LSB - traffic class 2367 * Use macro DPNI_BUILD_PARAM() to build correct value. 2368 * If dpni uses a single channel (uses only channel zero) the parameter can receive 2369 * traffic class directly. 2370 * @early_drop_iova: I/O virtual address of 256 bytes DMA-able memory 2371 * 2372 * warning: After calling this function, call dpni_extract_early_drop() to 2373 * get the early drop configuration 2374 * 2375 * Return: '0' on Success; error code otherwise. 2376 */ 2377 int dpni_get_early_drop(struct fsl_mc_io *mc_io, 2378 uint32_t cmd_flags, 2379 uint16_t token, 2380 enum dpni_queue_type qtype, 2381 uint16_t param, 2382 uint64_t early_drop_iova) 2383 { 2384 struct dpni_cmd_early_drop *cmd_params; 2385 struct mc_command cmd = { 0 }; 2386 2387 /* prepare command */ 2388 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_EARLY_DROP, 2389 cmd_flags, 2390 token); 2391 cmd_params = (struct dpni_cmd_early_drop *)cmd.params; 2392 cmd_params->qtype = qtype; 2393 cmd_params->tc = (uint8_t)(param & 0xff); 2394 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff); 2395 cmd_params->early_drop_iova = cpu_to_le64(early_drop_iova); 2396 2397 /* send command to mc*/ 2398 return mc_send_command(mc_io, &cmd); 2399 } 2400 2401 /** 2402 * dpni_set_congestion_notification() - Set traffic class congestion 2403 * notification configuration 2404 * @mc_io: Pointer to MC portal's I/O object 2405 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2406 * @token: Token of DPNI object 2407 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported 2408 * @param: Traffic class and channel. Bits[0-7] contain traaffic class, 2409 * bite[8-15] contains channel id 2410 * @cfg: congestion notification configuration 2411 * 2412 * Return: '0' on Success; error code otherwise. 2413 */ 2414 int dpni_set_congestion_notification(struct fsl_mc_io *mc_io, 2415 uint32_t cmd_flags, 2416 uint16_t token, 2417 enum dpni_queue_type qtype, 2418 uint16_t param, 2419 const struct dpni_congestion_notification_cfg *cfg) 2420 { 2421 struct dpni_cmd_set_congestion_notification *cmd_params; 2422 struct mc_command cmd = { 0 }; 2423 2424 /* prepare command */ 2425 cmd.header = mc_encode_cmd_header( 2426 DPNI_CMDID_SET_CONGESTION_NOTIFICATION, 2427 cmd_flags, 2428 token); 2429 cmd_params = (struct dpni_cmd_set_congestion_notification *)cmd.params; 2430 cmd_params->qtype = qtype; 2431 cmd_params->tc = (uint8_t)(param & 0xff); 2432 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff); 2433 cmd_params->congestion_point = cfg->cg_point; 2434 cmd_params->cgid = (uint8_t)cfg->cgid; 2435 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id); 2436 cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode); 2437 cmd_params->dest_priority = cfg->dest_cfg.priority; 2438 cmd_params->message_iova = cpu_to_le64(cfg->message_iova); 2439 cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx); 2440 cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry); 2441 cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit); 2442 dpni_set_field(cmd_params->type_units, 2443 DEST_TYPE, 2444 cfg->dest_cfg.dest_type); 2445 dpni_set_field(cmd_params->type_units, 2446 CONG_UNITS, 2447 cfg->units); 2448 2449 /* send command to mc*/ 2450 return mc_send_command(mc_io, &cmd); 2451 } 2452 2453 /** 2454 * dpni_get_congestion_notification() - Get traffic class congestion 2455 * notification configuration 2456 * @mc_io: Pointer to MC portal's I/O object 2457 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2458 * @token: Token of DPNI object 2459 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported 2460 * @tc_id: Traffic class selection (0-7) 2461 * @cfg: congestion notification configuration 2462 * 2463 * Return: '0' on Success; error code otherwise. 2464 */ 2465 int dpni_get_congestion_notification(struct fsl_mc_io *mc_io, 2466 uint32_t cmd_flags, 2467 uint16_t token, 2468 enum dpni_queue_type qtype, 2469 uint16_t param, 2470 struct dpni_congestion_notification_cfg *cfg) 2471 { 2472 struct dpni_rsp_get_congestion_notification *rsp_params; 2473 struct dpni_cmd_get_congestion_notification *cmd_params; 2474 struct mc_command cmd = { 0 }; 2475 int err; 2476 2477 /* prepare command */ 2478 cmd.header = mc_encode_cmd_header( 2479 DPNI_CMDID_GET_CONGESTION_NOTIFICATION, 2480 cmd_flags, 2481 token); 2482 cmd_params = (struct dpni_cmd_get_congestion_notification *)cmd.params; 2483 cmd_params->qtype = qtype; 2484 cmd_params->tc = (uint8_t)(param & 0xff); 2485 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff); 2486 cmd_params->congestion_point = cfg->cg_point; 2487 cmd_params->cgid = cfg->cgid; 2488 2489 /* send command to mc*/ 2490 err = mc_send_command(mc_io, &cmd); 2491 if (err) 2492 return err; 2493 2494 rsp_params = (struct dpni_rsp_get_congestion_notification *)cmd.params; 2495 cfg->units = dpni_get_field(rsp_params->type_units, CONG_UNITS); 2496 cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry); 2497 cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit); 2498 cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx); 2499 cfg->message_iova = le64_to_cpu(rsp_params->message_iova); 2500 cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode); 2501 cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id); 2502 cfg->dest_cfg.priority = rsp_params->dest_priority; 2503 cfg->dest_cfg.dest_type = dpni_get_field(rsp_params->type_units, 2504 DEST_TYPE); 2505 2506 return 0; 2507 } 2508 2509 /** 2510 * dpni_get_api_version() - Get Data Path Network Interface API version 2511 * @mc_io: Pointer to MC portal's I/O object 2512 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2513 * @major_ver: Major version of data path network interface API 2514 * @minor_ver: Minor version of data path network interface API 2515 * 2516 * Return: '0' on Success; Error code otherwise. 2517 */ 2518 int dpni_get_api_version(struct fsl_mc_io *mc_io, 2519 uint32_t cmd_flags, 2520 uint16_t *major_ver, 2521 uint16_t *minor_ver) 2522 { 2523 struct dpni_rsp_get_api_version *rsp_params; 2524 struct mc_command cmd = { 0 }; 2525 int err; 2526 2527 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION, 2528 cmd_flags, 2529 0); 2530 2531 err = mc_send_command(mc_io, &cmd); 2532 if (err) 2533 return err; 2534 2535 rsp_params = (struct dpni_rsp_get_api_version *)cmd.params; 2536 *major_ver = le16_to_cpu(rsp_params->major); 2537 *minor_ver = le16_to_cpu(rsp_params->minor); 2538 2539 return 0; 2540 } 2541 2542 /** 2543 * dpni_set_queue() - Set queue parameters 2544 * @mc_io: Pointer to MC portal's I/O object 2545 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2546 * @token: Token of DPNI object 2547 * @qtype: Type of queue - all queue types are supported, although 2548 * the command is ignored for Tx 2549 * @tc: Traffic class, in range 0 to NUM_TCS - 1 2550 * @index: Selects the specific queue out of the set allocated for the 2551 * same TC. Value must be in range 0 to NUM_QUEUES - 1 2552 * @options: A combination of DPNI_QUEUE_OPT_ values that control what 2553 * configuration options are set on the queue 2554 * @queue: Queue structure 2555 * 2556 * Return: '0' on Success; Error code otherwise. 2557 */ 2558 int dpni_set_queue(struct fsl_mc_io *mc_io, 2559 uint32_t cmd_flags, 2560 uint16_t token, 2561 enum dpni_queue_type qtype, 2562 uint16_t param, 2563 uint8_t index, 2564 uint8_t options, 2565 const struct dpni_queue *queue) 2566 { 2567 struct mc_command cmd = { 0 }; 2568 struct dpni_cmd_set_queue *cmd_params; 2569 2570 /* prepare command */ 2571 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE, 2572 cmd_flags, 2573 token); 2574 cmd_params = (struct dpni_cmd_set_queue *)cmd.params; 2575 cmd_params->qtype = qtype; 2576 cmd_params->tc = (uint8_t)(param & 0xff); 2577 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff); 2578 cmd_params->index = index; 2579 cmd_params->options = options; 2580 cmd_params->dest_id = cpu_to_le32(queue->destination.id); 2581 cmd_params->dest_prio = queue->destination.priority; 2582 dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type); 2583 dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control); 2584 dpni_set_field(cmd_params->flags, HOLD_ACTIVE, 2585 queue->destination.hold_active); 2586 cmd_params->flc = cpu_to_le64(queue->flc.value); 2587 cmd_params->user_context = cpu_to_le64(queue->user_context); 2588 cmd_params->cgid = queue->cgid; 2589 2590 /* send command to mc */ 2591 return mc_send_command(mc_io, &cmd); 2592 } 2593 2594 /** 2595 * dpni_get_queue() - Get queue parameters 2596 * @mc_io: Pointer to MC portal's I/O object 2597 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2598 * @token: Token of DPNI object 2599 * @qtype: Type of queue - all queue types are supported 2600 * @param: Traffic class and channel ID. 2601 * MSB - channel id; used only for DPNI_QUEUE_TX and DPNI_QUEUE_TX_CONFIRM, 2602 * ignored for the rest 2603 * LSB - traffic class 2604 * Use macro DPNI_BUILD_PARAM() to build correct value. 2605 * If dpni uses a single channel (uses only channel zero) the parameter can receive 2606 * traffic class directly. 2607 * @index: Selects the specific queue out of the set allocated for the 2608 * same TC. Value must be in range 0 to NUM_QUEUES - 1 2609 * @queue: Queue configuration structure 2610 * @qid: Queue identification 2611 * 2612 * Return: '0' on Success; Error code otherwise. 2613 */ 2614 int dpni_get_queue(struct fsl_mc_io *mc_io, 2615 uint32_t cmd_flags, 2616 uint16_t token, 2617 enum dpni_queue_type qtype, 2618 uint16_t param, 2619 uint8_t index, 2620 struct dpni_queue *queue, 2621 struct dpni_queue_id *qid) 2622 { 2623 struct mc_command cmd = { 0 }; 2624 struct dpni_cmd_get_queue *cmd_params; 2625 struct dpni_rsp_get_queue *rsp_params; 2626 int err; 2627 2628 /* prepare command */ 2629 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE, 2630 cmd_flags, 2631 token); 2632 cmd_params = (struct dpni_cmd_get_queue *)cmd.params; 2633 cmd_params->qtype = qtype; 2634 cmd_params->tc = (uint8_t)(param & 0xff); 2635 cmd_params->index = index; 2636 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff); 2637 2638 /* send command to mc */ 2639 err = mc_send_command(mc_io, &cmd); 2640 if (err) 2641 return err; 2642 2643 /* retrieve response parameters */ 2644 rsp_params = (struct dpni_rsp_get_queue *)cmd.params; 2645 queue->destination.id = le32_to_cpu(rsp_params->dest_id); 2646 queue->destination.priority = rsp_params->dest_prio; 2647 queue->destination.type = dpni_get_field(rsp_params->flags, 2648 DEST_TYPE); 2649 queue->flc.stash_control = dpni_get_field(rsp_params->flags, 2650 STASH_CTRL); 2651 queue->destination.hold_active = dpni_get_field(rsp_params->flags, 2652 HOLD_ACTIVE); 2653 queue->flc.value = le64_to_cpu(rsp_params->flc); 2654 queue->user_context = le64_to_cpu(rsp_params->user_context); 2655 qid->fqid = le32_to_cpu(rsp_params->fqid); 2656 qid->qdbin = le16_to_cpu(rsp_params->qdbin); 2657 if (dpni_get_field(rsp_params->flags, CGID_VALID)) 2658 queue->cgid = rsp_params->cgid; 2659 else 2660 queue->cgid = -1; 2661 2662 return 0; 2663 } 2664 2665 /** 2666 * dpni_get_statistics() - Get DPNI statistics 2667 * @mc_io: Pointer to MC portal's I/O object 2668 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2669 * @token: Token of DPNI object 2670 * @page: Selects the statistics page to retrieve, see 2671 * DPNI_GET_STATISTICS output. Pages are numbered 0 to 6. 2672 * @param: Custom parameter for some pages used to select 2673 * a certain statistic source, for example the TC. 2674 * - page_0: not used 2675 * - page_1: not used 2676 * - page_2: not used 2677 * - page_3: high_byte - channel_id, low_byte - traffic class 2678 * - page_4: high_byte - queue_index have meaning only if dpni is 2679 * created using option DPNI_OPT_CUSTOM_CG, low_byte - traffic class 2680 * - page_5: not used 2681 * - page_6: not used 2682 * @stat: Structure containing the statistics 2683 * 2684 * Return: '0' on Success; Error code otherwise. 2685 */ 2686 int dpni_get_statistics(struct fsl_mc_io *mc_io, 2687 uint32_t cmd_flags, 2688 uint16_t token, 2689 uint8_t page, 2690 uint16_t param, 2691 union dpni_statistics *stat) 2692 { 2693 struct mc_command cmd = { 0 }; 2694 struct dpni_cmd_get_statistics *cmd_params; 2695 struct dpni_rsp_get_statistics *rsp_params; 2696 int i, err; 2697 2698 /* prepare command */ 2699 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS, 2700 cmd_flags, 2701 token); 2702 cmd_params = (struct dpni_cmd_get_statistics *)cmd.params; 2703 cmd_params->page_number = page; 2704 cmd_params->param = param; 2705 2706 /* send command to mc */ 2707 err = mc_send_command(mc_io, &cmd); 2708 if (err) 2709 return err; 2710 2711 /* retrieve response parameters */ 2712 rsp_params = (struct dpni_rsp_get_statistics *)cmd.params; 2713 for (i = 0; i < DPNI_STATISTICS_CNT; i++) 2714 stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]); 2715 2716 return 0; 2717 } 2718 2719 /** 2720 * dpni_reset_statistics() - Clears DPNI statistics 2721 * @mc_io: Pointer to MC portal's I/O object 2722 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2723 * @token: Token of DPNI object 2724 * 2725 * Return: '0' on Success; Error code otherwise. 2726 */ 2727 int dpni_reset_statistics(struct fsl_mc_io *mc_io, 2728 uint32_t cmd_flags, 2729 uint16_t token) 2730 { 2731 struct mc_command cmd = { 0 }; 2732 2733 /* prepare command */ 2734 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS, 2735 cmd_flags, 2736 token); 2737 2738 /* send command to mc*/ 2739 return mc_send_command(mc_io, &cmd); 2740 } 2741 2742 /** 2743 * dpni_set_taildrop() - Set taildrop per congestion group 2744 * 2745 * Setting a per-TC taildrop (cg_point = DPNI_CP_GROUP) will reset any current 2746 * congestion notification or early drop (WRED) configuration previously applied 2747 * to the same TC. 2748 * 2749 * @mc_io: Pointer to MC portal's I/O object 2750 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2751 * @token: Token of DPNI object 2752 * @cg_point: Congestion group identifier DPNI_CP_QUEUE is only supported in 2753 * combination with DPNI_QUEUE_RX. 2754 * @q_type: Queue type, can be DPNI_QUEUE_RX or DPNI_QUEUE_TX. 2755 * @tc: Traffic class to apply this taildrop to 2756 * @index/cgid: Index of the queue if the DPNI supports multiple queues for 2757 * traffic distribution. 2758 * If CONGESTION_POINT is DPNI_CP_CONGESTION_GROUP then it 2759 * represent the cgid of the congestion point 2760 * @taildrop: Taildrop structure 2761 * 2762 * Return: '0' on Success; Error code otherwise. 2763 */ 2764 int dpni_set_taildrop(struct fsl_mc_io *mc_io, 2765 uint32_t cmd_flags, 2766 uint16_t token, 2767 enum dpni_congestion_point cg_point, 2768 enum dpni_queue_type qtype, 2769 uint16_t param, 2770 uint8_t index, 2771 struct dpni_taildrop *taildrop) 2772 { 2773 struct mc_command cmd = { 0 }; 2774 struct dpni_cmd_set_taildrop *cmd_params; 2775 2776 /* prepare command */ 2777 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP, 2778 cmd_flags, 2779 token); 2780 cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params; 2781 cmd_params->congestion_point = cg_point; 2782 cmd_params->qtype = qtype; 2783 cmd_params->tc = (uint8_t)(param & 0xff); 2784 cmd_params->channel_id = (uint8_t)((param >> 8) & 0xff); 2785 cmd_params->index = index; 2786 cmd_params->units = taildrop->units; 2787 cmd_params->threshold = cpu_to_le32(taildrop->threshold); 2788 dpni_set_field(cmd_params->enable_oal_lo, ENABLE, taildrop->enable); 2789 dpni_set_field(cmd_params->enable_oal_lo, OAL_LO, taildrop->oal); 2790 dpni_set_field(cmd_params->oal_hi, 2791 OAL_HI, 2792 taildrop->oal >> DPNI_OAL_LO_SIZE); 2793 2794 /* send command to mc */ 2795 return mc_send_command(mc_io, &cmd); 2796 } 2797 2798 /** 2799 * dpni_get_taildrop() - Get taildrop information 2800 * @mc_io: Pointer to MC portal's I/O object 2801 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2802 * @token: Token of DPNI object 2803 * @cg_point: Congestion point 2804 * @q_type: Queue type on which the taildrop is configured. 2805 * Only Rx queues are supported for now 2806 * @tc: Traffic class to apply this taildrop to 2807 * @q_index: Index of the queue if the DPNI supports multiple queues for 2808 * traffic distribution. Ignored if CONGESTION_POINT is not 0. 2809 * @taildrop: Taildrop structure 2810 * 2811 * Return: '0' on Success; Error code otherwise. 2812 */ 2813 int dpni_get_taildrop(struct fsl_mc_io *mc_io, 2814 uint32_t cmd_flags, 2815 uint16_t token, 2816 enum dpni_congestion_point cg_point, 2817 enum dpni_queue_type qtype, 2818 uint8_t tc, 2819 uint8_t index, 2820 struct dpni_taildrop *taildrop) 2821 { 2822 struct mc_command cmd = { 0 }; 2823 struct dpni_cmd_get_taildrop *cmd_params; 2824 struct dpni_rsp_get_taildrop *rsp_params; 2825 uint8_t oal_lo, oal_hi; 2826 int err; 2827 2828 /* prepare command */ 2829 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP, 2830 cmd_flags, 2831 token); 2832 cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params; 2833 cmd_params->congestion_point = cg_point; 2834 cmd_params->qtype = qtype; 2835 cmd_params->tc = tc; 2836 cmd_params->index = index; 2837 2838 /* send command to mc */ 2839 err = mc_send_command(mc_io, &cmd); 2840 if (err) 2841 return err; 2842 2843 /* retrieve response parameters */ 2844 rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params; 2845 taildrop->enable = dpni_get_field(rsp_params->enable_oal_lo, ENABLE); 2846 taildrop->units = rsp_params->units; 2847 taildrop->threshold = le32_to_cpu(rsp_params->threshold); 2848 oal_lo = dpni_get_field(rsp_params->enable_oal_lo, OAL_LO); 2849 oal_hi = dpni_get_field(rsp_params->oal_hi, OAL_HI); 2850 taildrop->oal = oal_hi << DPNI_OAL_LO_SIZE | oal_lo; 2851 2852 /* Fill the first 4 bits, 'oal' is a 2's complement value of 12 bits */ 2853 if (taildrop->oal >= 0x0800) 2854 taildrop->oal |= 0xF000; 2855 2856 return 0; 2857 } 2858 2859 /** 2860 * dpni_set_opr() - Set Order Restoration configuration. 2861 * @mc_io: Pointer to MC portal's I/O object 2862 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2863 * @token: Token of DPNI object 2864 * @tc: Traffic class, in range 0 to NUM_TCS - 1 2865 * @index: Selects the specific queue out of the set allocated 2866 * for the same TC. Value must be in range 0 to 2867 * NUM_QUEUES - 1 2868 * @options: Configuration mode options 2869 * can be OPR_OPT_CREATE or OPR_OPT_RETIRE 2870 * @cfg: Configuration options for the OPR 2871 * 2872 * Return: '0' on Success; Error code otherwise. 2873 */ 2874 int dpni_set_opr(struct fsl_mc_io *mc_io, 2875 uint32_t cmd_flags, 2876 uint16_t token, 2877 uint8_t tc, 2878 uint8_t index, 2879 uint8_t options, 2880 struct opr_cfg *cfg, 2881 uint8_t opr_id) 2882 { 2883 struct dpni_cmd_set_opr *cmd_params; 2884 struct mc_command cmd = { 0 }; 2885 2886 /* prepare command */ 2887 cmd.header = mc_encode_cmd_header( 2888 DPNI_CMDID_SET_OPR, 2889 cmd_flags, 2890 token); 2891 cmd_params = (struct dpni_cmd_set_opr *)cmd.params; 2892 cmd_params->tc_id = tc; 2893 cmd_params->index = index; 2894 cmd_params->options = options; 2895 cmd_params->opr_id = opr_id; 2896 cmd_params->oloe = cfg->oloe; 2897 cmd_params->oeane = cfg->oeane; 2898 cmd_params->olws = cfg->olws; 2899 cmd_params->oa = cfg->oa; 2900 cmd_params->oprrws = cfg->oprrws; 2901 2902 /* send command to mc*/ 2903 return mc_send_command(mc_io, &cmd); 2904 } 2905 2906 /** 2907 * dpni_get_opr() - Retrieve Order Restoration config and query. 2908 * @mc_io: Pointer to MC portal's I/O object 2909 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2910 * @token: Token of DPNI object 2911 * @tc: Traffic class, in range 0 to NUM_TCS - 1 2912 * @index: Selects the specific queue out of the set allocated 2913 * for the same TC. Value must be in range 0 to 2914 * NUM_QUEUES - 1 2915 * @cfg: Returned OPR configuration 2916 * @qry: Returned OPR query 2917 * 2918 * Return: '0' on Success; Error code otherwise. 2919 */ 2920 int dpni_get_opr(struct fsl_mc_io *mc_io, 2921 uint32_t cmd_flags, 2922 uint16_t token, 2923 uint8_t tc, 2924 uint8_t index, 2925 struct opr_cfg *cfg, 2926 struct opr_qry *qry, 2927 uint8_t flags, 2928 uint8_t opr_id) 2929 { 2930 struct dpni_rsp_get_opr *rsp_params; 2931 struct dpni_cmd_get_opr *cmd_params; 2932 struct mc_command cmd = { 0 }; 2933 int err; 2934 2935 /* prepare command */ 2936 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OPR, 2937 cmd_flags, 2938 token); 2939 cmd_params = (struct dpni_cmd_get_opr *)cmd.params; 2940 cmd_params->index = index; 2941 cmd_params->tc_id = tc; 2942 cmd_params->flags = flags; 2943 cmd_params->opr_id = opr_id; 2944 2945 /* send command to mc*/ 2946 err = mc_send_command(mc_io, &cmd); 2947 if (err) 2948 return err; 2949 2950 /* retrieve response parameters */ 2951 rsp_params = (struct dpni_rsp_get_opr *)cmd.params; 2952 cfg->oloe = rsp_params->oloe; 2953 cfg->oeane = rsp_params->oeane; 2954 cfg->olws = rsp_params->olws; 2955 cfg->oa = rsp_params->oa; 2956 cfg->oprrws = rsp_params->oprrws; 2957 qry->rip = dpni_get_field(rsp_params->flags, RIP); 2958 qry->enable = dpni_get_field(rsp_params->flags, OPR_ENABLE); 2959 qry->nesn = le16_to_cpu(rsp_params->nesn); 2960 qry->ndsn = le16_to_cpu(rsp_params->ndsn); 2961 qry->ea_tseq = le16_to_cpu(rsp_params->ea_tseq); 2962 qry->tseq_nlis = dpni_get_field(rsp_params->tseq_nlis, TSEQ_NLIS); 2963 qry->ea_hseq = le16_to_cpu(rsp_params->ea_hseq); 2964 qry->hseq_nlis = dpni_get_field(rsp_params->hseq_nlis, HSEQ_NLIS); 2965 qry->ea_hptr = le16_to_cpu(rsp_params->ea_hptr); 2966 qry->ea_tptr = le16_to_cpu(rsp_params->ea_tptr); 2967 qry->opr_vid = le16_to_cpu(rsp_params->opr_vid); 2968 qry->opr_id = le16_to_cpu(rsp_params->opr_id); 2969 2970 return 0; 2971 } 2972 2973 int dpni_load_sw_sequence(struct fsl_mc_io *mc_io, 2974 uint32_t cmd_flags, 2975 uint16_t token, 2976 struct dpni_load_ss_cfg *cfg) 2977 { 2978 struct dpni_load_sw_sequence *cmd_params; 2979 struct mc_command cmd = { 0 }; 2980 2981 /* prepare command */ 2982 cmd.header = mc_encode_cmd_header(DPNI_CMDID_LOAD_SW_SEQUENCE, 2983 cmd_flags, 2984 token); 2985 cmd_params = (struct dpni_load_sw_sequence *)cmd.params; 2986 cmd_params->dest = cfg->dest; 2987 cmd_params->ss_offset = cpu_to_le16(cfg->ss_offset); 2988 cmd_params->ss_size = cpu_to_le16(cfg->ss_size); 2989 cmd_params->ss_iova = cpu_to_le64(cfg->ss_iova); 2990 2991 /* send command to mc*/ 2992 return mc_send_command(mc_io, &cmd); 2993 } 2994 2995 int dpni_enable_sw_sequence(struct fsl_mc_io *mc_io, 2996 uint32_t cmd_flags, 2997 uint16_t token, 2998 struct dpni_enable_ss_cfg *cfg) 2999 { 3000 struct dpni_enable_sw_sequence *cmd_params; 3001 struct mc_command cmd = { 0 }; 3002 3003 /* prepare command */ 3004 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_SW_SEQUENCE, 3005 cmd_flags, 3006 token); 3007 cmd_params = (struct dpni_enable_sw_sequence *)cmd.params; 3008 cmd_params->dest = cfg->dest; 3009 cmd_params->set_start = cfg->set_start; 3010 cmd_params->hxs = cpu_to_le16(cfg->hxs); 3011 cmd_params->ss_offset = cpu_to_le16(cfg->ss_offset); 3012 cmd_params->param_offset = cfg->param_offset; 3013 cmd_params->param_size = cfg->param_size; 3014 cmd_params->param_iova = cpu_to_le64(cfg->param_iova); 3015 3016 /* send command to mc*/ 3017 return mc_send_command(mc_io, &cmd); 3018 } 3019 3020 /** 3021 * dpni_get_sw_sequence_layout() - Get the soft sequence layout 3022 * @mc_io: Pointer to MC portal's I/O object 3023 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 3024 * @token: Token of DPNI object 3025 * @src: Source of the layout (WRIOP Rx or Tx) 3026 * @ss_layout_iova: I/O virtual address of 264 bytes DMA-able memory 3027 * 3028 * warning: After calling this function, call dpni_extract_sw_sequence_layout() 3029 * to get the layout. 3030 * 3031 * Return: '0' on Success; error code otherwise. 3032 */ 3033 int dpni_get_sw_sequence_layout(struct fsl_mc_io *mc_io, 3034 uint32_t cmd_flags, 3035 uint16_t token, 3036 enum dpni_soft_sequence_dest src, 3037 uint64_t ss_layout_iova) 3038 { 3039 struct dpni_get_sw_sequence_layout *cmd_params; 3040 struct mc_command cmd = { 0 }; 3041 3042 /* prepare command */ 3043 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_SW_SEQUENCE_LAYOUT, 3044 cmd_flags, 3045 token); 3046 3047 cmd_params = (struct dpni_get_sw_sequence_layout *)cmd.params; 3048 cmd_params->src = src; 3049 cmd_params->layout_iova = cpu_to_le64(ss_layout_iova); 3050 3051 /* send command to mc*/ 3052 return mc_send_command(mc_io, &cmd); 3053 } 3054 3055 /** 3056 * dpni_extract_sw_sequence_layout() - extract the software sequence layout 3057 * @layout: software sequence layout 3058 * @sw_sequence_layout_buf: Zeroed 264 bytes of memory before mapping it 3059 * to DMA 3060 * 3061 * This function has to be called after dpni_get_sw_sequence_layout 3062 * 3063 */ 3064 void dpni_extract_sw_sequence_layout(struct dpni_sw_sequence_layout *layout, 3065 const uint8_t *sw_sequence_layout_buf) 3066 { 3067 const struct dpni_sw_sequence_layout_entry *ext_params; 3068 int i; 3069 uint16_t ss_size, ss_offset; 3070 3071 ext_params = (const struct dpni_sw_sequence_layout_entry *) 3072 sw_sequence_layout_buf; 3073 3074 for (i = 0; i < DPNI_SW_SEQUENCE_LAYOUT_SIZE; i++) { 3075 ss_offset = le16_to_cpu(ext_params[i].ss_offset); 3076 ss_size = le16_to_cpu(ext_params[i].ss_size); 3077 3078 if (ss_offset == 0 && ss_size == 0) { 3079 layout->num_ss = i; 3080 return; 3081 } 3082 3083 layout->ss[i].ss_offset = ss_offset; 3084 layout->ss[i].ss_size = ss_size; 3085 layout->ss[i].param_offset = ext_params[i].param_offset; 3086 layout->ss[i].param_size = ext_params[i].param_size; 3087 } 3088 } 3089 /** 3090 * dpni_set_rx_fs_dist() - Set Rx traffic class FS distribution 3091 * @mc_io: Pointer to MC portal's I/O object 3092 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 3093 * @token: Token of DPNI object 3094 * @cfg: Distribution configuration 3095 * If the FS is already enabled with a previous call the classification 3096 * key will be changed but all the table rules are kept. If the 3097 * existing rules do not match the key the results will not be 3098 * predictable. It is the user responsibility to keep keyintegrity. 3099 * If cfg.enable is set to 1 the command will create a flow steering table 3100 * and will classify packets according to this table. The packets 3101 * that miss all the table rules will be classified according to 3102 * settings made in dpni_set_rx_hash_dist() 3103 * If cfg.enable is set to 0 the command will clear flow steering table. The 3104 * packets will be classified according to settings made in 3105 * dpni_set_rx_hash_dist() 3106 */ 3107 int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags, 3108 uint16_t token, const struct dpni_rx_dist_cfg *cfg) 3109 { 3110 struct dpni_cmd_set_rx_fs_dist *cmd_params; 3111 struct mc_command cmd = { 0 }; 3112 3113 /* prepare command */ 3114 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FS_DIST, 3115 cmd_flags, 3116 token); 3117 cmd_params = (struct dpni_cmd_set_rx_fs_dist *)cmd.params; 3118 cmd_params->dist_size = cpu_to_le16(cfg->dist_size); 3119 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable); 3120 cmd_params->tc = cfg->tc; 3121 cmd_params->miss_flow_id = cpu_to_le16(cfg->fs_miss_flow_id); 3122 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova); 3123 3124 /* send command to mc*/ 3125 return mc_send_command(mc_io, &cmd); 3126 } 3127 3128 /** 3129 * dpni_set_rx_hash_dist() - Set Rx traffic class HASH distribution 3130 * @mc_io: Pointer to MC portal's I/O object 3131 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 3132 * @token: Token of DPNI object 3133 * @cfg: Distribution configuration 3134 * If cfg.enable is set to 1 the packets will be classified using a hash 3135 * function based on the key received in cfg.key_cfg_iova parameter. 3136 * If cfg.enable is set to 0 the packets will be sent to the queue configured in 3137 * dpni_set_rx_dist_default_queue() call 3138 */ 3139 int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags, 3140 uint16_t token, const struct dpni_rx_dist_cfg *cfg) 3141 { 3142 struct dpni_cmd_set_rx_hash_dist *cmd_params; 3143 struct mc_command cmd = { 0 }; 3144 3145 /* prepare command */ 3146 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_HASH_DIST, 3147 cmd_flags, 3148 token); 3149 cmd_params = (struct dpni_cmd_set_rx_hash_dist *)cmd.params; 3150 cmd_params->dist_size = cpu_to_le16(cfg->dist_size); 3151 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable); 3152 cmd_params->tc_id = cfg->tc; 3153 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova); 3154 3155 /* send command to mc*/ 3156 return mc_send_command(mc_io, &cmd); 3157 } 3158 3159 /** 3160 * dpni_add_custom_tpid() - Configures a distinct Ethertype value (or TPID 3161 * value) to indicate VLAN tag in adition to the common TPID values 3162 * 0x81000 and 0x88A8 3163 * @mc_io: Pointer to MC portal's I/O object 3164 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 3165 * @token: Token of DPNI object 3166 * @tpid: New value for TPID 3167 * 3168 * Only two custom values are accepted. If the function is called for the third 3169 * time it will return error. 3170 * To replace an existing value use dpni_remove_custom_tpid() to remove a 3171 * previous TPID and after that use again the function. 3172 * 3173 * Return: '0' on Success; Error code otherwise. 3174 */ 3175 int dpni_add_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags, 3176 uint16_t token, uint16_t tpid) 3177 { 3178 struct dpni_cmd_add_custom_tpid *cmd_params; 3179 struct mc_command cmd = { 0 }; 3180 3181 /* prepare command */ 3182 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_CUSTOM_TPID, 3183 cmd_flags, 3184 token); 3185 cmd_params = (struct dpni_cmd_add_custom_tpid *)cmd.params; 3186 cmd_params->tpid = cpu_to_le16(tpid); 3187 3188 /* send command to mc*/ 3189 return mc_send_command(mc_io, &cmd); 3190 } 3191 3192 /** 3193 * dpni_remove_custom_tpid() - Removes a distinct Ethertype value added 3194 * previously with dpni_add_custom_tpid() 3195 * @mc_io: Pointer to MC portal's I/O object 3196 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 3197 * @token: Token of DPNI object 3198 * @tpid: New value for TPID 3199 * 3200 * Use this function when a TPID value added with dpni_add_custom_tpid() needs 3201 * to be replaced. 3202 * 3203 * Return: '0' on Success; Error code otherwise. 3204 */ 3205 int dpni_remove_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags, 3206 uint16_t token, uint16_t tpid) 3207 { 3208 struct dpni_cmd_remove_custom_tpid *cmd_params; 3209 struct mc_command cmd = { 0 }; 3210 3211 /* prepare command */ 3212 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_CUSTOM_TPID, 3213 cmd_flags, 3214 token); 3215 cmd_params = (struct dpni_cmd_remove_custom_tpid *)cmd.params; 3216 cmd_params->tpid = cpu_to_le16(tpid); 3217 3218 /* send command to mc*/ 3219 return mc_send_command(mc_io, &cmd); 3220 } 3221 3222 /** 3223 * dpni_get_custom_tpid() - Returns custom TPID (vlan tags) values configured to 3224 * detect 802.1q frames 3225 * @mc_io: Pointer to MC portal's I/O object 3226 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 3227 * @token: Token of DPNI object 3228 * @tpid: TPID values. Only nonzero members of the structure are valid. 3229 * 3230 * Return: '0' on Success; Error code otherwise. 3231 */ 3232 int dpni_get_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags, 3233 uint16_t token, struct dpni_custom_tpid_cfg *tpid) 3234 { 3235 struct dpni_rsp_get_custom_tpid *rsp_params; 3236 struct mc_command cmd = { 0 }; 3237 int err; 3238 3239 /* prepare command */ 3240 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_CUSTOM_TPID, 3241 cmd_flags, 3242 token); 3243 3244 /* send command to mc*/ 3245 err = mc_send_command(mc_io, &cmd); 3246 if (err) 3247 return err; 3248 3249 /* read command response */ 3250 rsp_params = (struct dpni_rsp_get_custom_tpid *)cmd.params; 3251 tpid->tpid1 = le16_to_cpu(rsp_params->tpid1); 3252 tpid->tpid2 = le16_to_cpu(rsp_params->tpid2); 3253 3254 return err; 3255 } 3256 3257 /** 3258 * dpni_set_port_cfg() - performs configurations at physical port connected on 3259 * this dpni. The command have effect only if dpni is connected to 3260 * another dpni object 3261 * @mc_io: Pointer to MC portal's I/O object 3262 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 3263 * @token: Token of DPNI object 3264 * @flags: Valid fields from port_cfg structure 3265 * @port_cfg: Configuration data; one or more of DPNI_PORT_CFG_ 3266 * The command can be called only when dpni is connected to a dpmac object. If 3267 * the dpni is unconnected or the endpoint is not a dpni it will return error. 3268 * If dpmac endpoint is disconnected the settings will be lost 3269 */ 3270 int dpni_set_port_cfg(struct fsl_mc_io *mc_io, uint32_t cmd_flags, 3271 uint16_t token, uint32_t flags, struct dpni_port_cfg *port_cfg) 3272 { 3273 struct dpni_cmd_set_port_cfg *cmd_params; 3274 struct mc_command cmd = { 0 }; 3275 3276 /* prepare command */ 3277 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PORT_CFG, 3278 cmd_flags, token); 3279 3280 cmd_params = (struct dpni_cmd_set_port_cfg *)cmd.params; 3281 cmd_params->flags = cpu_to_le32(flags); 3282 dpni_set_field(cmd_params->bit_params, PORT_LOOPBACK_EN, !!port_cfg->loopback_en); 3283 3284 /* send command to MC */ 3285 return mc_send_command(mc_io, &cmd); 3286 } 3287 3288 /** 3289 * dpni_get_single_step_cfg() - return current configuration for single step PTP 3290 * @mc_io: Pointer to MC portal's I/O object 3291 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 3292 * @token: Token of DPNI object 3293 * @ptp_cfg: ptp single step configuration 3294 * 3295 * Return: '0' on Success; Error code otherwise. 3296 * 3297 */ 3298 int dpni_get_single_step_cfg(struct fsl_mc_io *mc_io, uint32_t cmd_flags, uint16_t token, 3299 struct dpni_single_step_cfg *ptp_cfg) 3300 { 3301 struct dpni_rsp_single_step_cfg *rsp_params; 3302 struct mc_command cmd = { 0 }; 3303 int err; 3304 3305 /* prepare command */ 3306 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_SINGLE_STEP_CFG, 3307 cmd_flags, 3308 token); 3309 /* send command to mc*/ 3310 err = mc_send_command(mc_io, &cmd); 3311 if (err) 3312 return err; 3313 3314 /* read command response */ 3315 rsp_params = (struct dpni_rsp_single_step_cfg *)cmd.params; 3316 ptp_cfg->offset = le16_to_cpu(rsp_params->offset); 3317 ptp_cfg->en = dpni_get_field(rsp_params->flags, PTP_ENABLE); 3318 ptp_cfg->ch_update = dpni_get_field(rsp_params->flags, PTP_CH_UPDATE); 3319 ptp_cfg->peer_delay = le32_to_cpu(rsp_params->peer_delay); 3320 ptp_cfg->ptp_onestep_reg_base = 3321 le32_to_cpu(rsp_params->ptp_onestep_reg_base); 3322 3323 return err; 3324 } 3325 3326 /** 3327 * dpni_get_port_cfg() - return configuration from physical port. The command has effect only if 3328 * dpni is connected to a mac object 3329 * @mc_io: Pointer to MC portal's I/O object 3330 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 3331 * @token: Token of DPNI object 3332 * @port_cfg: Configuration data 3333 * The command can be called only when dpni is connected to a dpmac object. 3334 * If the dpni is unconnected or the endpoint is not a dpni it will return error; 3335 */ 3336 int dpni_get_port_cfg(struct fsl_mc_io *mc_io, uint32_t cmd_flags, uint16_t token, 3337 struct dpni_port_cfg *port_cfg) 3338 { 3339 struct dpni_rsp_get_port_cfg *rsp_params; 3340 struct mc_command cmd = { 0 }; 3341 int err; 3342 3343 /* prepare command */ 3344 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_CFG, 3345 cmd_flags, token); 3346 3347 /* send command to MC */ 3348 err = mc_send_command(mc_io, &cmd); 3349 if (err) 3350 return err; 3351 3352 /* read command response */ 3353 rsp_params = (struct dpni_rsp_get_port_cfg *)cmd.params; 3354 port_cfg->loopback_en = dpni_get_field(rsp_params->bit_params, PORT_LOOPBACK_EN); 3355 3356 return 0; 3357 } 3358 3359 /** 3360 * dpni_set_single_step_cfg() - enable/disable and configure single step PTP 3361 * @mc_io: Pointer to MC portal's I/O object 3362 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 3363 * @token: Token of DPNI object 3364 * @ptp_cfg: ptp single step configuration 3365 * 3366 * Return: '0' on Success; Error code otherwise. 3367 * 3368 * The function has effect only when dpni object is connected to a dpmac object. If the 3369 * dpni is not connected to a dpmac the configuration will be stored inside and applied 3370 * when connection is made. 3371 */ 3372 int dpni_set_single_step_cfg(struct fsl_mc_io *mc_io, uint32_t cmd_flags, uint16_t token, 3373 struct dpni_single_step_cfg *ptp_cfg) 3374 { 3375 struct dpni_cmd_single_step_cfg *cmd_params; 3376 struct mc_command cmd = { 0 }; 3377 3378 /* prepare command */ 3379 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_SINGLE_STEP_CFG, 3380 cmd_flags, 3381 token); 3382 cmd_params = (struct dpni_cmd_single_step_cfg *)cmd.params; 3383 cmd_params->offset = cpu_to_le16(ptp_cfg->offset); 3384 cmd_params->peer_delay = cpu_to_le32(ptp_cfg->peer_delay); 3385 dpni_set_field(cmd_params->flags, PTP_ENABLE, !!ptp_cfg->en); 3386 dpni_set_field(cmd_params->flags, PTP_CH_UPDATE, !!ptp_cfg->ch_update); 3387 3388 /* send command to mc*/ 3389 return mc_send_command(mc_io, &cmd); 3390 } 3391 3392 /** 3393 * dpni_dump_table() - Dump the content of table_type table into memory. 3394 * @mc_io: Pointer to MC portal's I/O object 3395 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 3396 * @token: Token of DPSW object 3397 * @table_type: The type of the table to dump 3398 * @table_index: The index of the table to dump in case of more than one table 3399 * @iova_addr: The snapshot will be stored in this variable as an header of struct dump_table_header 3400 * followed by an array of struct dump_table_entry 3401 * @iova_size: Memory size allocated for iova_addr 3402 * @num_entries: Number of entries written in iova_addr 3403 * 3404 * Return: Completion status. '0' on Success; Error code otherwise. 3405 * 3406 * The memory allocated at iova_addr must be zeroed before command execution. 3407 * If the table content exceeds the memory size provided the dump will be truncated. 3408 */ 3409 int dpni_dump_table(struct fsl_mc_io *mc_io, 3410 uint32_t cmd_flags, 3411 uint16_t token, 3412 uint16_t table_type, 3413 uint16_t table_index, 3414 uint64_t iova_addr, 3415 uint32_t iova_size, 3416 uint16_t *num_entries) 3417 { 3418 struct mc_command cmd = { 0 }; 3419 int err; 3420 struct dpni_cmd_dump_table *cmd_params; 3421 struct dpni_rsp_dump_table *rsp_params; 3422 3423 /* prepare command */ 3424 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DUMP_TABLE, cmd_flags, token); 3425 cmd_params = (struct dpni_cmd_dump_table *)cmd.params; 3426 cmd_params->table_type = cpu_to_le16(table_type); 3427 cmd_params->table_index = cpu_to_le16(table_index); 3428 cmd_params->iova_addr = cpu_to_le64(iova_addr); 3429 cmd_params->iova_size = cpu_to_le32(iova_size); 3430 3431 /* send command to mc*/ 3432 err = mc_send_command(mc_io, &cmd); 3433 if (err) 3434 return err; 3435 3436 rsp_params = (struct dpni_rsp_dump_table *)cmd.params; 3437 *num_entries = le16_to_cpu(rsp_params->num_entries); 3438 3439 return 0; 3440 } 3441 3442 /* Sets up a Soft Parser Profile on this DPNI 3443 * @mc_io: Pointer to MC portal's I/O object 3444 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 3445 * @token: Token of DPNI object 3446 * @sp_profile: Soft Parser Profile name (must a valid name for a defined profile) 3447 * Maximum allowed length for this string is 8 characters long 3448 * If this parameter is empty string (all zeros) 3449 * then the Default SP Profile is set on this dpni 3450 * @type: one of the SP Profile types defined above: Ingress or Egress (or both using bitwise OR) 3451 */ 3452 int dpni_set_sp_profile(struct fsl_mc_io *mc_io, uint32_t cmd_flags, uint16_t token, 3453 uint8_t sp_profile[], uint8_t type) 3454 { 3455 struct dpni_cmd_set_sp_profile *cmd_params; 3456 struct mc_command cmd = { 0 }; 3457 int i; 3458 3459 /* prepare command */ 3460 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_SP_PROFILE, 3461 cmd_flags, token); 3462 3463 cmd_params = (struct dpni_cmd_set_sp_profile *)cmd.params; 3464 for (i = 0; i < MAX_SP_PROFILE_ID_SIZE && sp_profile[i]; i++) 3465 cmd_params->sp_profile[i] = sp_profile[i]; 3466 cmd_params->type = type; 3467 3468 /* send command to MC */ 3469 return mc_send_command(mc_io, &cmd); 3470 } 3471 3472 /* Enable/Disable Soft Parser on this DPNI 3473 * @mc_io: Pointer to MC portal's I/O object 3474 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 3475 * @token: Token of DPNI object 3476 * @type: one of the SP Profile types defined above: Ingress or Egress (or both using bitwise OR) 3477 * @en: 1 to enable or 0 to disable 3478 */ 3479 int dpni_sp_enable(struct fsl_mc_io *mc_io, uint32_t cmd_flags, uint16_t token, 3480 uint8_t type, uint8_t en) 3481 { 3482 struct dpni_cmd_sp_enable *cmd_params; 3483 struct mc_command cmd = { 0 }; 3484 3485 /* prepare command */ 3486 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SP_ENABLE, 3487 cmd_flags, token); 3488 3489 cmd_params = (struct dpni_cmd_sp_enable *)cmd.params; 3490 cmd_params->type = type; 3491 cmd_params->en = en; 3492 3493 /* send command to MC */ 3494 return mc_send_command(mc_io, &cmd); 3495 } 3496