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