1 /*- 2 * BSD LICENSE 3 * 4 * Copyright(c) 2010-2017 Intel Corporation. All rights reserved. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * * Neither the name of Intel Corporation nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #include <string.h> 35 36 #include <rte_mbuf.h> 37 #include <rte_malloc.h> 38 #include <rte_ethdev.h> 39 #include <rte_tcp.h> 40 #include <rte_bus_vdev.h> 41 #include <rte_kvargs.h> 42 43 #include "rte_eth_bond.h" 44 #include "rte_eth_bond_private.h" 45 #include "rte_eth_bond_8023ad_private.h" 46 47 int 48 check_for_bonded_ethdev(const struct rte_eth_dev *eth_dev) 49 { 50 /* Check valid pointer */ 51 if (eth_dev->device->driver->name == NULL) 52 return -1; 53 54 /* return 0 if driver name matches */ 55 return eth_dev->device->driver->name != pmd_bond_drv.driver.name; 56 } 57 58 int 59 valid_bonded_port_id(uint16_t port_id) 60 { 61 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1); 62 return check_for_bonded_ethdev(&rte_eth_devices[port_id]); 63 } 64 65 int 66 check_for_master_bonded_ethdev(const struct rte_eth_dev *eth_dev) 67 { 68 int i; 69 struct bond_dev_private *internals; 70 71 if (check_for_bonded_ethdev(eth_dev) != 0) 72 return 0; 73 74 internals = eth_dev->data->dev_private; 75 76 /* Check if any of slave devices is a bonded device */ 77 for (i = 0; i < internals->slave_count; i++) 78 if (valid_bonded_port_id(internals->slaves[i].port_id) == 0) 79 return 1; 80 81 return 0; 82 } 83 84 int 85 valid_slave_port_id(uint16_t port_id, uint8_t mode) 86 { 87 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1); 88 89 /* Verify that port_id refers to a non bonded port */ 90 if (check_for_bonded_ethdev(&rte_eth_devices[port_id]) == 0 && 91 mode == BONDING_MODE_8023AD) { 92 RTE_BOND_LOG(ERR, "Cannot add slave to bonded device in 802.3ad" 93 " mode as slave is also a bonded device, only " 94 "physical devices can be support in this mode."); 95 return -1; 96 } 97 98 return 0; 99 } 100 101 void 102 activate_slave(struct rte_eth_dev *eth_dev, uint16_t port_id) 103 { 104 struct bond_dev_private *internals = eth_dev->data->dev_private; 105 uint8_t active_count = internals->active_slave_count; 106 107 if (internals->mode == BONDING_MODE_8023AD) 108 bond_mode_8023ad_activate_slave(eth_dev, port_id); 109 110 if (internals->mode == BONDING_MODE_TLB 111 || internals->mode == BONDING_MODE_ALB) { 112 113 internals->tlb_slaves_order[active_count] = port_id; 114 } 115 116 RTE_ASSERT(internals->active_slave_count < 117 (RTE_DIM(internals->active_slaves) - 1)); 118 119 internals->active_slaves[internals->active_slave_count] = port_id; 120 internals->active_slave_count++; 121 122 if (internals->mode == BONDING_MODE_TLB) 123 bond_tlb_activate_slave(internals); 124 if (internals->mode == BONDING_MODE_ALB) 125 bond_mode_alb_client_list_upd(eth_dev); 126 } 127 128 void 129 deactivate_slave(struct rte_eth_dev *eth_dev, uint16_t port_id) 130 { 131 uint16_t slave_pos; 132 struct bond_dev_private *internals = eth_dev->data->dev_private; 133 uint16_t active_count = internals->active_slave_count; 134 135 if (internals->mode == BONDING_MODE_8023AD) { 136 bond_mode_8023ad_stop(eth_dev); 137 bond_mode_8023ad_deactivate_slave(eth_dev, port_id); 138 } else if (internals->mode == BONDING_MODE_TLB 139 || internals->mode == BONDING_MODE_ALB) 140 bond_tlb_disable(internals); 141 142 slave_pos = find_slave_by_id(internals->active_slaves, active_count, 143 port_id); 144 145 /* If slave was not at the end of the list 146 * shift active slaves up active array list */ 147 if (slave_pos < active_count) { 148 active_count--; 149 memmove(internals->active_slaves + slave_pos, 150 internals->active_slaves + slave_pos + 1, 151 (active_count - slave_pos) * 152 sizeof(internals->active_slaves[0])); 153 } 154 155 RTE_ASSERT(active_count < RTE_DIM(internals->active_slaves)); 156 internals->active_slave_count = active_count; 157 158 if (eth_dev->data->dev_started) { 159 if (internals->mode == BONDING_MODE_8023AD) { 160 bond_mode_8023ad_start(eth_dev); 161 } else if (internals->mode == BONDING_MODE_TLB) { 162 bond_tlb_enable(internals); 163 } else if (internals->mode == BONDING_MODE_ALB) { 164 bond_tlb_enable(internals); 165 bond_mode_alb_client_list_upd(eth_dev); 166 } 167 } 168 } 169 170 int 171 rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id) 172 { 173 struct bond_dev_private *internals; 174 char devargs[52]; 175 uint16_t port_id; 176 int ret; 177 178 if (name == NULL) { 179 RTE_BOND_LOG(ERR, "Invalid name specified"); 180 return -EINVAL; 181 } 182 183 ret = snprintf(devargs, sizeof(devargs), 184 "driver=net_bonding,mode=%d,socket_id=%d", mode, socket_id); 185 if (ret < 0 || ret >= (int)sizeof(devargs)) 186 return -ENOMEM; 187 188 ret = rte_vdev_init(name, devargs); 189 if (ret) 190 return -ENOMEM; 191 192 ret = rte_eth_dev_get_port_by_name(name, &port_id); 193 RTE_ASSERT(!ret); 194 195 /* 196 * To make bond_ethdev_configure() happy we need to free the 197 * internals->kvlist here. 198 * 199 * Also see comment in bond_ethdev_configure(). 200 */ 201 internals = rte_eth_devices[port_id].data->dev_private; 202 rte_kvargs_free(internals->kvlist); 203 internals->kvlist = NULL; 204 205 return port_id; 206 } 207 208 int 209 rte_eth_bond_free(const char *name) 210 { 211 return rte_vdev_uninit(name); 212 } 213 214 static int 215 slave_vlan_filter_set(uint16_t bonded_port_id, uint16_t slave_port_id) 216 { 217 struct rte_eth_dev *bonded_eth_dev; 218 struct bond_dev_private *internals; 219 int found; 220 int res = 0; 221 uint64_t slab = 0; 222 uint32_t pos = 0; 223 uint16_t first; 224 225 bonded_eth_dev = &rte_eth_devices[bonded_port_id]; 226 if (bonded_eth_dev->data->dev_conf.rxmode.hw_vlan_filter == 0) 227 return 0; 228 229 internals = bonded_eth_dev->data->dev_private; 230 found = rte_bitmap_scan(internals->vlan_filter_bmp, &pos, &slab); 231 first = pos; 232 233 if (!found) 234 return 0; 235 236 do { 237 uint32_t i; 238 uint64_t mask; 239 240 for (i = 0, mask = 1; 241 i < RTE_BITMAP_SLAB_BIT_SIZE; 242 i ++, mask <<= 1) { 243 if (unlikely(slab & mask)) { 244 uint16_t vlan_id = pos + i; 245 246 res = rte_eth_dev_vlan_filter(slave_port_id, 247 vlan_id, 1); 248 } 249 } 250 found = rte_bitmap_scan(internals->vlan_filter_bmp, 251 &pos, &slab); 252 } while (found && first != pos && res == 0); 253 254 return res; 255 } 256 257 static int 258 __eth_bond_slave_add_lock_free(uint16_t bonded_port_id, uint16_t slave_port_id) 259 { 260 struct rte_eth_dev *bonded_eth_dev, *slave_eth_dev; 261 struct bond_dev_private *internals; 262 struct rte_eth_link link_props; 263 struct rte_eth_dev_info dev_info; 264 265 bonded_eth_dev = &rte_eth_devices[bonded_port_id]; 266 internals = bonded_eth_dev->data->dev_private; 267 268 if (valid_slave_port_id(slave_port_id, internals->mode) != 0) 269 return -1; 270 271 slave_eth_dev = &rte_eth_devices[slave_port_id]; 272 if (slave_eth_dev->data->dev_flags & RTE_ETH_DEV_BONDED_SLAVE) { 273 RTE_BOND_LOG(ERR, "Slave device is already a slave of a bonded device"); 274 return -1; 275 } 276 277 /* Add slave details to bonded device */ 278 slave_eth_dev->data->dev_flags |= RTE_ETH_DEV_BONDED_SLAVE; 279 280 rte_eth_dev_info_get(slave_port_id, &dev_info); 281 if (dev_info.max_rx_pktlen < internals->max_rx_pktlen) { 282 RTE_BOND_LOG(ERR, "Slave (port %u) max_rx_pktlen too small", 283 slave_port_id); 284 return -1; 285 } 286 287 slave_add(internals, slave_eth_dev); 288 289 /* We need to store slaves reta_size to be able to synchronize RETA for all 290 * slave devices even if its sizes are different. 291 */ 292 internals->slaves[internals->slave_count].reta_size = dev_info.reta_size; 293 294 if (internals->slave_count < 1) { 295 /* if MAC is not user defined then use MAC of first slave add to 296 * bonded device */ 297 if (!internals->user_defined_mac) { 298 if (mac_address_set(bonded_eth_dev, 299 slave_eth_dev->data->mac_addrs)) { 300 RTE_BOND_LOG(ERR, "Failed to set MAC address"); 301 return -1; 302 } 303 } 304 305 /* Inherit eth dev link properties from first slave */ 306 link_properties_set(bonded_eth_dev, 307 &(slave_eth_dev->data->dev_link)); 308 309 /* Make primary slave */ 310 internals->primary_port = slave_port_id; 311 internals->current_primary_port = slave_port_id; 312 313 /* Inherit queues settings from first slave */ 314 internals->nb_rx_queues = slave_eth_dev->data->nb_rx_queues; 315 internals->nb_tx_queues = slave_eth_dev->data->nb_tx_queues; 316 317 internals->reta_size = dev_info.reta_size; 318 319 /* Take the first dev's offload capabilities */ 320 internals->rx_offload_capa = dev_info.rx_offload_capa; 321 internals->tx_offload_capa = dev_info.tx_offload_capa; 322 internals->flow_type_rss_offloads = dev_info.flow_type_rss_offloads; 323 324 /* Inherit first slave's max rx packet size */ 325 internals->candidate_max_rx_pktlen = dev_info.max_rx_pktlen; 326 327 } else { 328 internals->rx_offload_capa &= dev_info.rx_offload_capa; 329 internals->tx_offload_capa &= dev_info.tx_offload_capa; 330 internals->flow_type_rss_offloads &= dev_info.flow_type_rss_offloads; 331 332 if (link_properties_valid(bonded_eth_dev, 333 &slave_eth_dev->data->dev_link) != 0) { 334 RTE_BOND_LOG(ERR, "Invalid link properties for slave %d" 335 " in bonding mode %d", slave_port_id, 336 internals->mode); 337 return -1; 338 } 339 340 /* RETA size is GCD of all slaves RETA sizes, so, if all sizes will be 341 * the power of 2, the lower one is GCD 342 */ 343 if (internals->reta_size > dev_info.reta_size) 344 internals->reta_size = dev_info.reta_size; 345 346 if (!internals->max_rx_pktlen && 347 dev_info.max_rx_pktlen < internals->candidate_max_rx_pktlen) 348 internals->candidate_max_rx_pktlen = dev_info.max_rx_pktlen; 349 } 350 351 bonded_eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf &= 352 internals->flow_type_rss_offloads; 353 354 internals->slave_count++; 355 356 /* Update all slave devices MACs*/ 357 mac_address_slaves_update(bonded_eth_dev); 358 359 if (bonded_eth_dev->data->dev_started) { 360 if (slave_configure(bonded_eth_dev, slave_eth_dev) != 0) { 361 slave_eth_dev->data->dev_flags &= (~RTE_ETH_DEV_BONDED_SLAVE); 362 RTE_BOND_LOG(ERR, "rte_bond_slaves_configure: port=%d", 363 slave_port_id); 364 return -1; 365 } 366 } 367 368 /* Register link status change callback with bonded device pointer as 369 * argument*/ 370 rte_eth_dev_callback_register(slave_port_id, RTE_ETH_EVENT_INTR_LSC, 371 bond_ethdev_lsc_event_callback, &bonded_eth_dev->data->port_id); 372 373 /* If bonded device is started then we can add the slave to our active 374 * slave array */ 375 if (bonded_eth_dev->data->dev_started) { 376 rte_eth_link_get_nowait(slave_port_id, &link_props); 377 378 if (link_props.link_status == ETH_LINK_UP) { 379 if (internals->active_slave_count == 0 && 380 !internals->user_defined_primary_port) 381 bond_ethdev_primary_set(internals, 382 slave_port_id); 383 384 if (find_slave_by_id(internals->active_slaves, 385 internals->active_slave_count, 386 slave_port_id) == internals->active_slave_count) 387 activate_slave(bonded_eth_dev, slave_port_id); 388 } 389 } 390 391 slave_vlan_filter_set(bonded_port_id, slave_port_id); 392 393 return 0; 394 395 } 396 397 int 398 rte_eth_bond_slave_add(uint16_t bonded_port_id, uint16_t slave_port_id) 399 { 400 struct rte_eth_dev *bonded_eth_dev; 401 struct bond_dev_private *internals; 402 403 int retval; 404 405 /* Verify that port id's are valid bonded and slave ports */ 406 if (valid_bonded_port_id(bonded_port_id) != 0) 407 return -1; 408 409 bonded_eth_dev = &rte_eth_devices[bonded_port_id]; 410 internals = bonded_eth_dev->data->dev_private; 411 412 rte_spinlock_lock(&internals->lock); 413 414 retval = __eth_bond_slave_add_lock_free(bonded_port_id, slave_port_id); 415 416 rte_spinlock_unlock(&internals->lock); 417 418 return retval; 419 } 420 421 static int 422 __eth_bond_slave_remove_lock_free(uint16_t bonded_port_id, 423 uint16_t slave_port_id) 424 { 425 struct rte_eth_dev *bonded_eth_dev; 426 struct bond_dev_private *internals; 427 struct rte_eth_dev *slave_eth_dev; 428 int i, slave_idx; 429 430 bonded_eth_dev = &rte_eth_devices[bonded_port_id]; 431 internals = bonded_eth_dev->data->dev_private; 432 433 if (valid_slave_port_id(slave_port_id, internals->mode) < 0) 434 return -1; 435 436 /* first remove from active slave list */ 437 slave_idx = find_slave_by_id(internals->active_slaves, 438 internals->active_slave_count, slave_port_id); 439 440 if (slave_idx < internals->active_slave_count) 441 deactivate_slave(bonded_eth_dev, slave_port_id); 442 443 slave_idx = -1; 444 /* now find in slave list */ 445 for (i = 0; i < internals->slave_count; i++) 446 if (internals->slaves[i].port_id == slave_port_id) { 447 slave_idx = i; 448 break; 449 } 450 451 if (slave_idx < 0) { 452 RTE_BOND_LOG(ERR, "Couldn't find slave in port list, slave count %d", 453 internals->slave_count); 454 return -1; 455 } 456 457 /* Un-register link status change callback with bonded device pointer as 458 * argument*/ 459 rte_eth_dev_callback_unregister(slave_port_id, RTE_ETH_EVENT_INTR_LSC, 460 bond_ethdev_lsc_event_callback, 461 &rte_eth_devices[bonded_port_id].data->port_id); 462 463 /* Restore original MAC address of slave device */ 464 rte_eth_dev_default_mac_addr_set(slave_port_id, 465 &(internals->slaves[slave_idx].persisted_mac_addr)); 466 467 slave_eth_dev = &rte_eth_devices[slave_port_id]; 468 slave_remove(internals, slave_eth_dev); 469 slave_eth_dev->data->dev_flags &= (~RTE_ETH_DEV_BONDED_SLAVE); 470 471 /* first slave in the active list will be the primary by default, 472 * otherwise use first device in list */ 473 if (internals->current_primary_port == slave_port_id) { 474 if (internals->active_slave_count > 0) 475 internals->current_primary_port = internals->active_slaves[0]; 476 else if (internals->slave_count > 0) 477 internals->current_primary_port = internals->slaves[0].port_id; 478 else 479 internals->primary_port = 0; 480 } 481 482 if (internals->active_slave_count < 1) { 483 /* if no slaves are any longer attached to bonded device and MAC is not 484 * user defined then clear MAC of bonded device as it will be reset 485 * when a new slave is added */ 486 if (internals->slave_count < 1 && !internals->user_defined_mac) 487 memset(rte_eth_devices[bonded_port_id].data->mac_addrs, 0, 488 sizeof(*(rte_eth_devices[bonded_port_id].data->mac_addrs))); 489 } 490 if (internals->slave_count == 0) { 491 internals->rx_offload_capa = 0; 492 internals->tx_offload_capa = 0; 493 internals->flow_type_rss_offloads = ETH_RSS_PROTO_MASK; 494 internals->reta_size = 0; 495 internals->candidate_max_rx_pktlen = 0; 496 internals->max_rx_pktlen = 0; 497 } 498 return 0; 499 } 500 501 int 502 rte_eth_bond_slave_remove(uint16_t bonded_port_id, uint16_t slave_port_id) 503 { 504 struct rte_eth_dev *bonded_eth_dev; 505 struct bond_dev_private *internals; 506 int retval; 507 508 if (valid_bonded_port_id(bonded_port_id) != 0) 509 return -1; 510 511 bonded_eth_dev = &rte_eth_devices[bonded_port_id]; 512 internals = bonded_eth_dev->data->dev_private; 513 514 rte_spinlock_lock(&internals->lock); 515 516 retval = __eth_bond_slave_remove_lock_free(bonded_port_id, slave_port_id); 517 518 rte_spinlock_unlock(&internals->lock); 519 520 return retval; 521 } 522 523 int 524 rte_eth_bond_mode_set(uint16_t bonded_port_id, uint8_t mode) 525 { 526 struct rte_eth_dev *bonded_eth_dev; 527 528 if (valid_bonded_port_id(bonded_port_id) != 0) 529 return -1; 530 531 bonded_eth_dev = &rte_eth_devices[bonded_port_id]; 532 533 if (check_for_master_bonded_ethdev(bonded_eth_dev) != 0 && 534 mode == BONDING_MODE_8023AD) 535 return -1; 536 537 return bond_ethdev_mode_set(bonded_eth_dev, mode); 538 } 539 540 int 541 rte_eth_bond_mode_get(uint16_t bonded_port_id) 542 { 543 struct bond_dev_private *internals; 544 545 if (valid_bonded_port_id(bonded_port_id) != 0) 546 return -1; 547 548 internals = rte_eth_devices[bonded_port_id].data->dev_private; 549 550 return internals->mode; 551 } 552 553 int 554 rte_eth_bond_primary_set(uint16_t bonded_port_id, uint16_t slave_port_id) 555 { 556 struct bond_dev_private *internals; 557 558 if (valid_bonded_port_id(bonded_port_id) != 0) 559 return -1; 560 561 internals = rte_eth_devices[bonded_port_id].data->dev_private; 562 563 if (valid_slave_port_id(slave_port_id, internals->mode) != 0) 564 return -1; 565 566 internals->user_defined_primary_port = 1; 567 internals->primary_port = slave_port_id; 568 569 bond_ethdev_primary_set(internals, slave_port_id); 570 571 return 0; 572 } 573 574 int 575 rte_eth_bond_primary_get(uint16_t bonded_port_id) 576 { 577 struct bond_dev_private *internals; 578 579 if (valid_bonded_port_id(bonded_port_id) != 0) 580 return -1; 581 582 internals = rte_eth_devices[bonded_port_id].data->dev_private; 583 584 if (internals->slave_count < 1) 585 return -1; 586 587 return internals->current_primary_port; 588 } 589 590 int 591 rte_eth_bond_slaves_get(uint16_t bonded_port_id, uint16_t slaves[], 592 uint16_t len) 593 { 594 struct bond_dev_private *internals; 595 uint8_t i; 596 597 if (valid_bonded_port_id(bonded_port_id) != 0) 598 return -1; 599 600 if (slaves == NULL) 601 return -1; 602 603 internals = rte_eth_devices[bonded_port_id].data->dev_private; 604 605 if (internals->slave_count > len) 606 return -1; 607 608 for (i = 0; i < internals->slave_count; i++) 609 slaves[i] = internals->slaves[i].port_id; 610 611 return internals->slave_count; 612 } 613 614 int 615 rte_eth_bond_active_slaves_get(uint16_t bonded_port_id, uint16_t slaves[], 616 uint16_t len) 617 { 618 struct bond_dev_private *internals; 619 620 if (valid_bonded_port_id(bonded_port_id) != 0) 621 return -1; 622 623 if (slaves == NULL) 624 return -1; 625 626 internals = rte_eth_devices[bonded_port_id].data->dev_private; 627 628 if (internals->active_slave_count > len) 629 return -1; 630 631 memcpy(slaves, internals->active_slaves, 632 internals->active_slave_count * sizeof(internals->active_slaves[0])); 633 634 return internals->active_slave_count; 635 } 636 637 int 638 rte_eth_bond_mac_address_set(uint16_t bonded_port_id, 639 struct ether_addr *mac_addr) 640 { 641 struct rte_eth_dev *bonded_eth_dev; 642 struct bond_dev_private *internals; 643 644 if (valid_bonded_port_id(bonded_port_id) != 0) 645 return -1; 646 647 bonded_eth_dev = &rte_eth_devices[bonded_port_id]; 648 internals = bonded_eth_dev->data->dev_private; 649 650 /* Set MAC Address of Bonded Device */ 651 if (mac_address_set(bonded_eth_dev, mac_addr)) 652 return -1; 653 654 internals->user_defined_mac = 1; 655 656 /* Update all slave devices MACs*/ 657 if (internals->slave_count > 0) 658 return mac_address_slaves_update(bonded_eth_dev); 659 660 return 0; 661 } 662 663 int 664 rte_eth_bond_mac_address_reset(uint16_t bonded_port_id) 665 { 666 struct rte_eth_dev *bonded_eth_dev; 667 struct bond_dev_private *internals; 668 669 if (valid_bonded_port_id(bonded_port_id) != 0) 670 return -1; 671 672 bonded_eth_dev = &rte_eth_devices[bonded_port_id]; 673 internals = bonded_eth_dev->data->dev_private; 674 675 internals->user_defined_mac = 0; 676 677 if (internals->slave_count > 0) { 678 int slave_port; 679 /* Get the primary slave location based on the primary port 680 * number as, while slave_add(), we will keep the primary 681 * slave based on slave_count,but not based on the primary port. 682 */ 683 for (slave_port = 0; slave_port < internals->slave_count; 684 slave_port++) { 685 if (internals->slaves[slave_port].port_id == 686 internals->primary_port) 687 break; 688 } 689 690 /* Set MAC Address of Bonded Device */ 691 if (mac_address_set(bonded_eth_dev, 692 &internals->slaves[slave_port].persisted_mac_addr) 693 != 0) { 694 RTE_BOND_LOG(ERR, "Failed to set MAC address on bonded device"); 695 return -1; 696 } 697 /* Update all slave devices MAC addresses */ 698 return mac_address_slaves_update(bonded_eth_dev); 699 } 700 /* No need to update anything as no slaves present */ 701 return 0; 702 } 703 704 int 705 rte_eth_bond_xmit_policy_set(uint16_t bonded_port_id, uint8_t policy) 706 { 707 struct bond_dev_private *internals; 708 709 if (valid_bonded_port_id(bonded_port_id) != 0) 710 return -1; 711 712 internals = rte_eth_devices[bonded_port_id].data->dev_private; 713 714 switch (policy) { 715 case BALANCE_XMIT_POLICY_LAYER2: 716 internals->balance_xmit_policy = policy; 717 internals->xmit_hash = xmit_l2_hash; 718 break; 719 case BALANCE_XMIT_POLICY_LAYER23: 720 internals->balance_xmit_policy = policy; 721 internals->xmit_hash = xmit_l23_hash; 722 break; 723 case BALANCE_XMIT_POLICY_LAYER34: 724 internals->balance_xmit_policy = policy; 725 internals->xmit_hash = xmit_l34_hash; 726 break; 727 728 default: 729 return -1; 730 } 731 return 0; 732 } 733 734 int 735 rte_eth_bond_xmit_policy_get(uint16_t bonded_port_id) 736 { 737 struct bond_dev_private *internals; 738 739 if (valid_bonded_port_id(bonded_port_id) != 0) 740 return -1; 741 742 internals = rte_eth_devices[bonded_port_id].data->dev_private; 743 744 return internals->balance_xmit_policy; 745 } 746 747 int 748 rte_eth_bond_link_monitoring_set(uint16_t bonded_port_id, uint32_t internal_ms) 749 { 750 struct bond_dev_private *internals; 751 752 if (valid_bonded_port_id(bonded_port_id) != 0) 753 return -1; 754 755 internals = rte_eth_devices[bonded_port_id].data->dev_private; 756 internals->link_status_polling_interval_ms = internal_ms; 757 758 return 0; 759 } 760 761 int 762 rte_eth_bond_link_monitoring_get(uint16_t bonded_port_id) 763 { 764 struct bond_dev_private *internals; 765 766 if (valid_bonded_port_id(bonded_port_id) != 0) 767 return -1; 768 769 internals = rte_eth_devices[bonded_port_id].data->dev_private; 770 771 return internals->link_status_polling_interval_ms; 772 } 773 774 int 775 rte_eth_bond_link_down_prop_delay_set(uint16_t bonded_port_id, 776 uint32_t delay_ms) 777 778 { 779 struct bond_dev_private *internals; 780 781 if (valid_bonded_port_id(bonded_port_id) != 0) 782 return -1; 783 784 internals = rte_eth_devices[bonded_port_id].data->dev_private; 785 internals->link_down_delay_ms = delay_ms; 786 787 return 0; 788 } 789 790 int 791 rte_eth_bond_link_down_prop_delay_get(uint16_t bonded_port_id) 792 { 793 struct bond_dev_private *internals; 794 795 if (valid_bonded_port_id(bonded_port_id) != 0) 796 return -1; 797 798 internals = rte_eth_devices[bonded_port_id].data->dev_private; 799 800 return internals->link_down_delay_ms; 801 } 802 803 int 804 rte_eth_bond_link_up_prop_delay_set(uint16_t bonded_port_id, uint32_t delay_ms) 805 806 { 807 struct bond_dev_private *internals; 808 809 if (valid_bonded_port_id(bonded_port_id) != 0) 810 return -1; 811 812 internals = rte_eth_devices[bonded_port_id].data->dev_private; 813 internals->link_up_delay_ms = delay_ms; 814 815 return 0; 816 } 817 818 int 819 rte_eth_bond_link_up_prop_delay_get(uint16_t bonded_port_id) 820 { 821 struct bond_dev_private *internals; 822 823 if (valid_bonded_port_id(bonded_port_id) != 0) 824 return -1; 825 826 internals = rte_eth_devices[bonded_port_id].data->dev_private; 827 828 return internals->link_up_delay_ms; 829 } 830