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