1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0) 2 * 3 * Copyright 2013-2016 Freescale Semiconductor Inc. 4 * Copyright 2016 NXP 5 * 6 */ 7 #include <fsl_mc_sys.h> 8 #include <fsl_mc_cmd.h> 9 #include <fsl_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 130 /* send command to mc*/ 131 err = mc_send_command(mc_io, &cmd); 132 if (err) 133 return err; 134 135 /* retrieve response parameters */ 136 *obj_id = mc_cmd_read_object_id(&cmd); 137 138 return 0; 139 } 140 141 /** 142 * dpni_destroy() - Destroy the DPNI object and release all its resources. 143 * @mc_io: Pointer to MC portal's I/O object 144 * @dprc_token: Parent container token; '0' for default container 145 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 146 * @object_id: The object id; it must be a valid id within the container that 147 * created this object; 148 * 149 * The function accepts the authentication token of the parent container that 150 * created the object (not the one that currently owns the object). The object 151 * is searched within parent using the provided 'object_id'. 152 * All tokens to the object must be closed before calling destroy. 153 * 154 * Return: '0' on Success; error code otherwise. 155 */ 156 int dpni_destroy(struct fsl_mc_io *mc_io, 157 uint16_t dprc_token, 158 uint32_t cmd_flags, 159 uint32_t object_id) 160 { 161 struct dpni_cmd_destroy *cmd_params; 162 struct mc_command cmd = { 0 }; 163 164 /* prepare command */ 165 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DESTROY, 166 cmd_flags, 167 dprc_token); 168 /* set object id to destroy */ 169 cmd_params = (struct dpni_cmd_destroy *)cmd.params; 170 cmd_params->dpsw_id = cpu_to_le32(object_id); 171 172 /* send command to mc*/ 173 return mc_send_command(mc_io, &cmd); 174 } 175 176 /** 177 * dpni_set_pools() - Set buffer pools configuration 178 * @mc_io: Pointer to MC portal's I/O object 179 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 180 * @token: Token of DPNI object 181 * @cfg: Buffer pools configuration 182 * 183 * mandatory for DPNI operation 184 * warning:Allowed only when DPNI is disabled 185 * 186 * Return: '0' on Success; Error code otherwise. 187 */ 188 int dpni_set_pools(struct fsl_mc_io *mc_io, 189 uint32_t cmd_flags, 190 uint16_t token, 191 const struct dpni_pools_cfg *cfg) 192 { 193 struct mc_command cmd = { 0 }; 194 struct dpni_cmd_set_pools *cmd_params; 195 int i; 196 197 /* prepare command */ 198 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_POOLS, 199 cmd_flags, 200 token); 201 cmd_params = (struct dpni_cmd_set_pools *)cmd.params; 202 cmd_params->num_dpbp = cfg->num_dpbp; 203 for (i = 0; i < cmd_params->num_dpbp; i++) { 204 cmd_params->pool[i].dpbp_id = 205 cpu_to_le16(cfg->pools[i].dpbp_id); 206 cmd_params->pool[i].priority_mask = 207 cfg->pools[i].priority_mask; 208 cmd_params->buffer_size[i] = 209 cpu_to_le16(cfg->pools[i].buffer_size); 210 cmd_params->backup_pool_mask |= 211 DPNI_BACKUP_POOL(cfg->pools[i].backup_pool, i); 212 } 213 214 /* send command to mc*/ 215 return mc_send_command(mc_io, &cmd); 216 } 217 218 /** 219 * dpni_enable() - Enable the DPNI, allow sending and receiving frames. 220 * @mc_io: Pointer to MC portal's I/O object 221 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 222 * @token: Token of DPNI object 223 * 224 * Return: '0' on Success; Error code otherwise. 225 */ 226 int dpni_enable(struct fsl_mc_io *mc_io, 227 uint32_t cmd_flags, 228 uint16_t token) 229 { 230 struct mc_command cmd = { 0 }; 231 232 /* prepare command */ 233 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE, 234 cmd_flags, 235 token); 236 237 /* send command to mc*/ 238 return mc_send_command(mc_io, &cmd); 239 } 240 241 /** 242 * dpni_disable() - Disable the DPNI, stop sending and receiving frames. 243 * @mc_io: Pointer to MC portal's I/O object 244 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 245 * @token: Token of DPNI object 246 * 247 * Return: '0' on Success; Error code otherwise. 248 */ 249 int dpni_disable(struct fsl_mc_io *mc_io, 250 uint32_t cmd_flags, 251 uint16_t token) 252 { 253 struct mc_command cmd = { 0 }; 254 255 /* prepare command */ 256 cmd.header = mc_encode_cmd_header(DPNI_CMDID_DISABLE, 257 cmd_flags, 258 token); 259 260 /* send command to mc*/ 261 return mc_send_command(mc_io, &cmd); 262 } 263 264 /** 265 * dpni_is_enabled() - Check if the DPNI is enabled. 266 * @mc_io: Pointer to MC portal's I/O object 267 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 268 * @token: Token of DPNI object 269 * @en: Returns '1' if object is enabled; '0' otherwise 270 * 271 * Return: '0' on Success; Error code otherwise. 272 */ 273 int dpni_is_enabled(struct fsl_mc_io *mc_io, 274 uint32_t cmd_flags, 275 uint16_t token, 276 int *en) 277 { 278 struct mc_command cmd = { 0 }; 279 struct dpni_rsp_is_enabled *rsp_params; 280 int err; 281 282 /* prepare command */ 283 cmd.header = mc_encode_cmd_header(DPNI_CMDID_IS_ENABLED, 284 cmd_flags, 285 token); 286 287 /* send command to mc*/ 288 err = mc_send_command(mc_io, &cmd); 289 if (err) 290 return err; 291 292 /* retrieve response parameters */ 293 rsp_params = (struct dpni_rsp_is_enabled *)cmd.params; 294 *en = dpni_get_field(rsp_params->enabled, ENABLE); 295 296 return 0; 297 } 298 299 /** 300 * dpni_reset() - Reset the DPNI, returns the object to initial state. 301 * @mc_io: Pointer to MC portal's I/O object 302 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 303 * @token: Token of DPNI object 304 * 305 * Return: '0' on Success; Error code otherwise. 306 */ 307 int dpni_reset(struct fsl_mc_io *mc_io, 308 uint32_t cmd_flags, 309 uint16_t token) 310 { 311 struct mc_command cmd = { 0 }; 312 313 /* prepare command */ 314 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET, 315 cmd_flags, 316 token); 317 318 /* send command to mc*/ 319 return mc_send_command(mc_io, &cmd); 320 } 321 322 /** 323 * dpni_set_irq_enable() - Set overall interrupt state. 324 * @mc_io: Pointer to MC portal's I/O object 325 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 326 * @token: Token of DPNI object 327 * @irq_index: The interrupt index to configure 328 * @en: Interrupt state: - enable = 1, disable = 0 329 * 330 * Allows GPP software to control when interrupts are generated. 331 * Each interrupt can have up to 32 causes. The enable/disable control's the 332 * overall interrupt state. if the interrupt is disabled no causes will cause 333 * an interrupt. 334 * 335 * Return: '0' on Success; Error code otherwise. 336 */ 337 int dpni_set_irq_enable(struct fsl_mc_io *mc_io, 338 uint32_t cmd_flags, 339 uint16_t token, 340 uint8_t irq_index, 341 uint8_t en) 342 { 343 struct mc_command cmd = { 0 }; 344 struct dpni_cmd_set_irq_enable *cmd_params; 345 346 /* prepare command */ 347 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_ENABLE, 348 cmd_flags, 349 token); 350 cmd_params = (struct dpni_cmd_set_irq_enable *)cmd.params; 351 dpni_set_field(cmd_params->enable, ENABLE, en); 352 cmd_params->irq_index = irq_index; 353 354 /* send command to mc*/ 355 return mc_send_command(mc_io, &cmd); 356 } 357 358 /** 359 * dpni_get_irq_enable() - Get overall interrupt state 360 * @mc_io: Pointer to MC portal's I/O object 361 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 362 * @token: Token of DPNI object 363 * @irq_index: The interrupt index to configure 364 * @en: Returned interrupt state - enable = 1, disable = 0 365 * 366 * Return: '0' on Success; Error code otherwise. 367 */ 368 int dpni_get_irq_enable(struct fsl_mc_io *mc_io, 369 uint32_t cmd_flags, 370 uint16_t token, 371 uint8_t irq_index, 372 uint8_t *en) 373 { 374 struct mc_command cmd = { 0 }; 375 struct dpni_cmd_get_irq_enable *cmd_params; 376 struct dpni_rsp_get_irq_enable *rsp_params; 377 378 int err; 379 380 /* prepare command */ 381 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_ENABLE, 382 cmd_flags, 383 token); 384 cmd_params = (struct dpni_cmd_get_irq_enable *)cmd.params; 385 cmd_params->irq_index = irq_index; 386 387 /* send command to mc*/ 388 err = mc_send_command(mc_io, &cmd); 389 if (err) 390 return err; 391 392 /* retrieve response parameters */ 393 rsp_params = (struct dpni_rsp_get_irq_enable *)cmd.params; 394 *en = dpni_get_field(rsp_params->enabled, ENABLE); 395 396 return 0; 397 } 398 399 /** 400 * dpni_set_irq_mask() - Set interrupt mask. 401 * @mc_io: Pointer to MC portal's I/O object 402 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 403 * @token: Token of DPNI object 404 * @irq_index: The interrupt index to configure 405 * @mask: Event mask to trigger interrupt; 406 * each bit: 407 * 0 = ignore event 408 * 1 = consider event for asserting IRQ 409 * 410 * Every interrupt can have up to 32 causes and the interrupt model supports 411 * masking/unmasking each cause independently 412 * 413 * Return: '0' on Success; Error code otherwise. 414 */ 415 int dpni_set_irq_mask(struct fsl_mc_io *mc_io, 416 uint32_t cmd_flags, 417 uint16_t token, 418 uint8_t irq_index, 419 uint32_t mask) 420 { 421 struct mc_command cmd = { 0 }; 422 struct dpni_cmd_set_irq_mask *cmd_params; 423 424 /* prepare command */ 425 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_IRQ_MASK, 426 cmd_flags, 427 token); 428 cmd_params = (struct dpni_cmd_set_irq_mask *)cmd.params; 429 cmd_params->mask = cpu_to_le32(mask); 430 cmd_params->irq_index = irq_index; 431 432 /* send command to mc*/ 433 return mc_send_command(mc_io, &cmd); 434 } 435 436 /** 437 * dpni_get_irq_mask() - Get interrupt mask. 438 * @mc_io: Pointer to MC portal's I/O object 439 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 440 * @token: Token of DPNI object 441 * @irq_index: The interrupt index to configure 442 * @mask: Returned event mask to trigger interrupt 443 * 444 * Every interrupt can have up to 32 causes and the interrupt model supports 445 * masking/unmasking each cause independently 446 * 447 * Return: '0' on Success; Error code otherwise. 448 */ 449 int dpni_get_irq_mask(struct fsl_mc_io *mc_io, 450 uint32_t cmd_flags, 451 uint16_t token, 452 uint8_t irq_index, 453 uint32_t *mask) 454 { 455 struct mc_command cmd = { 0 }; 456 struct dpni_cmd_get_irq_mask *cmd_params; 457 struct dpni_rsp_get_irq_mask *rsp_params; 458 int err; 459 460 /* prepare command */ 461 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_MASK, 462 cmd_flags, 463 token); 464 cmd_params = (struct dpni_cmd_get_irq_mask *)cmd.params; 465 cmd_params->irq_index = irq_index; 466 467 /* send command to mc*/ 468 err = mc_send_command(mc_io, &cmd); 469 if (err) 470 return err; 471 472 /* retrieve response parameters */ 473 rsp_params = (struct dpni_rsp_get_irq_mask *)cmd.params; 474 *mask = le32_to_cpu(rsp_params->mask); 475 476 return 0; 477 } 478 479 /** 480 * dpni_get_irq_status() - Get the current status of any pending interrupts. 481 * @mc_io: Pointer to MC portal's I/O object 482 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 483 * @token: Token of DPNI object 484 * @irq_index: The interrupt index to configure 485 * @status: Returned interrupts status - one bit per cause: 486 * 0 = no interrupt pending 487 * 1 = interrupt pending 488 * 489 * Return: '0' on Success; Error code otherwise. 490 */ 491 int dpni_get_irq_status(struct fsl_mc_io *mc_io, 492 uint32_t cmd_flags, 493 uint16_t token, 494 uint8_t irq_index, 495 uint32_t *status) 496 { 497 struct mc_command cmd = { 0 }; 498 struct dpni_cmd_get_irq_status *cmd_params; 499 struct dpni_rsp_get_irq_status *rsp_params; 500 int err; 501 502 /* prepare command */ 503 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_IRQ_STATUS, 504 cmd_flags, 505 token); 506 cmd_params = (struct dpni_cmd_get_irq_status *)cmd.params; 507 cmd_params->status = cpu_to_le32(*status); 508 cmd_params->irq_index = irq_index; 509 510 /* send command to mc*/ 511 err = mc_send_command(mc_io, &cmd); 512 if (err) 513 return err; 514 515 /* retrieve response parameters */ 516 rsp_params = (struct dpni_rsp_get_irq_status *)cmd.params; 517 *status = le32_to_cpu(rsp_params->status); 518 519 return 0; 520 } 521 522 /** 523 * dpni_clear_irq_status() - Clear a pending interrupt's status 524 * @mc_io: Pointer to MC portal's I/O object 525 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 526 * @token: Token of DPNI object 527 * @irq_index: The interrupt index to configure 528 * @status: bits to clear (W1C) - one bit per cause: 529 * 0 = don't change 530 * 1 = clear status bit 531 * 532 * Return: '0' on Success; Error code otherwise. 533 */ 534 int dpni_clear_irq_status(struct fsl_mc_io *mc_io, 535 uint32_t cmd_flags, 536 uint16_t token, 537 uint8_t irq_index, 538 uint32_t status) 539 { 540 struct mc_command cmd = { 0 }; 541 struct dpni_cmd_clear_irq_status *cmd_params; 542 543 /* prepare command */ 544 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLEAR_IRQ_STATUS, 545 cmd_flags, 546 token); 547 cmd_params = (struct dpni_cmd_clear_irq_status *)cmd.params; 548 cmd_params->irq_index = irq_index; 549 cmd_params->status = cpu_to_le32(status); 550 551 /* send command to mc*/ 552 return mc_send_command(mc_io, &cmd); 553 } 554 555 /** 556 * dpni_get_attributes() - Retrieve DPNI attributes. 557 * @mc_io: Pointer to MC portal's I/O object 558 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 559 * @token: Token of DPNI object 560 * @attr: Object's attributes 561 * 562 * Return: '0' on Success; Error code otherwise. 563 */ 564 int dpni_get_attributes(struct fsl_mc_io *mc_io, 565 uint32_t cmd_flags, 566 uint16_t token, 567 struct dpni_attr *attr) 568 { 569 struct mc_command cmd = { 0 }; 570 struct dpni_rsp_get_attr *rsp_params; 571 572 int err; 573 574 /* prepare command */ 575 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_ATTR, 576 cmd_flags, 577 token); 578 579 /* send command to mc*/ 580 err = mc_send_command(mc_io, &cmd); 581 if (err) 582 return err; 583 584 /* retrieve response parameters */ 585 rsp_params = (struct dpni_rsp_get_attr *)cmd.params; 586 attr->options = le32_to_cpu(rsp_params->options); 587 attr->num_queues = rsp_params->num_queues; 588 attr->num_rx_tcs = rsp_params->num_rx_tcs; 589 attr->num_tx_tcs = rsp_params->num_tx_tcs; 590 attr->mac_filter_entries = rsp_params->mac_filter_entries; 591 attr->vlan_filter_entries = rsp_params->vlan_filter_entries; 592 attr->qos_entries = rsp_params->qos_entries; 593 attr->fs_entries = le16_to_cpu(rsp_params->fs_entries); 594 attr->qos_key_size = rsp_params->qos_key_size; 595 attr->fs_key_size = rsp_params->fs_key_size; 596 attr->wriop_version = le16_to_cpu(rsp_params->wriop_version); 597 attr->num_cgs = rsp_params->num_cgs; 598 599 return 0; 600 } 601 602 /** 603 * dpni_set_errors_behavior() - Set errors behavior 604 * @mc_io: Pointer to MC portal's I/O object 605 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 606 * @token: Token of DPNI object 607 * @cfg: Errors configuration 608 * 609 * This function may be called numerous times with different 610 * error masks 611 * 612 * Return: '0' on Success; Error code otherwise. 613 */ 614 int dpni_set_errors_behavior(struct fsl_mc_io *mc_io, 615 uint32_t cmd_flags, 616 uint16_t token, 617 struct dpni_error_cfg *cfg) 618 { 619 struct mc_command cmd = { 0 }; 620 struct dpni_cmd_set_errors_behavior *cmd_params; 621 622 /* prepare command */ 623 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_ERRORS_BEHAVIOR, 624 cmd_flags, 625 token); 626 cmd_params = (struct dpni_cmd_set_errors_behavior *)cmd.params; 627 cmd_params->errors = cpu_to_le32(cfg->errors); 628 dpni_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action); 629 dpni_set_field(cmd_params->flags, FRAME_ANN, cfg->set_frame_annotation); 630 631 /* send command to mc*/ 632 return mc_send_command(mc_io, &cmd); 633 } 634 635 /** 636 * dpni_get_buffer_layout() - Retrieve buffer layout attributes. 637 * @mc_io: Pointer to MC portal's I/O object 638 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 639 * @token: Token of DPNI object 640 * @qtype: Type of queue to retrieve configuration for 641 * @layout: Returns buffer layout attributes 642 * 643 * Return: '0' on Success; Error code otherwise. 644 */ 645 int dpni_get_buffer_layout(struct fsl_mc_io *mc_io, 646 uint32_t cmd_flags, 647 uint16_t token, 648 enum dpni_queue_type qtype, 649 struct dpni_buffer_layout *layout) 650 { 651 struct mc_command cmd = { 0 }; 652 struct dpni_cmd_get_buffer_layout *cmd_params; 653 struct dpni_rsp_get_buffer_layout *rsp_params; 654 int err; 655 656 /* prepare command */ 657 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_BUFFER_LAYOUT, 658 cmd_flags, 659 token); 660 cmd_params = (struct dpni_cmd_get_buffer_layout *)cmd.params; 661 cmd_params->qtype = qtype; 662 663 /* send command to mc*/ 664 err = mc_send_command(mc_io, &cmd); 665 if (err) 666 return err; 667 668 /* retrieve response parameters */ 669 rsp_params = (struct dpni_rsp_get_buffer_layout *)cmd.params; 670 layout->pass_timestamp = 671 (int)dpni_get_field(rsp_params->flags, PASS_TS); 672 layout->pass_parser_result = 673 (int)dpni_get_field(rsp_params->flags, PASS_PR); 674 layout->pass_frame_status = 675 (int)dpni_get_field(rsp_params->flags, PASS_FS); 676 layout->pass_sw_opaque = 677 (int)dpni_get_field(rsp_params->flags, PASS_SWO); 678 layout->private_data_size = le16_to_cpu(rsp_params->private_data_size); 679 layout->data_align = le16_to_cpu(rsp_params->data_align); 680 layout->data_head_room = le16_to_cpu(rsp_params->head_room); 681 layout->data_tail_room = le16_to_cpu(rsp_params->tail_room); 682 683 return 0; 684 } 685 686 /** 687 * dpni_set_buffer_layout() - Set buffer layout configuration. 688 * @mc_io: Pointer to MC portal's I/O object 689 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 690 * @token: Token of DPNI object 691 * @qtype: Type of queue this configuration applies to 692 * @layout: Buffer layout configuration 693 * 694 * Return: '0' on Success; Error code otherwise. 695 * 696 * @warning Allowed only when DPNI is disabled 697 */ 698 int dpni_set_buffer_layout(struct fsl_mc_io *mc_io, 699 uint32_t cmd_flags, 700 uint16_t token, 701 enum dpni_queue_type qtype, 702 const struct dpni_buffer_layout *layout) 703 { 704 struct mc_command cmd = { 0 }; 705 struct dpni_cmd_set_buffer_layout *cmd_params; 706 707 /* prepare command */ 708 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_BUFFER_LAYOUT, 709 cmd_flags, 710 token); 711 cmd_params = (struct dpni_cmd_set_buffer_layout *)cmd.params; 712 cmd_params->qtype = qtype; 713 cmd_params->options = cpu_to_le16((uint16_t)layout->options); 714 dpni_set_field(cmd_params->flags, PASS_TS, layout->pass_timestamp); 715 dpni_set_field(cmd_params->flags, PASS_PR, layout->pass_parser_result); 716 dpni_set_field(cmd_params->flags, PASS_FS, layout->pass_frame_status); 717 dpni_set_field(cmd_params->flags, PASS_SWO, layout->pass_sw_opaque); 718 cmd_params->private_data_size = cpu_to_le16(layout->private_data_size); 719 cmd_params->data_align = cpu_to_le16(layout->data_align); 720 cmd_params->head_room = cpu_to_le16(layout->data_head_room); 721 cmd_params->tail_room = cpu_to_le16(layout->data_tail_room); 722 723 /* send command to mc*/ 724 return mc_send_command(mc_io, &cmd); 725 } 726 727 /** 728 * dpni_set_offload() - Set DPNI offload configuration. 729 * @mc_io: Pointer to MC portal's I/O object 730 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 731 * @token: Token of DPNI object 732 * @type: Type of DPNI offload 733 * @config: Offload configuration. 734 * For checksum offloads, non-zero value enables the offload 735 * 736 * Return: '0' on Success; Error code otherwise. 737 * 738 * @warning Allowed only when DPNI is disabled 739 */ 740 741 int dpni_set_offload(struct fsl_mc_io *mc_io, 742 uint32_t cmd_flags, 743 uint16_t token, 744 enum dpni_offload type, 745 uint32_t config) 746 { 747 struct mc_command cmd = { 0 }; 748 struct dpni_cmd_set_offload *cmd_params; 749 750 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_OFFLOAD, 751 cmd_flags, 752 token); 753 cmd_params = (struct dpni_cmd_set_offload *)cmd.params; 754 cmd_params->dpni_offload = type; 755 cmd_params->config = cpu_to_le32(config); 756 757 return mc_send_command(mc_io, &cmd); 758 } 759 760 /** 761 * dpni_get_offload() - Get DPNI offload configuration. 762 * @mc_io: Pointer to MC portal's I/O object 763 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 764 * @token: Token of DPNI object 765 * @type: Type of DPNI offload 766 * @config: Offload configuration. 767 * For checksum offloads, a value of 1 indicates that the 768 * offload is enabled. 769 * 770 * Return: '0' on Success; Error code otherwise. 771 * 772 * @warning Allowed only when DPNI is disabled 773 */ 774 int dpni_get_offload(struct fsl_mc_io *mc_io, 775 uint32_t cmd_flags, 776 uint16_t token, 777 enum dpni_offload type, 778 uint32_t *config) 779 { 780 struct mc_command cmd = { 0 }; 781 struct dpni_cmd_get_offload *cmd_params; 782 struct dpni_rsp_get_offload *rsp_params; 783 int err; 784 785 /* prepare command */ 786 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OFFLOAD, 787 cmd_flags, 788 token); 789 cmd_params = (struct dpni_cmd_get_offload *)cmd.params; 790 cmd_params->dpni_offload = type; 791 792 /* send command to mc*/ 793 err = mc_send_command(mc_io, &cmd); 794 if (err) 795 return err; 796 797 /* retrieve response parameters */ 798 rsp_params = (struct dpni_rsp_get_offload *)cmd.params; 799 *config = le32_to_cpu(rsp_params->config); 800 801 return 0; 802 } 803 804 /** 805 * dpni_get_qdid() - Get the Queuing Destination ID (QDID) that should be used 806 * for enqueue operations 807 * @mc_io: Pointer to MC portal's I/O object 808 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 809 * @token: Token of DPNI object 810 * @qtype: Type of queue to receive QDID for 811 * @qdid: Returned virtual QDID value that should be used as an argument 812 * in all enqueue operations 813 * 814 * Return: '0' on Success; Error code otherwise. 815 */ 816 int dpni_get_qdid(struct fsl_mc_io *mc_io, 817 uint32_t cmd_flags, 818 uint16_t token, 819 enum dpni_queue_type qtype, 820 uint16_t *qdid) 821 { 822 struct mc_command cmd = { 0 }; 823 struct dpni_cmd_get_qdid *cmd_params; 824 struct dpni_rsp_get_qdid *rsp_params; 825 int err; 826 827 /* prepare command */ 828 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QDID, 829 cmd_flags, 830 token); 831 cmd_params = (struct dpni_cmd_get_qdid *)cmd.params; 832 cmd_params->qtype = qtype; 833 834 /* send command to mc*/ 835 err = mc_send_command(mc_io, &cmd); 836 if (err) 837 return err; 838 839 /* retrieve response parameters */ 840 rsp_params = (struct dpni_rsp_get_qdid *)cmd.params; 841 *qdid = le16_to_cpu(rsp_params->qdid); 842 843 return 0; 844 } 845 846 /** 847 * dpni_get_tx_data_offset() - Get the Tx data offset (from start of buffer) 848 * @mc_io: Pointer to MC portal's I/O object 849 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 850 * @token: Token of DPNI object 851 * @data_offset: Tx data offset (from start of buffer) 852 * 853 * Return: '0' on Success; Error code otherwise. 854 */ 855 int dpni_get_tx_data_offset(struct fsl_mc_io *mc_io, 856 uint32_t cmd_flags, 857 uint16_t token, 858 uint16_t *data_offset) 859 { 860 struct mc_command cmd = { 0 }; 861 struct dpni_rsp_get_tx_data_offset *rsp_params; 862 int err; 863 864 /* prepare command */ 865 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TX_DATA_OFFSET, 866 cmd_flags, 867 token); 868 869 /* send command to mc*/ 870 err = mc_send_command(mc_io, &cmd); 871 if (err) 872 return err; 873 874 /* retrieve response parameters */ 875 rsp_params = (struct dpni_rsp_get_tx_data_offset *)cmd.params; 876 *data_offset = le16_to_cpu(rsp_params->data_offset); 877 878 return 0; 879 } 880 881 /** 882 * dpni_set_link_cfg() - set the link configuration. 883 * @mc_io: Pointer to MC portal's I/O object 884 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 885 * @token: Token of DPNI object 886 * @cfg: Link configuration 887 * 888 * Return: '0' on Success; Error code otherwise. 889 */ 890 int dpni_set_link_cfg(struct fsl_mc_io *mc_io, 891 uint32_t cmd_flags, 892 uint16_t token, 893 const struct dpni_link_cfg *cfg) 894 { 895 struct mc_command cmd = { 0 }; 896 struct dpni_cmd_set_link_cfg *cmd_params; 897 898 /* prepare command */ 899 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_LINK_CFG, 900 cmd_flags, 901 token); 902 cmd_params = (struct dpni_cmd_set_link_cfg *)cmd.params; 903 cmd_params->rate = cpu_to_le32(cfg->rate); 904 cmd_params->options = cpu_to_le64(cfg->options); 905 cmd_params->advertising = cpu_to_le64(cfg->advertising); 906 907 /* send command to mc*/ 908 return mc_send_command(mc_io, &cmd); 909 } 910 911 /** 912 * dpni_get_link_state() - Return the link state (either up or down) 913 * @mc_io: Pointer to MC portal's I/O object 914 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 915 * @token: Token of DPNI object 916 * @state: Returned link state; 917 * 918 * Return: '0' on Success; Error code otherwise. 919 */ 920 int dpni_get_link_state(struct fsl_mc_io *mc_io, 921 uint32_t cmd_flags, 922 uint16_t token, 923 struct dpni_link_state *state) 924 { 925 struct mc_command cmd = { 0 }; 926 struct dpni_rsp_get_link_state *rsp_params; 927 int err; 928 929 /* prepare command */ 930 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_LINK_STATE, 931 cmd_flags, 932 token); 933 934 /* send command to mc*/ 935 err = mc_send_command(mc_io, &cmd); 936 if (err) 937 return err; 938 939 /* retrieve response parameters */ 940 rsp_params = (struct dpni_rsp_get_link_state *)cmd.params; 941 state->up = dpni_get_field(rsp_params->flags, LINK_STATE); 942 state->state_valid = dpni_get_field(rsp_params->flags, STATE_VALID); 943 state->rate = le32_to_cpu(rsp_params->rate); 944 state->options = le64_to_cpu(rsp_params->options); 945 state->supported = le64_to_cpu(rsp_params->supported); 946 state->advertising = le64_to_cpu(rsp_params->advertising); 947 948 return 0; 949 } 950 951 /** 952 * dpni_set_max_frame_length() - Set the maximum received frame length. 953 * @mc_io: Pointer to MC portal's I/O object 954 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 955 * @token: Token of DPNI object 956 * @max_frame_length: Maximum received frame length (in bytes); 957 * frame is discarded if its length exceeds this value 958 * 959 * Return: '0' on Success; Error code otherwise. 960 */ 961 int dpni_set_max_frame_length(struct fsl_mc_io *mc_io, 962 uint32_t cmd_flags, 963 uint16_t token, 964 uint16_t max_frame_length) 965 { 966 struct mc_command cmd = { 0 }; 967 struct dpni_cmd_set_max_frame_length *cmd_params; 968 969 /* prepare command */ 970 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MAX_FRAME_LENGTH, 971 cmd_flags, 972 token); 973 cmd_params = (struct dpni_cmd_set_max_frame_length *)cmd.params; 974 cmd_params->max_frame_length = cpu_to_le16(max_frame_length); 975 976 /* send command to mc*/ 977 return mc_send_command(mc_io, &cmd); 978 } 979 980 /** 981 * dpni_get_max_frame_length() - Get the maximum received frame length. 982 * @mc_io: Pointer to MC portal's I/O object 983 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 984 * @token: Token of DPNI object 985 * @max_frame_length: Maximum received frame length (in bytes); 986 * frame is discarded if its length exceeds this value 987 * 988 * Return: '0' on Success; Error code otherwise. 989 */ 990 int dpni_get_max_frame_length(struct fsl_mc_io *mc_io, 991 uint32_t cmd_flags, 992 uint16_t token, 993 uint16_t *max_frame_length) 994 { 995 struct mc_command cmd = { 0 }; 996 struct dpni_rsp_get_max_frame_length *rsp_params; 997 int err; 998 999 /* prepare command */ 1000 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MAX_FRAME_LENGTH, 1001 cmd_flags, 1002 token); 1003 1004 /* send command to mc*/ 1005 err = mc_send_command(mc_io, &cmd); 1006 if (err) 1007 return err; 1008 1009 /* retrieve response parameters */ 1010 rsp_params = (struct dpni_rsp_get_max_frame_length *)cmd.params; 1011 *max_frame_length = le16_to_cpu(rsp_params->max_frame_length); 1012 1013 return 0; 1014 } 1015 1016 /** 1017 * dpni_set_multicast_promisc() - Enable/disable multicast promiscuous mode 1018 * @mc_io: Pointer to MC portal's I/O object 1019 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1020 * @token: Token of DPNI object 1021 * @en: Set to '1' to enable; '0' to disable 1022 * 1023 * Return: '0' on Success; Error code otherwise. 1024 */ 1025 int dpni_set_multicast_promisc(struct fsl_mc_io *mc_io, 1026 uint32_t cmd_flags, 1027 uint16_t token, 1028 int en) 1029 { 1030 struct mc_command cmd = { 0 }; 1031 struct dpni_cmd_set_multicast_promisc *cmd_params; 1032 1033 /* prepare command */ 1034 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_MCAST_PROMISC, 1035 cmd_flags, 1036 token); 1037 cmd_params = (struct dpni_cmd_set_multicast_promisc *)cmd.params; 1038 dpni_set_field(cmd_params->enable, ENABLE, en); 1039 1040 /* send command to mc*/ 1041 return mc_send_command(mc_io, &cmd); 1042 } 1043 1044 /** 1045 * dpni_get_multicast_promisc() - Get multicast promiscuous mode 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 * @en: Returns '1' if enabled; '0' otherwise 1050 * 1051 * Return: '0' on Success; Error code otherwise. 1052 */ 1053 int dpni_get_multicast_promisc(struct fsl_mc_io *mc_io, 1054 uint32_t cmd_flags, 1055 uint16_t token, 1056 int *en) 1057 { 1058 struct mc_command cmd = { 0 }; 1059 struct dpni_rsp_get_multicast_promisc *rsp_params; 1060 int err; 1061 1062 /* prepare command */ 1063 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_MCAST_PROMISC, 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_multicast_promisc *)cmd.params; 1074 *en = dpni_get_field(rsp_params->enabled, ENABLE); 1075 1076 return 0; 1077 } 1078 1079 /** 1080 * dpni_set_unicast_promisc() - Enable/disable unicast promiscuous mode 1081 * @mc_io: Pointer to MC portal's I/O object 1082 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1083 * @token: Token of DPNI object 1084 * @en: Set to '1' to enable; '0' to disable 1085 * 1086 * Return: '0' on Success; Error code otherwise. 1087 */ 1088 int dpni_set_unicast_promisc(struct fsl_mc_io *mc_io, 1089 uint32_t cmd_flags, 1090 uint16_t token, 1091 int en) 1092 { 1093 struct mc_command cmd = { 0 }; 1094 struct dpni_cmd_set_unicast_promisc *cmd_params; 1095 1096 /* prepare command */ 1097 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_UNICAST_PROMISC, 1098 cmd_flags, 1099 token); 1100 cmd_params = (struct dpni_cmd_set_unicast_promisc *)cmd.params; 1101 dpni_set_field(cmd_params->enable, ENABLE, en); 1102 1103 /* send command to mc*/ 1104 return mc_send_command(mc_io, &cmd); 1105 } 1106 1107 /** 1108 * dpni_get_unicast_promisc() - Get unicast promiscuous mode 1109 * @mc_io: Pointer to MC portal's I/O object 1110 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1111 * @token: Token of DPNI object 1112 * @en: Returns '1' if enabled; '0' otherwise 1113 * 1114 * Return: '0' on Success; Error code otherwise. 1115 */ 1116 int dpni_get_unicast_promisc(struct fsl_mc_io *mc_io, 1117 uint32_t cmd_flags, 1118 uint16_t token, 1119 int *en) 1120 { 1121 struct mc_command cmd = { 0 }; 1122 struct dpni_rsp_get_unicast_promisc *rsp_params; 1123 int err; 1124 1125 /* prepare command */ 1126 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_UNICAST_PROMISC, 1127 cmd_flags, 1128 token); 1129 1130 /* send command to mc*/ 1131 err = mc_send_command(mc_io, &cmd); 1132 if (err) 1133 return err; 1134 1135 /* retrieve response parameters */ 1136 rsp_params = (struct dpni_rsp_get_unicast_promisc *)cmd.params; 1137 *en = dpni_get_field(rsp_params->enabled, ENABLE); 1138 1139 return 0; 1140 } 1141 1142 /** 1143 * dpni_set_primary_mac_addr() - Set the primary MAC address 1144 * @mc_io: Pointer to MC portal's I/O object 1145 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1146 * @token: Token of DPNI object 1147 * @mac_addr: MAC address to set as primary address 1148 * 1149 * Return: '0' on Success; Error code otherwise. 1150 */ 1151 int dpni_set_primary_mac_addr(struct fsl_mc_io *mc_io, 1152 uint32_t cmd_flags, 1153 uint16_t token, 1154 const uint8_t mac_addr[6]) 1155 { 1156 struct mc_command cmd = { 0 }; 1157 struct dpni_cmd_set_primary_mac_addr *cmd_params; 1158 int i; 1159 1160 /* prepare command */ 1161 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_PRIM_MAC, 1162 cmd_flags, 1163 token); 1164 cmd_params = (struct dpni_cmd_set_primary_mac_addr *)cmd.params; 1165 for (i = 0; i < 6; i++) 1166 cmd_params->mac_addr[i] = mac_addr[5 - i]; 1167 1168 /* send command to mc*/ 1169 return mc_send_command(mc_io, &cmd); 1170 } 1171 1172 /** 1173 * dpni_get_primary_mac_addr() - Get the primary MAC address 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 * @mac_addr: Returned MAC address 1178 * 1179 * Return: '0' on Success; Error code otherwise. 1180 */ 1181 int dpni_get_primary_mac_addr(struct fsl_mc_io *mc_io, 1182 uint32_t cmd_flags, 1183 uint16_t token, 1184 uint8_t mac_addr[6]) 1185 { 1186 struct mc_command cmd = { 0 }; 1187 struct dpni_rsp_get_primary_mac_addr *rsp_params; 1188 int i, err; 1189 1190 /* prepare command */ 1191 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PRIM_MAC, 1192 cmd_flags, 1193 token); 1194 1195 /* send command to mc*/ 1196 err = mc_send_command(mc_io, &cmd); 1197 if (err) 1198 return err; 1199 1200 /* retrieve response parameters */ 1201 rsp_params = (struct dpni_rsp_get_primary_mac_addr *)cmd.params; 1202 for (i = 0; i < 6; i++) 1203 mac_addr[5 - i] = rsp_params->mac_addr[i]; 1204 1205 return 0; 1206 } 1207 1208 /** 1209 * dpni_add_mac_addr() - Add MAC address filter 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 * @mac_addr: MAC address to add 1214 * 1215 * Return: '0' on Success; Error code otherwise. 1216 */ 1217 int dpni_add_mac_addr(struct fsl_mc_io *mc_io, 1218 uint32_t cmd_flags, 1219 uint16_t token, 1220 const uint8_t mac_addr[6]) 1221 { 1222 struct mc_command cmd = { 0 }; 1223 struct dpni_cmd_add_mac_addr *cmd_params; 1224 int i; 1225 1226 /* prepare command */ 1227 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_MAC_ADDR, 1228 cmd_flags, 1229 token); 1230 cmd_params = (struct dpni_cmd_add_mac_addr *)cmd.params; 1231 for (i = 0; i < 6; i++) 1232 cmd_params->mac_addr[i] = mac_addr[5 - i]; 1233 1234 /* send command to mc*/ 1235 return mc_send_command(mc_io, &cmd); 1236 } 1237 1238 /** 1239 * dpni_remove_mac_addr() - Remove MAC address filter 1240 * @mc_io: Pointer to MC portal's I/O object 1241 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1242 * @token: Token of DPNI object 1243 * @mac_addr: MAC address to remove 1244 * 1245 * Return: '0' on Success; Error code otherwise. 1246 */ 1247 int dpni_remove_mac_addr(struct fsl_mc_io *mc_io, 1248 uint32_t cmd_flags, 1249 uint16_t token, 1250 const uint8_t mac_addr[6]) 1251 { 1252 struct mc_command cmd = { 0 }; 1253 struct dpni_cmd_remove_mac_addr *cmd_params; 1254 int i; 1255 1256 /* prepare command */ 1257 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_MAC_ADDR, 1258 cmd_flags, 1259 token); 1260 cmd_params = (struct dpni_cmd_remove_mac_addr *)cmd.params; 1261 for (i = 0; i < 6; i++) 1262 cmd_params->mac_addr[i] = mac_addr[5 - i]; 1263 1264 /* send command to mc*/ 1265 return mc_send_command(mc_io, &cmd); 1266 } 1267 1268 /** 1269 * dpni_clear_mac_filters() - Clear all unicast and/or multicast MAC filters 1270 * @mc_io: Pointer to MC portal's I/O object 1271 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1272 * @token: Token of DPNI object 1273 * @unicast: Set to '1' to clear unicast addresses 1274 * @multicast: Set to '1' to clear multicast addresses 1275 * 1276 * The primary MAC address is not cleared by this operation. 1277 * 1278 * Return: '0' on Success; Error code otherwise. 1279 */ 1280 int dpni_clear_mac_filters(struct fsl_mc_io *mc_io, 1281 uint32_t cmd_flags, 1282 uint16_t token, 1283 int unicast, 1284 int multicast) 1285 { 1286 struct mc_command cmd = { 0 }; 1287 struct dpni_cmd_clear_mac_filters *cmd_params; 1288 1289 /* prepare command */ 1290 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_MAC_FILTERS, 1291 cmd_flags, 1292 token); 1293 cmd_params = (struct dpni_cmd_clear_mac_filters *)cmd.params; 1294 dpni_set_field(cmd_params->flags, UNICAST_FILTERS, unicast); 1295 dpni_set_field(cmd_params->flags, MULTICAST_FILTERS, multicast); 1296 1297 /* send command to mc*/ 1298 return mc_send_command(mc_io, &cmd); 1299 } 1300 1301 /** 1302 * dpni_get_port_mac_addr() - Retrieve MAC address associated to the physical 1303 * port the DPNI is attached to 1304 * @mc_io: Pointer to MC portal's I/O object 1305 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1306 * @token: Token of DPNI object 1307 * @mac_addr: MAC address of the physical port, if any, otherwise 0 1308 * 1309 * The primary MAC address is not cleared by this operation. 1310 * 1311 * Return: '0' on Success; Error code otherwise. 1312 */ 1313 int dpni_get_port_mac_addr(struct fsl_mc_io *mc_io, 1314 uint32_t cmd_flags, 1315 uint16_t token, 1316 uint8_t mac_addr[6]) 1317 { 1318 struct mc_command cmd = { 0 }; 1319 struct dpni_rsp_get_port_mac_addr *rsp_params; 1320 int i, err; 1321 1322 /* prepare command */ 1323 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_PORT_MAC_ADDR, 1324 cmd_flags, 1325 token); 1326 1327 /* send command to mc*/ 1328 err = mc_send_command(mc_io, &cmd); 1329 if (err) 1330 return err; 1331 1332 /* retrieve response parameters */ 1333 rsp_params = (struct dpni_rsp_get_port_mac_addr *)cmd.params; 1334 for (i = 0; i < 6; i++) 1335 mac_addr[5 - i] = rsp_params->mac_addr[i]; 1336 1337 return 0; 1338 } 1339 1340 /** 1341 * dpni_enable_vlan_filter() - Enable/disable VLAN filtering mode 1342 * @mc_io: Pointer to MC portal's I/O object 1343 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1344 * @token: Token of DPNI object 1345 * @en: Set to '1' to enable; '0' to disable 1346 * 1347 * Return: '0' on Success; Error code otherwise. 1348 */ 1349 int dpni_enable_vlan_filter(struct fsl_mc_io *mc_io, 1350 uint32_t cmd_flags, 1351 uint16_t token, 1352 int en) 1353 { 1354 struct dpni_cmd_enable_vlan_filter *cmd_params; 1355 struct mc_command cmd = { 0 }; 1356 1357 /* prepare command */ 1358 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ENABLE_VLAN_FILTER, 1359 cmd_flags, 1360 token); 1361 cmd_params = (struct dpni_cmd_enable_vlan_filter *)cmd.params; 1362 dpni_set_field(cmd_params->en, ENABLE, en); 1363 1364 /* send command to mc*/ 1365 return mc_send_command(mc_io, &cmd); 1366 } 1367 1368 /** 1369 * dpni_add_vlan_id() - Add VLAN ID filter 1370 * @mc_io: Pointer to MC portal's I/O object 1371 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1372 * @token: Token of DPNI object 1373 * @vlan_id: VLAN ID to add 1374 * 1375 * Return: '0' on Success; Error code otherwise. 1376 */ 1377 int dpni_add_vlan_id(struct fsl_mc_io *mc_io, 1378 uint32_t cmd_flags, 1379 uint16_t token, 1380 uint16_t vlan_id) 1381 { 1382 struct dpni_cmd_vlan_id *cmd_params; 1383 struct mc_command cmd = { 0 }; 1384 1385 /* prepare command */ 1386 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_VLAN_ID, 1387 cmd_flags, 1388 token); 1389 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params; 1390 cmd_params->vlan_id = cpu_to_le16(vlan_id); 1391 1392 /* send command to mc*/ 1393 return mc_send_command(mc_io, &cmd); 1394 } 1395 1396 /** 1397 * dpni_remove_vlan_id() - Remove VLAN ID filter 1398 * @mc_io: Pointer to MC portal's I/O object 1399 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1400 * @token: Token of DPNI object 1401 * @vlan_id: VLAN ID to remove 1402 * 1403 * Return: '0' on Success; Error code otherwise. 1404 */ 1405 int dpni_remove_vlan_id(struct fsl_mc_io *mc_io, 1406 uint32_t cmd_flags, 1407 uint16_t token, 1408 uint16_t vlan_id) 1409 { 1410 struct dpni_cmd_vlan_id *cmd_params; 1411 struct mc_command cmd = { 0 }; 1412 1413 /* prepare command */ 1414 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_VLAN_ID, 1415 cmd_flags, 1416 token); 1417 cmd_params = (struct dpni_cmd_vlan_id *)cmd.params; 1418 cmd_params->vlan_id = cpu_to_le16(vlan_id); 1419 1420 /* send command to mc*/ 1421 return mc_send_command(mc_io, &cmd); 1422 } 1423 1424 /** 1425 * dpni_clear_vlan_filters() - Clear all VLAN filters 1426 * @mc_io: Pointer to MC portal's I/O object 1427 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1428 * @token: Token of DPNI object 1429 * 1430 * Return: '0' on Success; Error code otherwise. 1431 */ 1432 int dpni_clear_vlan_filters(struct fsl_mc_io *mc_io, 1433 uint32_t cmd_flags, 1434 uint16_t token) 1435 { 1436 struct mc_command cmd = { 0 }; 1437 1438 /* prepare command */ 1439 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_VLAN_FILTERS, 1440 cmd_flags, 1441 token); 1442 1443 /* send command to mc*/ 1444 return mc_send_command(mc_io, &cmd); 1445 } 1446 1447 /** 1448 * dpni_set_rx_tc_dist() - Set Rx traffic class distribution configuration 1449 * @mc_io: Pointer to MC portal's I/O object 1450 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1451 * @token: Token of DPNI object 1452 * @tc_id: Traffic class selection (0-7) 1453 * @cfg: Traffic class distribution configuration 1454 * 1455 * warning: if 'dist_mode != DPNI_DIST_MODE_NONE', call dpkg_prepare_key_cfg() 1456 * first to prepare the key_cfg_iova parameter 1457 * 1458 * Return: '0' on Success; error code otherwise. 1459 */ 1460 int dpni_set_rx_tc_dist(struct fsl_mc_io *mc_io, 1461 uint32_t cmd_flags, 1462 uint16_t token, 1463 uint8_t tc_id, 1464 const struct dpni_rx_tc_dist_cfg *cfg) 1465 { 1466 struct mc_command cmd = { 0 }; 1467 struct dpni_cmd_set_rx_tc_dist *cmd_params; 1468 1469 /* prepare command */ 1470 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_TC_DIST, 1471 cmd_flags, 1472 token); 1473 cmd_params = (struct dpni_cmd_set_rx_tc_dist *)cmd.params; 1474 cmd_params->dist_size = cpu_to_le16(cfg->dist_size); 1475 cmd_params->tc_id = tc_id; 1476 cmd_params->default_flow_id = cpu_to_le16(cfg->fs_cfg.default_flow_id); 1477 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova); 1478 dpni_set_field(cmd_params->flags, 1479 DIST_MODE, 1480 cfg->dist_mode); 1481 dpni_set_field(cmd_params->flags, 1482 MISS_ACTION, 1483 cfg->fs_cfg.miss_action); 1484 dpni_set_field(cmd_params->keep_hash_key, 1485 KEEP_HASH_KEY, 1486 cfg->fs_cfg.keep_hash_key); 1487 dpni_set_field(cmd_params->keep_hash_key, 1488 KEEP_ENTRIES, 1489 cfg->fs_cfg.keep_entries); 1490 1491 /* send command to mc*/ 1492 return mc_send_command(mc_io, &cmd); 1493 } 1494 1495 /** 1496 * dpni_set_tx_confirmation_mode() - Tx confirmation mode 1497 * @mc_io: Pointer to MC portal's I/O object 1498 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1499 * @token: Token of DPNI object 1500 * @mode: Tx confirmation mode 1501 * 1502 * This function is useful only when 'DPNI_OPT_TX_CONF_DISABLED' is not 1503 * selected at DPNI creation. 1504 * Calling this function with 'mode' set to DPNI_CONF_DISABLE disables all 1505 * transmit confirmation (including the private confirmation queues), regardless 1506 * of previous settings; Note that in this case, Tx error frames are still 1507 * enqueued to the general transmit errors queue. 1508 * Calling this function with 'mode' set to DPNI_CONF_SINGLE switches all 1509 * Tx confirmations to a shared Tx conf queue. 'index' field in dpni_get_queue 1510 * command will be ignored. 1511 * 1512 * Return: '0' on Success; Error code otherwise. 1513 */ 1514 int dpni_set_tx_confirmation_mode(struct fsl_mc_io *mc_io, 1515 uint32_t cmd_flags, 1516 uint16_t token, 1517 enum dpni_confirmation_mode mode) 1518 { 1519 struct dpni_tx_confirmation_mode *cmd_params; 1520 struct mc_command cmd = { 0 }; 1521 1522 /* prepare command */ 1523 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TX_CONFIRMATION_MODE, 1524 cmd_flags, 1525 token); 1526 cmd_params = (struct dpni_tx_confirmation_mode *)cmd.params; 1527 cmd_params->confirmation_mode = mode; 1528 1529 /* send command to mc*/ 1530 return mc_send_command(mc_io, &cmd); 1531 } 1532 1533 /** 1534 * dpni_set_qos_table() - Set QoS mapping table 1535 * @mc_io: Pointer to MC portal's I/O object 1536 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1537 * @token: Token of DPNI object 1538 * @cfg: QoS table configuration 1539 * 1540 * This function and all QoS-related functions require that 1541 *'max_tcs > 1' was set at DPNI creation. 1542 * 1543 * warning: Before calling this function, call dpkg_prepare_key_cfg() to 1544 * prepare the key_cfg_iova parameter 1545 * 1546 * Return: '0' on Success; Error code otherwise. 1547 */ 1548 int dpni_set_qos_table(struct fsl_mc_io *mc_io, 1549 uint32_t cmd_flags, 1550 uint16_t token, 1551 const struct dpni_qos_tbl_cfg *cfg) 1552 { 1553 struct dpni_cmd_set_qos_table *cmd_params; 1554 struct mc_command cmd = { 0 }; 1555 1556 /* prepare command */ 1557 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QOS_TBL, 1558 cmd_flags, 1559 token); 1560 cmd_params = (struct dpni_cmd_set_qos_table *)cmd.params; 1561 cmd_params->default_tc = cfg->default_tc; 1562 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova); 1563 dpni_set_field(cmd_params->discard_on_miss, 1564 ENABLE, 1565 cfg->discard_on_miss); 1566 dpni_set_field(cmd_params->discard_on_miss, 1567 KEEP_QOS_ENTRIES, 1568 cfg->keep_entries); 1569 1570 /* send command to mc*/ 1571 return mc_send_command(mc_io, &cmd); 1572 } 1573 1574 /** 1575 * dpni_add_qos_entry() - Add QoS mapping entry (to select a traffic class) 1576 * @mc_io: Pointer to MC portal's I/O object 1577 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1578 * @token: Token of DPNI object 1579 * @cfg: QoS rule to add 1580 * @tc_id: Traffic class selection (0-7) 1581 * @index: Location in the QoS table where to insert the entry. 1582 * Only relevant if MASKING is enabled for QoS classification on 1583 * this DPNI, it is ignored for exact match. 1584 * 1585 * Return: '0' on Success; Error code otherwise. 1586 */ 1587 int dpni_add_qos_entry(struct fsl_mc_io *mc_io, 1588 uint32_t cmd_flags, 1589 uint16_t token, 1590 const struct dpni_rule_cfg *cfg, 1591 uint8_t tc_id, 1592 uint16_t index) 1593 { 1594 struct dpni_cmd_add_qos_entry *cmd_params; 1595 struct mc_command cmd = { 0 }; 1596 1597 /* prepare command */ 1598 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_QOS_ENT, 1599 cmd_flags, 1600 token); 1601 cmd_params = (struct dpni_cmd_add_qos_entry *)cmd.params; 1602 cmd_params->tc_id = tc_id; 1603 cmd_params->key_size = cfg->key_size; 1604 cmd_params->index = cpu_to_le16(index); 1605 cmd_params->key_iova = cpu_to_le64(cfg->key_iova); 1606 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova); 1607 1608 /* send command to mc*/ 1609 return mc_send_command(mc_io, &cmd); 1610 } 1611 1612 /** 1613 * dpni_remove_qos_entry() - Remove QoS mapping entry 1614 * @mc_io: Pointer to MC portal's I/O object 1615 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1616 * @token: Token of DPNI object 1617 * @cfg: QoS rule to remove 1618 * 1619 * Return: '0' on Success; Error code otherwise. 1620 */ 1621 int dpni_remove_qos_entry(struct fsl_mc_io *mc_io, 1622 uint32_t cmd_flags, 1623 uint16_t token, 1624 const struct dpni_rule_cfg *cfg) 1625 { 1626 struct dpni_cmd_remove_qos_entry *cmd_params; 1627 struct mc_command cmd = { 0 }; 1628 1629 /* prepare command */ 1630 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_QOS_ENT, 1631 cmd_flags, 1632 token); 1633 cmd_params = (struct dpni_cmd_remove_qos_entry *)cmd.params; 1634 cmd_params->key_size = cfg->key_size; 1635 cmd_params->key_iova = cpu_to_le64(cfg->key_iova); 1636 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova); 1637 1638 /* send command to mc*/ 1639 return mc_send_command(mc_io, &cmd); 1640 } 1641 1642 /** 1643 * dpni_clear_qos_table() - Clear all QoS mapping entries 1644 * @mc_io: Pointer to MC portal's I/O object 1645 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1646 * @token: Token of DPNI object 1647 * 1648 * Following this function call, all frames are directed to 1649 * the default traffic class (0) 1650 * 1651 * Return: '0' on Success; Error code otherwise. 1652 */ 1653 int dpni_clear_qos_table(struct fsl_mc_io *mc_io, 1654 uint32_t cmd_flags, 1655 uint16_t token) 1656 { 1657 struct mc_command cmd = { 0 }; 1658 1659 /* prepare command */ 1660 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_QOS_TBL, 1661 cmd_flags, 1662 token); 1663 1664 /* send command to mc*/ 1665 return mc_send_command(mc_io, &cmd); 1666 } 1667 1668 /** 1669 * dpni_add_fs_entry() - Add Flow Steering entry for a specific traffic class 1670 * (to select a flow ID) 1671 * @mc_io: Pointer to MC portal's I/O object 1672 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1673 * @token: Token of DPNI object 1674 * @tc_id: Traffic class selection (0-7) 1675 * @index: Location in the QoS table where to insert the entry. 1676 * Only relevant if MASKING is enabled for QoS classification 1677 * on this DPNI, it is ignored for exact match. 1678 * @cfg: Flow steering rule to add 1679 * @action: Action to be taken as result of a classification hit 1680 * 1681 * Return: '0' on Success; Error code otherwise. 1682 */ 1683 int dpni_add_fs_entry(struct fsl_mc_io *mc_io, 1684 uint32_t cmd_flags, 1685 uint16_t token, 1686 uint8_t tc_id, 1687 uint16_t index, 1688 const struct dpni_rule_cfg *cfg, 1689 const struct dpni_fs_action_cfg *action) 1690 { 1691 struct dpni_cmd_add_fs_entry *cmd_params; 1692 struct mc_command cmd = { 0 }; 1693 1694 /* prepare command */ 1695 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_FS_ENT, 1696 cmd_flags, 1697 token); 1698 cmd_params = (struct dpni_cmd_add_fs_entry *)cmd.params; 1699 cmd_params->tc_id = tc_id; 1700 cmd_params->key_size = cfg->key_size; 1701 cmd_params->index = cpu_to_le16(index); 1702 cmd_params->key_iova = cpu_to_le64(cfg->key_iova); 1703 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova); 1704 cmd_params->options = cpu_to_le16(action->options); 1705 cmd_params->flow_id = cpu_to_le16(action->flow_id); 1706 cmd_params->flc = cpu_to_le64(action->flc); 1707 1708 /* send command to mc*/ 1709 return mc_send_command(mc_io, &cmd); 1710 } 1711 1712 /** 1713 * dpni_remove_fs_entry() - Remove Flow Steering entry from a specific 1714 * traffic class 1715 * @mc_io: Pointer to MC portal's I/O object 1716 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1717 * @token: Token of DPNI object 1718 * @tc_id: Traffic class selection (0-7) 1719 * @cfg: Flow steering rule to remove 1720 * 1721 * Return: '0' on Success; Error code otherwise. 1722 */ 1723 int dpni_remove_fs_entry(struct fsl_mc_io *mc_io, 1724 uint32_t cmd_flags, 1725 uint16_t token, 1726 uint8_t tc_id, 1727 const struct dpni_rule_cfg *cfg) 1728 { 1729 struct dpni_cmd_remove_fs_entry *cmd_params; 1730 struct mc_command cmd = { 0 }; 1731 1732 /* prepare command */ 1733 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_FS_ENT, 1734 cmd_flags, 1735 token); 1736 cmd_params = (struct dpni_cmd_remove_fs_entry *)cmd.params; 1737 cmd_params->tc_id = tc_id; 1738 cmd_params->key_size = cfg->key_size; 1739 cmd_params->key_iova = cpu_to_le64(cfg->key_iova); 1740 cmd_params->mask_iova = cpu_to_le64(cfg->mask_iova); 1741 1742 /* send command to mc*/ 1743 return mc_send_command(mc_io, &cmd); 1744 } 1745 1746 /** 1747 * dpni_clear_fs_entries() - Clear all Flow Steering entries of a specific 1748 * traffic class 1749 * @mc_io: Pointer to MC portal's I/O object 1750 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1751 * @token: Token of DPNI object 1752 * @tc_id: Traffic class selection (0-7) 1753 * 1754 * Return: '0' on Success; Error code otherwise. 1755 */ 1756 int dpni_clear_fs_entries(struct fsl_mc_io *mc_io, 1757 uint32_t cmd_flags, 1758 uint16_t token, 1759 uint8_t tc_id) 1760 { 1761 struct dpni_cmd_clear_fs_entries *cmd_params; 1762 struct mc_command cmd = { 0 }; 1763 1764 /* prepare command */ 1765 cmd.header = mc_encode_cmd_header(DPNI_CMDID_CLR_FS_ENT, 1766 cmd_flags, 1767 token); 1768 cmd_params = (struct dpni_cmd_clear_fs_entries *)cmd.params; 1769 cmd_params->tc_id = tc_id; 1770 1771 /* send command to mc*/ 1772 return mc_send_command(mc_io, &cmd); 1773 } 1774 1775 /** 1776 * dpni_set_congestion_notification() - Set traffic class congestion 1777 * notification configuration 1778 * @mc_io: Pointer to MC portal's I/O object 1779 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1780 * @token: Token of DPNI object 1781 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported 1782 * @tc_id: Traffic class selection (0-7) 1783 * @cfg: congestion notification configuration 1784 * 1785 * Return: '0' on Success; error code otherwise. 1786 */ 1787 int dpni_set_congestion_notification(struct fsl_mc_io *mc_io, 1788 uint32_t cmd_flags, 1789 uint16_t token, 1790 enum dpni_queue_type qtype, 1791 uint8_t tc_id, 1792 const struct dpni_congestion_notification_cfg *cfg) 1793 { 1794 struct dpni_cmd_set_congestion_notification *cmd_params; 1795 struct mc_command cmd = { 0 }; 1796 1797 /* prepare command */ 1798 cmd.header = mc_encode_cmd_header( 1799 DPNI_CMDID_SET_CONGESTION_NOTIFICATION, 1800 cmd_flags, 1801 token); 1802 cmd_params = (struct dpni_cmd_set_congestion_notification *)cmd.params; 1803 cmd_params->qtype = qtype; 1804 cmd_params->tc = tc_id; 1805 cmd_params->congestion_point = cfg->cg_point; 1806 cmd_params->cgid = (uint8_t)cfg->cgid; 1807 cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id); 1808 cmd_params->notification_mode = cpu_to_le16(cfg->notification_mode); 1809 cmd_params->dest_priority = cfg->dest_cfg.priority; 1810 cmd_params->message_iova = cpu_to_le64(cfg->message_iova); 1811 cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx); 1812 cmd_params->threshold_entry = cpu_to_le32(cfg->threshold_entry); 1813 cmd_params->threshold_exit = cpu_to_le32(cfg->threshold_exit); 1814 dpni_set_field(cmd_params->type_units, 1815 DEST_TYPE, 1816 cfg->dest_cfg.dest_type); 1817 dpni_set_field(cmd_params->type_units, 1818 CONG_UNITS, 1819 cfg->units); 1820 1821 /* send command to mc*/ 1822 return mc_send_command(mc_io, &cmd); 1823 } 1824 1825 /** 1826 * dpni_get_congestion_notification() - Get traffic class congestion 1827 * notification configuration 1828 * @mc_io: Pointer to MC portal's I/O object 1829 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1830 * @token: Token of DPNI object 1831 * @qtype: Type of queue - Rx, Tx and Tx confirm types are supported 1832 * @tc_id: Traffic class selection (0-7) 1833 * @cfg: congestion notification configuration 1834 * 1835 * Return: '0' on Success; error code otherwise. 1836 */ 1837 int dpni_get_congestion_notification(struct fsl_mc_io *mc_io, 1838 uint32_t cmd_flags, 1839 uint16_t token, 1840 enum dpni_queue_type qtype, 1841 uint8_t tc_id, 1842 struct dpni_congestion_notification_cfg *cfg) 1843 { 1844 struct dpni_rsp_get_congestion_notification *rsp_params; 1845 struct dpni_cmd_get_congestion_notification *cmd_params; 1846 struct mc_command cmd = { 0 }; 1847 int err; 1848 1849 /* prepare command */ 1850 cmd.header = mc_encode_cmd_header( 1851 DPNI_CMDID_GET_CONGESTION_NOTIFICATION, 1852 cmd_flags, 1853 token); 1854 cmd_params = (struct dpni_cmd_get_congestion_notification *)cmd.params; 1855 cmd_params->qtype = qtype; 1856 cmd_params->tc = tc_id; 1857 cmd_params->congestion_point = cfg->cg_point; 1858 cmd_params->cgid = cfg->cgid; 1859 1860 /* send command to mc*/ 1861 err = mc_send_command(mc_io, &cmd); 1862 if (err) 1863 return err; 1864 1865 rsp_params = (struct dpni_rsp_get_congestion_notification *)cmd.params; 1866 cfg->units = dpni_get_field(rsp_params->type_units, CONG_UNITS); 1867 cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry); 1868 cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit); 1869 cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx); 1870 cfg->message_iova = le64_to_cpu(rsp_params->message_iova); 1871 cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode); 1872 cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id); 1873 cfg->dest_cfg.priority = rsp_params->dest_priority; 1874 cfg->dest_cfg.dest_type = dpni_get_field(rsp_params->type_units, 1875 DEST_TYPE); 1876 1877 return 0; 1878 } 1879 1880 /** 1881 * dpni_get_api_version() - Get Data Path Network Interface API version 1882 * @mc_io: Pointer to MC portal's I/O object 1883 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1884 * @major_ver: Major version of data path network interface API 1885 * @minor_ver: Minor version of data path network interface API 1886 * 1887 * Return: '0' on Success; Error code otherwise. 1888 */ 1889 int dpni_get_api_version(struct fsl_mc_io *mc_io, 1890 uint32_t cmd_flags, 1891 uint16_t *major_ver, 1892 uint16_t *minor_ver) 1893 { 1894 struct dpni_rsp_get_api_version *rsp_params; 1895 struct mc_command cmd = { 0 }; 1896 int err; 1897 1898 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_API_VERSION, 1899 cmd_flags, 1900 0); 1901 1902 err = mc_send_command(mc_io, &cmd); 1903 if (err) 1904 return err; 1905 1906 rsp_params = (struct dpni_rsp_get_api_version *)cmd.params; 1907 *major_ver = le16_to_cpu(rsp_params->major); 1908 *minor_ver = le16_to_cpu(rsp_params->minor); 1909 1910 return 0; 1911 } 1912 1913 /** 1914 * dpni_set_queue() - Set queue parameters 1915 * @mc_io: Pointer to MC portal's I/O object 1916 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1917 * @token: Token of DPNI object 1918 * @qtype: Type of queue - all queue types are supported, although 1919 * the command is ignored for Tx 1920 * @tc: Traffic class, in range 0 to NUM_TCS - 1 1921 * @index: Selects the specific queue out of the set allocated for the 1922 * same TC. Value must be in range 0 to NUM_QUEUES - 1 1923 * @options: A combination of DPNI_QUEUE_OPT_ values that control what 1924 * configuration options are set on the queue 1925 * @queue: Queue structure 1926 * 1927 * Return: '0' on Success; Error code otherwise. 1928 */ 1929 int dpni_set_queue(struct fsl_mc_io *mc_io, 1930 uint32_t cmd_flags, 1931 uint16_t token, 1932 enum dpni_queue_type qtype, 1933 uint8_t tc, 1934 uint8_t index, 1935 uint8_t options, 1936 const struct dpni_queue *queue) 1937 { 1938 struct mc_command cmd = { 0 }; 1939 struct dpni_cmd_set_queue *cmd_params; 1940 1941 /* prepare command */ 1942 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_QUEUE, 1943 cmd_flags, 1944 token); 1945 cmd_params = (struct dpni_cmd_set_queue *)cmd.params; 1946 cmd_params->qtype = qtype; 1947 cmd_params->tc = tc; 1948 cmd_params->index = index; 1949 cmd_params->options = options; 1950 cmd_params->dest_id = cpu_to_le32(queue->destination.id); 1951 cmd_params->dest_prio = queue->destination.priority; 1952 dpni_set_field(cmd_params->flags, DEST_TYPE, queue->destination.type); 1953 dpni_set_field(cmd_params->flags, STASH_CTRL, queue->flc.stash_control); 1954 dpni_set_field(cmd_params->flags, HOLD_ACTIVE, 1955 queue->destination.hold_active); 1956 cmd_params->flc = cpu_to_le64(queue->flc.value); 1957 cmd_params->user_context = cpu_to_le64(queue->user_context); 1958 cmd_params->cgid = queue->cgid; 1959 1960 /* send command to mc */ 1961 return mc_send_command(mc_io, &cmd); 1962 } 1963 1964 /** 1965 * dpni_get_queue() - Get queue parameters 1966 * @mc_io: Pointer to MC portal's I/O object 1967 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 1968 * @token: Token of DPNI object 1969 * @qtype: Type of queue - all queue types are supported 1970 * @tc: Traffic class, in range 0 to NUM_TCS - 1 1971 * @index: Selects the specific queue out of the set allocated for the 1972 * same TC. Value must be in range 0 to NUM_QUEUES - 1 1973 * @queue: Queue configuration structure 1974 * @qid: Queue identification 1975 * 1976 * Return: '0' on Success; Error code otherwise. 1977 */ 1978 int dpni_get_queue(struct fsl_mc_io *mc_io, 1979 uint32_t cmd_flags, 1980 uint16_t token, 1981 enum dpni_queue_type qtype, 1982 uint8_t tc, 1983 uint8_t index, 1984 struct dpni_queue *queue, 1985 struct dpni_queue_id *qid) 1986 { 1987 struct mc_command cmd = { 0 }; 1988 struct dpni_cmd_get_queue *cmd_params; 1989 struct dpni_rsp_get_queue *rsp_params; 1990 int err; 1991 1992 /* prepare command */ 1993 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_QUEUE, 1994 cmd_flags, 1995 token); 1996 cmd_params = (struct dpni_cmd_get_queue *)cmd.params; 1997 cmd_params->qtype = qtype; 1998 cmd_params->tc = tc; 1999 cmd_params->index = index; 2000 2001 /* send command to mc */ 2002 err = mc_send_command(mc_io, &cmd); 2003 if (err) 2004 return err; 2005 2006 /* retrieve response parameters */ 2007 rsp_params = (struct dpni_rsp_get_queue *)cmd.params; 2008 queue->destination.id = le32_to_cpu(rsp_params->dest_id); 2009 queue->destination.priority = rsp_params->dest_prio; 2010 queue->destination.type = dpni_get_field(rsp_params->flags, 2011 DEST_TYPE); 2012 queue->flc.stash_control = dpni_get_field(rsp_params->flags, 2013 STASH_CTRL); 2014 queue->destination.hold_active = dpni_get_field(rsp_params->flags, 2015 HOLD_ACTIVE); 2016 queue->flc.value = le64_to_cpu(rsp_params->flc); 2017 queue->user_context = le64_to_cpu(rsp_params->user_context); 2018 qid->fqid = le32_to_cpu(rsp_params->fqid); 2019 qid->qdbin = le16_to_cpu(rsp_params->qdbin); 2020 if (dpni_get_field(rsp_params->flags, CGID_VALID)) 2021 queue->cgid = rsp_params->cgid; 2022 else 2023 queue->cgid = -1; 2024 2025 return 0; 2026 } 2027 2028 /** 2029 * dpni_get_statistics() - Get DPNI statistics 2030 * @mc_io: Pointer to MC portal's I/O object 2031 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2032 * @token: Token of DPNI object 2033 * @page: Selects the statistics page to retrieve, see 2034 * DPNI_GET_STATISTICS output. Pages are numbered 0 to 3. 2035 * @param: Custom parameter for some pages used to select 2036 * a certain statistic source, for example the TC. 2037 * @stat: Structure containing the statistics 2038 * 2039 * Return: '0' on Success; Error code otherwise. 2040 */ 2041 int dpni_get_statistics(struct fsl_mc_io *mc_io, 2042 uint32_t cmd_flags, 2043 uint16_t token, 2044 uint8_t page, 2045 uint16_t param, 2046 union dpni_statistics *stat) 2047 { 2048 struct mc_command cmd = { 0 }; 2049 struct dpni_cmd_get_statistics *cmd_params; 2050 struct dpni_rsp_get_statistics *rsp_params; 2051 int i, err; 2052 2053 /* prepare command */ 2054 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_STATISTICS, 2055 cmd_flags, 2056 token); 2057 cmd_params = (struct dpni_cmd_get_statistics *)cmd.params; 2058 cmd_params->page_number = page; 2059 cmd_params->param = param; 2060 2061 /* send command to mc */ 2062 err = mc_send_command(mc_io, &cmd); 2063 if (err) 2064 return err; 2065 2066 /* retrieve response parameters */ 2067 rsp_params = (struct dpni_rsp_get_statistics *)cmd.params; 2068 for (i = 0; i < DPNI_STATISTICS_CNT; i++) 2069 stat->raw.counter[i] = le64_to_cpu(rsp_params->counter[i]); 2070 2071 return 0; 2072 } 2073 2074 /** 2075 * dpni_reset_statistics() - Clears DPNI statistics 2076 * @mc_io: Pointer to MC portal's I/O object 2077 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2078 * @token: Token of DPNI object 2079 * 2080 * Return: '0' on Success; Error code otherwise. 2081 */ 2082 int dpni_reset_statistics(struct fsl_mc_io *mc_io, 2083 uint32_t cmd_flags, 2084 uint16_t token) 2085 { 2086 struct mc_command cmd = { 0 }; 2087 2088 /* prepare command */ 2089 cmd.header = mc_encode_cmd_header(DPNI_CMDID_RESET_STATISTICS, 2090 cmd_flags, 2091 token); 2092 2093 /* send command to mc*/ 2094 return mc_send_command(mc_io, &cmd); 2095 } 2096 2097 /** 2098 * dpni_set_taildrop() - Set taildrop per queue or TC 2099 * 2100 * Setting a per-TC taildrop (cg_point = DPNI_CP_GROUP) will reset any current 2101 * congestion notification or early drop (WRED) configuration previously applied 2102 * to the same TC. 2103 * 2104 * @mc_io: Pointer to MC portal's I/O object 2105 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2106 * @token: Token of DPNI object 2107 * @cg_point: Congestion point, DPNI_CP_QUEUE is only supported in 2108 * combination with DPNI_QUEUE_RX. 2109 * @q_type: Queue type, can be DPNI_QUEUE_RX or DPNI_QUEUE_TX. 2110 * @tc: Traffic class to apply this taildrop to 2111 * @q_index: Index of the queue if the DPNI supports multiple queues for 2112 * traffic distribution. 2113 * Ignored if CONGESTION_POINT is not DPNI_CP_QUEUE. 2114 * @taildrop: Taildrop structure 2115 * 2116 * Return: '0' on Success; Error code otherwise. 2117 */ 2118 int dpni_set_taildrop(struct fsl_mc_io *mc_io, 2119 uint32_t cmd_flags, 2120 uint16_t token, 2121 enum dpni_congestion_point cg_point, 2122 enum dpni_queue_type qtype, 2123 uint8_t tc, 2124 uint8_t index, 2125 struct dpni_taildrop *taildrop) 2126 { 2127 struct mc_command cmd = { 0 }; 2128 struct dpni_cmd_set_taildrop *cmd_params; 2129 2130 /* prepare command */ 2131 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_TAILDROP, 2132 cmd_flags, 2133 token); 2134 cmd_params = (struct dpni_cmd_set_taildrop *)cmd.params; 2135 cmd_params->congestion_point = cg_point; 2136 cmd_params->qtype = qtype; 2137 cmd_params->tc = tc; 2138 cmd_params->index = index; 2139 cmd_params->units = taildrop->units; 2140 cmd_params->threshold = cpu_to_le32(taildrop->threshold); 2141 dpni_set_field(cmd_params->enable_oal_lo, ENABLE, taildrop->enable); 2142 dpni_set_field(cmd_params->enable_oal_lo, OAL_LO, taildrop->oal); 2143 dpni_set_field(cmd_params->oal_hi, 2144 OAL_HI, 2145 taildrop->oal >> DPNI_OAL_LO_SIZE); 2146 2147 /* send command to mc */ 2148 return mc_send_command(mc_io, &cmd); 2149 } 2150 2151 /** 2152 * dpni_get_taildrop() - Get taildrop information 2153 * @mc_io: Pointer to MC portal's I/O object 2154 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2155 * @token: Token of DPNI object 2156 * @cg_point: Congestion point 2157 * @q_type: Queue type on which the taildrop is configured. 2158 * Only Rx queues are supported for now 2159 * @tc: Traffic class to apply this taildrop to 2160 * @q_index: Index of the queue if the DPNI supports multiple queues for 2161 * traffic distribution. Ignored if CONGESTION_POINT is not 0. 2162 * @taildrop: Taildrop structure 2163 * 2164 * Return: '0' on Success; Error code otherwise. 2165 */ 2166 int dpni_get_taildrop(struct fsl_mc_io *mc_io, 2167 uint32_t cmd_flags, 2168 uint16_t token, 2169 enum dpni_congestion_point cg_point, 2170 enum dpni_queue_type qtype, 2171 uint8_t tc, 2172 uint8_t index, 2173 struct dpni_taildrop *taildrop) 2174 { 2175 struct mc_command cmd = { 0 }; 2176 struct dpni_cmd_get_taildrop *cmd_params; 2177 struct dpni_rsp_get_taildrop *rsp_params; 2178 uint8_t oal_lo, oal_hi; 2179 int err; 2180 2181 /* prepare command */ 2182 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_TAILDROP, 2183 cmd_flags, 2184 token); 2185 cmd_params = (struct dpni_cmd_get_taildrop *)cmd.params; 2186 cmd_params->congestion_point = cg_point; 2187 cmd_params->qtype = qtype; 2188 cmd_params->tc = tc; 2189 cmd_params->index = index; 2190 2191 /* send command to mc */ 2192 err = mc_send_command(mc_io, &cmd); 2193 if (err) 2194 return err; 2195 2196 /* retrieve response parameters */ 2197 rsp_params = (struct dpni_rsp_get_taildrop *)cmd.params; 2198 taildrop->enable = dpni_get_field(rsp_params->enable_oal_lo, ENABLE); 2199 taildrop->units = rsp_params->units; 2200 taildrop->threshold = le32_to_cpu(rsp_params->threshold); 2201 oal_lo = dpni_get_field(rsp_params->enable_oal_lo, OAL_LO); 2202 oal_hi = dpni_get_field(rsp_params->oal_hi, OAL_HI); 2203 taildrop->oal = oal_hi << DPNI_OAL_LO_SIZE | oal_lo; 2204 2205 /* Fill the first 4 bits, 'oal' is a 2's complement value of 12 bits */ 2206 if (taildrop->oal >= 0x0800) 2207 taildrop->oal |= 0xF000; 2208 2209 return 0; 2210 } 2211 2212 /** 2213 * dpni_set_opr() - Set Order Restoration configuration. 2214 * @mc_io: Pointer to MC portal's I/O object 2215 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2216 * @token: Token of DPNI object 2217 * @tc: Traffic class, in range 0 to NUM_TCS - 1 2218 * @index: Selects the specific queue out of the set allocated 2219 * for the same TC. Value must be in range 0 to 2220 * NUM_QUEUES - 1 2221 * @options: Configuration mode options 2222 * can be OPR_OPT_CREATE or OPR_OPT_RETIRE 2223 * @cfg: Configuration options for the OPR 2224 * 2225 * Return: '0' on Success; Error code otherwise. 2226 */ 2227 int dpni_set_opr(struct fsl_mc_io *mc_io, 2228 uint32_t cmd_flags, 2229 uint16_t token, 2230 uint8_t tc, 2231 uint8_t index, 2232 uint8_t options, 2233 struct opr_cfg *cfg) 2234 { 2235 struct dpni_cmd_set_opr *cmd_params; 2236 struct mc_command cmd = { 0 }; 2237 2238 /* prepare command */ 2239 cmd.header = mc_encode_cmd_header( 2240 DPNI_CMDID_SET_OPR, 2241 cmd_flags, 2242 token); 2243 cmd_params = (struct dpni_cmd_set_opr *)cmd.params; 2244 cmd_params->tc_id = tc; 2245 cmd_params->index = index; 2246 cmd_params->options = options; 2247 cmd_params->oloe = cfg->oloe; 2248 cmd_params->oeane = cfg->oeane; 2249 cmd_params->olws = cfg->olws; 2250 cmd_params->oa = cfg->oa; 2251 cmd_params->oprrws = cfg->oprrws; 2252 2253 /* send command to mc*/ 2254 return mc_send_command(mc_io, &cmd); 2255 } 2256 2257 /** 2258 * dpni_get_opr() - Retrieve Order Restoration config and query. 2259 * @mc_io: Pointer to MC portal's I/O object 2260 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2261 * @token: Token of DPNI object 2262 * @tc: Traffic class, in range 0 to NUM_TCS - 1 2263 * @index: Selects the specific queue out of the set allocated 2264 * for the same TC. Value must be in range 0 to 2265 * NUM_QUEUES - 1 2266 * @cfg: Returned OPR configuration 2267 * @qry: Returned OPR query 2268 * 2269 * Return: '0' on Success; Error code otherwise. 2270 */ 2271 int dpni_get_opr(struct fsl_mc_io *mc_io, 2272 uint32_t cmd_flags, 2273 uint16_t token, 2274 uint8_t tc, 2275 uint8_t index, 2276 struct opr_cfg *cfg, 2277 struct opr_qry *qry) 2278 { 2279 struct dpni_rsp_get_opr *rsp_params; 2280 struct dpni_cmd_get_opr *cmd_params; 2281 struct mc_command cmd = { 0 }; 2282 int err; 2283 2284 /* prepare command */ 2285 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_OPR, 2286 cmd_flags, 2287 token); 2288 cmd_params = (struct dpni_cmd_get_opr *)cmd.params; 2289 cmd_params->index = index; 2290 cmd_params->tc_id = tc; 2291 2292 /* send command to mc*/ 2293 err = mc_send_command(mc_io, &cmd); 2294 if (err) 2295 return err; 2296 2297 /* retrieve response parameters */ 2298 rsp_params = (struct dpni_rsp_get_opr *)cmd.params; 2299 cfg->oloe = rsp_params->oloe; 2300 cfg->oeane = rsp_params->oeane; 2301 cfg->olws = rsp_params->olws; 2302 cfg->oa = rsp_params->oa; 2303 cfg->oprrws = rsp_params->oprrws; 2304 qry->rip = dpni_get_field(rsp_params->flags, RIP); 2305 qry->enable = dpni_get_field(rsp_params->flags, OPR_ENABLE); 2306 qry->nesn = le16_to_cpu(rsp_params->nesn); 2307 qry->ndsn = le16_to_cpu(rsp_params->ndsn); 2308 qry->ea_tseq = le16_to_cpu(rsp_params->ea_tseq); 2309 qry->tseq_nlis = dpni_get_field(rsp_params->tseq_nlis, TSEQ_NLIS); 2310 qry->ea_hseq = le16_to_cpu(rsp_params->ea_hseq); 2311 qry->hseq_nlis = dpni_get_field(rsp_params->hseq_nlis, HSEQ_NLIS); 2312 qry->ea_hptr = le16_to_cpu(rsp_params->ea_hptr); 2313 qry->ea_tptr = le16_to_cpu(rsp_params->ea_tptr); 2314 qry->opr_vid = le16_to_cpu(rsp_params->opr_vid); 2315 qry->opr_id = le16_to_cpu(rsp_params->opr_id); 2316 2317 return 0; 2318 } 2319 2320 /** 2321 * dpni_set_rx_fs_dist() - Set Rx traffic class FS distribution 2322 * @mc_io: Pointer to MC portal's I/O object 2323 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2324 * @token: Token of DPNI object 2325 * @cfg: Distribution configuration 2326 * If the FS is already enabled with a previous call the classification 2327 * key will be changed but all the table rules are kept. If the 2328 * existing rules do not match the key the results will not be 2329 * predictable. It is the user responsibility to keep key integrity 2330 * If cfg.enable is set to 1 the command will create a flow steering table 2331 * and will classify packets according to this table. The packets 2332 * that miss all the table rules will be classified according to 2333 * settings made in dpni_set_rx_hash_dist() 2334 * If cfg.enable is set to 0 the command will clear flow steering table. The 2335 * packets will be classified according to settings made in 2336 * dpni_set_rx_hash_dist() 2337 */ 2338 int dpni_set_rx_fs_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags, 2339 uint16_t token, const struct dpni_rx_dist_cfg *cfg) 2340 { 2341 struct dpni_cmd_set_rx_fs_dist *cmd_params; 2342 struct mc_command cmd = { 0 }; 2343 2344 /* prepare command */ 2345 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_FS_DIST, 2346 cmd_flags, 2347 token); 2348 cmd_params = (struct dpni_cmd_set_rx_fs_dist *)cmd.params; 2349 cmd_params->dist_size = cpu_to_le16(cfg->dist_size); 2350 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable); 2351 cmd_params->tc = cfg->tc; 2352 cmd_params->miss_flow_id = cpu_to_le16(cfg->fs_miss_flow_id); 2353 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova); 2354 2355 /* send command to mc*/ 2356 return mc_send_command(mc_io, &cmd); 2357 } 2358 2359 /** 2360 * dpni_set_rx_hash_dist() - Set Rx traffic class HASH distribution 2361 * @mc_io: Pointer to MC portal's I/O object 2362 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2363 * @token: Token of DPNI object 2364 * @cfg: Distribution configuration 2365 * If cfg.enable is set to 1 the packets will be classified using a hash 2366 * function based on the key received in cfg.key_cfg_iova parameter 2367 * If cfg.enable is set to 0 the packets will be sent to the queue configured in 2368 * dpni_set_rx_dist_default_queue() call 2369 */ 2370 int dpni_set_rx_hash_dist(struct fsl_mc_io *mc_io, uint32_t cmd_flags, 2371 uint16_t token, const struct dpni_rx_dist_cfg *cfg) 2372 { 2373 struct dpni_cmd_set_rx_hash_dist *cmd_params; 2374 struct mc_command cmd = { 0 }; 2375 2376 /* prepare command */ 2377 cmd.header = mc_encode_cmd_header(DPNI_CMDID_SET_RX_HASH_DIST, 2378 cmd_flags, 2379 token); 2380 cmd_params = (struct dpni_cmd_set_rx_hash_dist *)cmd.params; 2381 cmd_params->dist_size = cpu_to_le16(cfg->dist_size); 2382 dpni_set_field(cmd_params->enable, RX_FS_DIST_ENABLE, cfg->enable); 2383 cmd_params->tc_id = cfg->tc; 2384 cmd_params->key_cfg_iova = cpu_to_le64(cfg->key_cfg_iova); 2385 2386 /* send command to mc*/ 2387 return mc_send_command(mc_io, &cmd); 2388 } 2389 2390 /** 2391 * dpni_add_custom_tpid() - Configures a distinct Ethertype value 2392 * (or TPID value) to indicate VLAN tag in addition to the common 2393 * TPID values 0x8100 and 0x88A8 2394 * @mc_io: Pointer to MC portal's I/O object 2395 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2396 * @token: Token of DPNI object 2397 * @tpid: New value for TPID 2398 * 2399 * Only two custom values are accepted. If the function is called for the third 2400 * time it will return error. 2401 * To replace an existing value use dpni_remove_custom_tpid() to remove 2402 * a previous TPID and after that use again the function. 2403 * 2404 * Return: '0' on Success; Error code otherwise. 2405 */ 2406 int dpni_add_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags, 2407 uint16_t token, uint16_t tpid) 2408 { 2409 struct dpni_cmd_add_custom_tpid *cmd_params; 2410 struct mc_command cmd = { 0 }; 2411 2412 /* prepare command */ 2413 cmd.header = mc_encode_cmd_header(DPNI_CMDID_ADD_CUSTOM_TPID, 2414 cmd_flags, 2415 token); 2416 cmd_params = (struct dpni_cmd_add_custom_tpid *)cmd.params; 2417 cmd_params->tpid = cpu_to_le16(tpid); 2418 2419 /* send command to mc*/ 2420 return mc_send_command(mc_io, &cmd); 2421 } 2422 2423 /** 2424 * dpni_remove_custom_tpid() - Removes a distinct Ethertype value added 2425 * previously with dpni_add_custom_tpid() 2426 * @mc_io: Pointer to MC portal's I/O object 2427 * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' 2428 * @token: Token of DPNI object 2429 * @tpid: New value for TPID 2430 * 2431 * Use this function when a TPID value added with dpni_add_custom_tpid() needs 2432 * to be replaced. 2433 * 2434 * Return: '0' on Success; Error code otherwise. 2435 */ 2436 int dpni_remove_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags, 2437 uint16_t token, uint16_t tpid) 2438 { 2439 struct dpni_cmd_remove_custom_tpid *cmd_params; 2440 struct mc_command cmd = { 0 }; 2441 2442 /* prepare command */ 2443 cmd.header = mc_encode_cmd_header(DPNI_CMDID_REMOVE_CUSTOM_TPID, 2444 cmd_flags, 2445 token); 2446 cmd_params = (struct dpni_cmd_remove_custom_tpid *)cmd.params; 2447 cmd_params->tpid = cpu_to_le16(tpid); 2448 2449 /* send command to mc*/ 2450 return mc_send_command(mc_io, &cmd); 2451 } 2452 2453 /** 2454 * dpni_get_custom_tpid() - Returns custom TPID (vlan tags) values configured 2455 * to detect 802.1q frames 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 * @tpid: TPID values. Only nonzero members of the structure are valid. 2460 * 2461 * Return: '0' on Success; Error code otherwise. 2462 */ 2463 int dpni_get_custom_tpid(struct fsl_mc_io *mc_io, uint32_t cmd_flags, 2464 uint16_t token, struct dpni_custom_tpid_cfg *tpid) 2465 { 2466 struct dpni_rsp_get_custom_tpid *rsp_params; 2467 struct mc_command cmd = { 0 }; 2468 int err; 2469 2470 /* prepare command */ 2471 cmd.header = mc_encode_cmd_header(DPNI_CMDID_GET_CUSTOM_TPID, 2472 cmd_flags, 2473 token); 2474 2475 /* send command to mc*/ 2476 err = mc_send_command(mc_io, &cmd); 2477 if (err) 2478 return err; 2479 2480 /* read command response */ 2481 rsp_params = (struct dpni_rsp_get_custom_tpid *)cmd.params; 2482 tpid->tpid1 = le16_to_cpu(rsp_params->tpid1); 2483 tpid->tpid2 = le16_to_cpu(rsp_params->tpid2); 2484 2485 return err; 2486 } 2487