1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
8 #include <rte_malloc.h>
9 #include <ethdev_driver.h>
11 #include <rte_bus_vdev.h>
12 #include <rte_kvargs.h>
14 #include "rte_eth_bond.h"
15 #include "eth_bond_private.h"
16 #include "eth_bond_8023ad_private.h"
19 check_for_bonded_ethdev(const struct rte_eth_dev *eth_dev)
21 /* Check valid pointer */
22 if (eth_dev == NULL ||
23 eth_dev->device == NULL ||
24 eth_dev->device->driver == NULL ||
25 eth_dev->device->driver->name == NULL)
28 /* return 0 if driver name matches */
29 return eth_dev->device->driver->name != pmd_bond_drv.driver.name;
33 valid_bonded_port_id(uint16_t port_id)
35 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
36 return check_for_bonded_ethdev(&rte_eth_devices[port_id]);
40 check_for_master_bonded_ethdev(const struct rte_eth_dev *eth_dev)
43 struct bond_dev_private *internals;
45 if (check_for_bonded_ethdev(eth_dev) != 0)
48 internals = eth_dev->data->dev_private;
50 /* Check if any of slave devices is a bonded device */
51 for (i = 0; i < internals->slave_count; i++)
52 if (valid_bonded_port_id(internals->slaves[i].port_id) == 0)
59 valid_slave_port_id(struct bond_dev_private *internals, uint16_t slave_port_id)
61 RTE_ETH_VALID_PORTID_OR_ERR_RET(slave_port_id, -1);
63 /* Verify that slave_port_id refers to a non bonded port */
64 if (check_for_bonded_ethdev(&rte_eth_devices[slave_port_id]) == 0 &&
65 internals->mode == BONDING_MODE_8023AD) {
66 RTE_BOND_LOG(ERR, "Cannot add slave to bonded device in 802.3ad"
67 " mode as slave is also a bonded device, only "
68 "physical devices can be support in this mode.");
72 if (internals->port_id == slave_port_id) {
74 "Cannot add the bonded device itself as its slave.");
82 activate_slave(struct rte_eth_dev *eth_dev, uint16_t port_id)
84 struct bond_dev_private *internals = eth_dev->data->dev_private;
85 uint16_t active_count = internals->active_slave_count;
87 if (internals->mode == BONDING_MODE_8023AD)
88 bond_mode_8023ad_activate_slave(eth_dev, port_id);
90 if (internals->mode == BONDING_MODE_TLB
91 || internals->mode == BONDING_MODE_ALB) {
93 internals->tlb_slaves_order[active_count] = port_id;
96 RTE_ASSERT(internals->active_slave_count <
97 (RTE_DIM(internals->active_slaves) - 1));
99 internals->active_slaves[internals->active_slave_count] = port_id;
100 internals->active_slave_count++;
102 if (internals->mode == BONDING_MODE_TLB)
103 bond_tlb_activate_slave(internals);
104 if (internals->mode == BONDING_MODE_ALB)
105 bond_mode_alb_client_list_upd(eth_dev);
109 deactivate_slave(struct rte_eth_dev *eth_dev, uint16_t port_id)
112 struct bond_dev_private *internals = eth_dev->data->dev_private;
113 uint16_t active_count = internals->active_slave_count;
115 if (internals->mode == BONDING_MODE_8023AD) {
116 bond_mode_8023ad_stop(eth_dev);
117 bond_mode_8023ad_deactivate_slave(eth_dev, port_id);
118 } else if (internals->mode == BONDING_MODE_TLB
119 || internals->mode == BONDING_MODE_ALB)
120 bond_tlb_disable(internals);
122 slave_pos = find_slave_by_id(internals->active_slaves, active_count,
125 /* If slave was not at the end of the list
126 * shift active slaves up active array list */
127 if (slave_pos < active_count) {
129 memmove(internals->active_slaves + slave_pos,
130 internals->active_slaves + slave_pos + 1,
131 (active_count - slave_pos) *
132 sizeof(internals->active_slaves[0]));
135 RTE_ASSERT(active_count < RTE_DIM(internals->active_slaves));
136 internals->active_slave_count = active_count;
138 if (eth_dev->data->dev_started) {
139 if (internals->mode == BONDING_MODE_8023AD) {
140 bond_mode_8023ad_start(eth_dev);
141 } else if (internals->mode == BONDING_MODE_TLB) {
142 bond_tlb_enable(internals);
143 } else if (internals->mode == BONDING_MODE_ALB) {
144 bond_tlb_enable(internals);
145 bond_mode_alb_client_list_upd(eth_dev);
151 rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id)
153 struct bond_dev_private *internals;
159 RTE_BOND_LOG(ERR, "Invalid name specified");
163 ret = snprintf(devargs, sizeof(devargs),
164 "driver=net_bonding,mode=%d,socket_id=%d", mode, socket_id);
165 if (ret < 0 || ret >= (int)sizeof(devargs))
168 ret = rte_vdev_init(name, devargs);
172 ret = rte_eth_dev_get_port_by_name(name, &port_id);
176 * To make bond_ethdev_configure() happy we need to free the
177 * internals->kvlist here.
179 * Also see comment in bond_ethdev_configure().
181 internals = rte_eth_devices[port_id].data->dev_private;
182 rte_kvargs_free(internals->kvlist);
183 internals->kvlist = NULL;
189 rte_eth_bond_free(const char *name)
191 return rte_vdev_uninit(name);
195 slave_vlan_filter_set(uint16_t bonded_port_id, uint16_t slave_port_id)
197 struct rte_eth_dev *bonded_eth_dev;
198 struct bond_dev_private *internals;
205 bonded_eth_dev = &rte_eth_devices[bonded_port_id];
206 if ((bonded_eth_dev->data->dev_conf.rxmode.offloads &
207 RTE_ETH_RX_OFFLOAD_VLAN_FILTER) == 0)
210 internals = bonded_eth_dev->data->dev_private;
211 found = rte_bitmap_scan(internals->vlan_filter_bmp, &pos, &slab);
221 for (i = 0, mask = 1;
222 i < RTE_BITMAP_SLAB_BIT_SIZE;
224 if (unlikely(slab & mask)) {
225 uint16_t vlan_id = pos + i;
227 res = rte_eth_dev_vlan_filter(slave_port_id,
231 found = rte_bitmap_scan(internals->vlan_filter_bmp,
233 } while (found && first != pos && res == 0);
239 slave_rte_flow_prepare(uint16_t slave_id, struct bond_dev_private *internals)
241 struct rte_flow *flow;
242 struct rte_flow_error ferror;
243 uint16_t slave_port_id = internals->slaves[slave_id].port_id;
245 if (internals->flow_isolated_valid != 0) {
246 if (rte_eth_dev_stop(slave_port_id) != 0) {
247 RTE_BOND_LOG(ERR, "Failed to stop device on port %u",
252 if (rte_flow_isolate(slave_port_id, internals->flow_isolated,
254 RTE_BOND_LOG(ERR, "rte_flow_isolate failed for slave"
255 " %d: %s", slave_id, ferror.message ?
256 ferror.message : "(no stated reason)");
260 TAILQ_FOREACH(flow, &internals->flow_list, next) {
261 flow->flows[slave_id] = rte_flow_create(slave_port_id,
266 if (flow->flows[slave_id] == NULL) {
267 RTE_BOND_LOG(ERR, "Cannot create flow for slave"
269 ferror.message ? ferror.message :
270 "(no stated reason)");
271 /* Destroy successful bond flows from the slave */
272 TAILQ_FOREACH(flow, &internals->flow_list, next) {
273 if (flow->flows[slave_id] != NULL) {
274 rte_flow_destroy(slave_port_id,
275 flow->flows[slave_id],
277 flow->flows[slave_id] = NULL;
287 eth_bond_slave_inherit_dev_info_rx_first(struct bond_dev_private *internals,
288 const struct rte_eth_dev_info *di)
290 struct rte_eth_rxconf *rxconf_i = &internals->default_rxconf;
292 internals->reta_size = di->reta_size;
293 internals->rss_key_len = di->hash_key_size;
295 /* Inherit Rx offload capabilities from the first slave device */
296 internals->rx_offload_capa = di->rx_offload_capa;
297 internals->rx_queue_offload_capa = di->rx_queue_offload_capa;
298 internals->flow_type_rss_offloads = di->flow_type_rss_offloads;
300 /* Inherit maximum Rx packet size from the first slave device */
301 internals->candidate_max_rx_pktlen = di->max_rx_pktlen;
303 /* Inherit default Rx queue settings from the first slave device */
304 memcpy(rxconf_i, &di->default_rxconf, sizeof(*rxconf_i));
307 * Turn off descriptor prefetch and writeback by default for all
308 * slave devices. Applications may tweak this setting if need be.
310 rxconf_i->rx_thresh.pthresh = 0;
311 rxconf_i->rx_thresh.hthresh = 0;
312 rxconf_i->rx_thresh.wthresh = 0;
314 /* Setting this to zero should effectively enable default values */
315 rxconf_i->rx_free_thresh = 0;
317 /* Disable deferred start by default for all slave devices */
318 rxconf_i->rx_deferred_start = 0;
322 eth_bond_slave_inherit_dev_info_tx_first(struct bond_dev_private *internals,
323 const struct rte_eth_dev_info *di)
325 struct rte_eth_txconf *txconf_i = &internals->default_txconf;
327 /* Inherit Tx offload capabilities from the first slave device */
328 internals->tx_offload_capa = di->tx_offload_capa;
329 internals->tx_queue_offload_capa = di->tx_queue_offload_capa;
331 /* Inherit default Tx queue settings from the first slave device */
332 memcpy(txconf_i, &di->default_txconf, sizeof(*txconf_i));
335 * Turn off descriptor prefetch and writeback by default for all
336 * slave devices. Applications may tweak this setting if need be.
338 txconf_i->tx_thresh.pthresh = 0;
339 txconf_i->tx_thresh.hthresh = 0;
340 txconf_i->tx_thresh.wthresh = 0;
343 * Setting these parameters to zero assumes that default
344 * values will be configured implicitly by slave devices.
346 txconf_i->tx_free_thresh = 0;
347 txconf_i->tx_rs_thresh = 0;
349 /* Disable deferred start by default for all slave devices */
350 txconf_i->tx_deferred_start = 0;
354 eth_bond_slave_inherit_dev_info_rx_next(struct bond_dev_private *internals,
355 const struct rte_eth_dev_info *di)
357 struct rte_eth_rxconf *rxconf_i = &internals->default_rxconf;
358 const struct rte_eth_rxconf *rxconf = &di->default_rxconf;
360 internals->rx_offload_capa &= di->rx_offload_capa;
361 internals->rx_queue_offload_capa &= di->rx_queue_offload_capa;
362 internals->flow_type_rss_offloads &= di->flow_type_rss_offloads;
365 * If at least one slave device suggests enabling this
366 * setting by default, enable it for all slave devices
367 * since disabling it may not be necessarily supported.
369 if (rxconf->rx_drop_en == 1)
370 rxconf_i->rx_drop_en = 1;
373 * Adding a new slave device may cause some of previously inherited
374 * offloads to be withdrawn from the internal rx_queue_offload_capa
375 * value. Thus, the new internal value of default Rx queue offloads
376 * has to be masked by rx_queue_offload_capa to make sure that only
377 * commonly supported offloads are preserved from both the previous
378 * value and the value being inhereted from the new slave device.
380 rxconf_i->offloads = (rxconf_i->offloads | rxconf->offloads) &
381 internals->rx_queue_offload_capa;
384 * RETA size is GCD of all slaves RETA sizes, so, if all sizes will be
385 * the power of 2, the lower one is GCD
387 if (internals->reta_size > di->reta_size)
388 internals->reta_size = di->reta_size;
389 if (internals->rss_key_len > di->hash_key_size) {
390 RTE_BOND_LOG(WARNING, "slave has different rss key size, "
391 "configuring rss may fail");
392 internals->rss_key_len = di->hash_key_size;
395 if (!internals->max_rx_pktlen &&
396 di->max_rx_pktlen < internals->candidate_max_rx_pktlen)
397 internals->candidate_max_rx_pktlen = di->max_rx_pktlen;
401 eth_bond_slave_inherit_dev_info_tx_next(struct bond_dev_private *internals,
402 const struct rte_eth_dev_info *di)
404 struct rte_eth_txconf *txconf_i = &internals->default_txconf;
405 const struct rte_eth_txconf *txconf = &di->default_txconf;
407 internals->tx_offload_capa &= di->tx_offload_capa;
408 internals->tx_queue_offload_capa &= di->tx_queue_offload_capa;
411 * Adding a new slave device may cause some of previously inherited
412 * offloads to be withdrawn from the internal tx_queue_offload_capa
413 * value. Thus, the new internal value of default Tx queue offloads
414 * has to be masked by tx_queue_offload_capa to make sure that only
415 * commonly supported offloads are preserved from both the previous
416 * value and the value being inhereted from the new slave device.
418 txconf_i->offloads = (txconf_i->offloads | txconf->offloads) &
419 internals->tx_queue_offload_capa;
423 eth_bond_slave_inherit_desc_lim_first(struct rte_eth_desc_lim *bond_desc_lim,
424 const struct rte_eth_desc_lim *slave_desc_lim)
426 memcpy(bond_desc_lim, slave_desc_lim, sizeof(*bond_desc_lim));
430 eth_bond_slave_inherit_desc_lim_next(struct rte_eth_desc_lim *bond_desc_lim,
431 const struct rte_eth_desc_lim *slave_desc_lim)
433 bond_desc_lim->nb_max = RTE_MIN(bond_desc_lim->nb_max,
434 slave_desc_lim->nb_max);
435 bond_desc_lim->nb_min = RTE_MAX(bond_desc_lim->nb_min,
436 slave_desc_lim->nb_min);
437 bond_desc_lim->nb_align = RTE_MAX(bond_desc_lim->nb_align,
438 slave_desc_lim->nb_align);
440 if (bond_desc_lim->nb_min > bond_desc_lim->nb_max ||
441 bond_desc_lim->nb_align > bond_desc_lim->nb_max) {
442 RTE_BOND_LOG(ERR, "Failed to inherit descriptor limits");
446 /* Treat maximum number of segments equal to 0 as unspecified */
447 if (slave_desc_lim->nb_seg_max != 0 &&
448 (bond_desc_lim->nb_seg_max == 0 ||
449 slave_desc_lim->nb_seg_max < bond_desc_lim->nb_seg_max))
450 bond_desc_lim->nb_seg_max = slave_desc_lim->nb_seg_max;
451 if (slave_desc_lim->nb_mtu_seg_max != 0 &&
452 (bond_desc_lim->nb_mtu_seg_max == 0 ||
453 slave_desc_lim->nb_mtu_seg_max < bond_desc_lim->nb_mtu_seg_max))
454 bond_desc_lim->nb_mtu_seg_max = slave_desc_lim->nb_mtu_seg_max;
460 __eth_bond_slave_add_lock_free(uint16_t bonded_port_id, uint16_t slave_port_id)
462 struct rte_eth_dev *bonded_eth_dev, *slave_eth_dev;
463 struct bond_dev_private *internals;
464 struct rte_eth_link link_props;
465 struct rte_eth_dev_info dev_info;
468 bonded_eth_dev = &rte_eth_devices[bonded_port_id];
469 internals = bonded_eth_dev->data->dev_private;
471 if (valid_slave_port_id(internals, slave_port_id) != 0)
474 slave_eth_dev = &rte_eth_devices[slave_port_id];
475 if (slave_eth_dev->data->dev_flags & RTE_ETH_DEV_BONDED_SLAVE) {
476 RTE_BOND_LOG(ERR, "Slave device is already a slave of a bonded device");
480 ret = rte_eth_dev_info_get(slave_port_id, &dev_info);
483 "%s: Error during getting device (port %u) info: %s\n",
484 __func__, slave_port_id, strerror(-ret));
488 if (dev_info.max_rx_pktlen < internals->max_rx_pktlen) {
489 RTE_BOND_LOG(ERR, "Slave (port %u) max_rx_pktlen too small",
494 slave_add(internals, slave_eth_dev);
496 /* We need to store slaves reta_size to be able to synchronize RETA for all
497 * slave devices even if its sizes are different.
499 internals->slaves[internals->slave_count].reta_size = dev_info.reta_size;
501 if (internals->slave_count < 1) {
502 /* if MAC is not user defined then use MAC of first slave add to
504 if (!internals->user_defined_mac) {
505 if (mac_address_set(bonded_eth_dev,
506 slave_eth_dev->data->mac_addrs)) {
507 RTE_BOND_LOG(ERR, "Failed to set MAC address");
512 /* Make primary slave */
513 internals->primary_port = slave_port_id;
514 internals->current_primary_port = slave_port_id;
516 /* Inherit queues settings from first slave */
517 internals->nb_rx_queues = slave_eth_dev->data->nb_rx_queues;
518 internals->nb_tx_queues = slave_eth_dev->data->nb_tx_queues;
520 eth_bond_slave_inherit_dev_info_rx_first(internals, &dev_info);
521 eth_bond_slave_inherit_dev_info_tx_first(internals, &dev_info);
523 eth_bond_slave_inherit_desc_lim_first(&internals->rx_desc_lim,
524 &dev_info.rx_desc_lim);
525 eth_bond_slave_inherit_desc_lim_first(&internals->tx_desc_lim,
526 &dev_info.tx_desc_lim);
530 eth_bond_slave_inherit_dev_info_rx_next(internals, &dev_info);
531 eth_bond_slave_inherit_dev_info_tx_next(internals, &dev_info);
533 ret = eth_bond_slave_inherit_desc_lim_next(
534 &internals->rx_desc_lim, &dev_info.rx_desc_lim);
538 ret = eth_bond_slave_inherit_desc_lim_next(
539 &internals->tx_desc_lim, &dev_info.tx_desc_lim);
544 bonded_eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf &=
545 internals->flow_type_rss_offloads;
547 if (slave_rte_flow_prepare(internals->slave_count, internals) != 0) {
548 RTE_BOND_LOG(ERR, "Failed to prepare new slave flows: port=%d",
553 /* Add additional MAC addresses to the slave */
554 if (slave_add_mac_addresses(bonded_eth_dev, slave_port_id) != 0) {
555 RTE_BOND_LOG(ERR, "Failed to add mac address(es) to slave %hu",
560 internals->slave_count++;
562 if (bonded_eth_dev->data->dev_started) {
563 if (slave_configure(bonded_eth_dev, slave_eth_dev) != 0) {
564 internals->slave_count--;
565 RTE_BOND_LOG(ERR, "rte_bond_slaves_configure: port=%d",
571 /* Update all slave devices MACs */
572 mac_address_slaves_update(bonded_eth_dev);
574 /* Register link status change callback with bonded device pointer as
576 rte_eth_dev_callback_register(slave_port_id, RTE_ETH_EVENT_INTR_LSC,
577 bond_ethdev_lsc_event_callback, &bonded_eth_dev->data->port_id);
579 /* If bonded device is started then we can add the slave to our active
581 if (bonded_eth_dev->data->dev_started) {
582 ret = rte_eth_link_get_nowait(slave_port_id, &link_props);
584 rte_eth_dev_callback_unregister(slave_port_id,
585 RTE_ETH_EVENT_INTR_LSC,
586 bond_ethdev_lsc_event_callback,
587 &bonded_eth_dev->data->port_id);
588 internals->slave_count--;
590 "Slave (port %u) link get failed: %s\n",
591 slave_port_id, rte_strerror(-ret));
595 if (link_props.link_status == RTE_ETH_LINK_UP) {
596 if (internals->active_slave_count == 0 &&
597 !internals->user_defined_primary_port)
598 bond_ethdev_primary_set(internals,
603 /* Add slave details to bonded device */
604 slave_eth_dev->data->dev_flags |= RTE_ETH_DEV_BONDED_SLAVE;
606 slave_vlan_filter_set(bonded_port_id, slave_port_id);
613 rte_eth_bond_slave_add(uint16_t bonded_port_id, uint16_t slave_port_id)
615 struct rte_eth_dev *bonded_eth_dev;
616 struct bond_dev_private *internals;
620 if (valid_bonded_port_id(bonded_port_id) != 0)
623 bonded_eth_dev = &rte_eth_devices[bonded_port_id];
624 internals = bonded_eth_dev->data->dev_private;
626 if (valid_slave_port_id(internals, slave_port_id) != 0)
629 rte_spinlock_lock(&internals->lock);
631 retval = __eth_bond_slave_add_lock_free(bonded_port_id, slave_port_id);
633 rte_spinlock_unlock(&internals->lock);
639 __eth_bond_slave_remove_lock_free(uint16_t bonded_port_id,
640 uint16_t slave_port_id)
642 struct rte_eth_dev *bonded_eth_dev;
643 struct bond_dev_private *internals;
644 struct rte_eth_dev *slave_eth_dev;
645 struct rte_flow_error flow_error;
646 struct rte_flow *flow;
649 bonded_eth_dev = &rte_eth_devices[bonded_port_id];
650 internals = bonded_eth_dev->data->dev_private;
652 if (valid_slave_port_id(internals, slave_port_id) < 0)
655 /* first remove from active slave list */
656 slave_idx = find_slave_by_id(internals->active_slaves,
657 internals->active_slave_count, slave_port_id);
659 if (slave_idx < internals->active_slave_count)
660 deactivate_slave(bonded_eth_dev, slave_port_id);
663 /* now find in slave list */
664 for (i = 0; i < internals->slave_count; i++)
665 if (internals->slaves[i].port_id == slave_port_id) {
671 RTE_BOND_LOG(ERR, "Couldn't find slave in port list, slave count %d",
672 internals->slave_count);
676 /* Un-register link status change callback with bonded device pointer as
678 rte_eth_dev_callback_unregister(slave_port_id, RTE_ETH_EVENT_INTR_LSC,
679 bond_ethdev_lsc_event_callback,
680 &rte_eth_devices[bonded_port_id].data->port_id);
682 /* Restore original MAC address of slave device */
683 rte_eth_dev_default_mac_addr_set(slave_port_id,
684 &(internals->slaves[slave_idx].persisted_mac_addr));
686 /* remove additional MAC addresses from the slave */
687 slave_remove_mac_addresses(bonded_eth_dev, slave_port_id);
690 * Remove bond device flows from slave device.
691 * Note: don't restore flow isolate mode.
693 TAILQ_FOREACH(flow, &internals->flow_list, next) {
694 if (flow->flows[slave_idx] != NULL) {
695 rte_flow_destroy(slave_port_id, flow->flows[slave_idx],
697 flow->flows[slave_idx] = NULL;
701 slave_eth_dev = &rte_eth_devices[slave_port_id];
702 slave_remove(internals, slave_eth_dev);
703 slave_eth_dev->data->dev_flags &= (~RTE_ETH_DEV_BONDED_SLAVE);
705 /* first slave in the active list will be the primary by default,
706 * otherwise use first device in list */
707 if (internals->current_primary_port == slave_port_id) {
708 if (internals->active_slave_count > 0)
709 internals->current_primary_port = internals->active_slaves[0];
710 else if (internals->slave_count > 0)
711 internals->current_primary_port = internals->slaves[0].port_id;
713 internals->primary_port = 0;
714 mac_address_slaves_update(bonded_eth_dev);
717 if (internals->active_slave_count < 1) {
718 /* if no slaves are any longer attached to bonded device and MAC is not
719 * user defined then clear MAC of bonded device as it will be reset
720 * when a new slave is added */
721 if (internals->slave_count < 1 && !internals->user_defined_mac)
722 memset(rte_eth_devices[bonded_port_id].data->mac_addrs, 0,
723 sizeof(*(rte_eth_devices[bonded_port_id].data->mac_addrs)));
725 if (internals->slave_count == 0) {
726 internals->rx_offload_capa = 0;
727 internals->tx_offload_capa = 0;
728 internals->rx_queue_offload_capa = 0;
729 internals->tx_queue_offload_capa = 0;
730 internals->flow_type_rss_offloads = RTE_ETH_RSS_PROTO_MASK;
731 internals->reta_size = 0;
732 internals->candidate_max_rx_pktlen = 0;
733 internals->max_rx_pktlen = 0;
739 rte_eth_bond_slave_remove(uint16_t bonded_port_id, uint16_t slave_port_id)
741 struct rte_eth_dev *bonded_eth_dev;
742 struct bond_dev_private *internals;
745 if (valid_bonded_port_id(bonded_port_id) != 0)
748 bonded_eth_dev = &rte_eth_devices[bonded_port_id];
749 internals = bonded_eth_dev->data->dev_private;
751 rte_spinlock_lock(&internals->lock);
753 retval = __eth_bond_slave_remove_lock_free(bonded_port_id, slave_port_id);
755 rte_spinlock_unlock(&internals->lock);
761 rte_eth_bond_mode_set(uint16_t bonded_port_id, uint8_t mode)
763 struct rte_eth_dev *bonded_eth_dev;
765 if (valid_bonded_port_id(bonded_port_id) != 0)
768 bonded_eth_dev = &rte_eth_devices[bonded_port_id];
770 if (check_for_master_bonded_ethdev(bonded_eth_dev) != 0 &&
771 mode == BONDING_MODE_8023AD)
774 return bond_ethdev_mode_set(bonded_eth_dev, mode);
778 rte_eth_bond_mode_get(uint16_t bonded_port_id)
780 struct bond_dev_private *internals;
782 if (valid_bonded_port_id(bonded_port_id) != 0)
785 internals = rte_eth_devices[bonded_port_id].data->dev_private;
787 return internals->mode;
791 rte_eth_bond_primary_set(uint16_t bonded_port_id, uint16_t slave_port_id)
793 struct bond_dev_private *internals;
795 if (valid_bonded_port_id(bonded_port_id) != 0)
798 internals = rte_eth_devices[bonded_port_id].data->dev_private;
800 if (valid_slave_port_id(internals, slave_port_id) != 0)
803 internals->user_defined_primary_port = 1;
804 internals->primary_port = slave_port_id;
806 bond_ethdev_primary_set(internals, slave_port_id);
812 rte_eth_bond_primary_get(uint16_t bonded_port_id)
814 struct bond_dev_private *internals;
816 if (valid_bonded_port_id(bonded_port_id) != 0)
819 internals = rte_eth_devices[bonded_port_id].data->dev_private;
821 if (internals->slave_count < 1)
824 return internals->current_primary_port;
828 rte_eth_bond_slaves_get(uint16_t bonded_port_id, uint16_t slaves[],
831 struct bond_dev_private *internals;
834 if (valid_bonded_port_id(bonded_port_id) != 0)
840 internals = rte_eth_devices[bonded_port_id].data->dev_private;
842 if (internals->slave_count > len)
845 for (i = 0; i < internals->slave_count; i++)
846 slaves[i] = internals->slaves[i].port_id;
848 return internals->slave_count;
852 rte_eth_bond_active_slaves_get(uint16_t bonded_port_id, uint16_t slaves[],
855 struct bond_dev_private *internals;
857 if (valid_bonded_port_id(bonded_port_id) != 0)
863 internals = rte_eth_devices[bonded_port_id].data->dev_private;
865 if (internals->active_slave_count > len)
868 memcpy(slaves, internals->active_slaves,
869 internals->active_slave_count * sizeof(internals->active_slaves[0]));
871 return internals->active_slave_count;
875 rte_eth_bond_mac_address_set(uint16_t bonded_port_id,
876 struct rte_ether_addr *mac_addr)
878 struct rte_eth_dev *bonded_eth_dev;
879 struct bond_dev_private *internals;
881 if (valid_bonded_port_id(bonded_port_id) != 0)
884 bonded_eth_dev = &rte_eth_devices[bonded_port_id];
885 internals = bonded_eth_dev->data->dev_private;
887 /* Set MAC Address of Bonded Device */
888 if (mac_address_set(bonded_eth_dev, mac_addr))
891 internals->user_defined_mac = 1;
893 /* Update all slave devices MACs*/
894 if (internals->slave_count > 0)
895 return mac_address_slaves_update(bonded_eth_dev);
901 rte_eth_bond_mac_address_reset(uint16_t bonded_port_id)
903 struct rte_eth_dev *bonded_eth_dev;
904 struct bond_dev_private *internals;
906 if (valid_bonded_port_id(bonded_port_id) != 0)
909 bonded_eth_dev = &rte_eth_devices[bonded_port_id];
910 internals = bonded_eth_dev->data->dev_private;
912 internals->user_defined_mac = 0;
914 if (internals->slave_count > 0) {
916 /* Get the primary slave location based on the primary port
917 * number as, while slave_add(), we will keep the primary
918 * slave based on slave_count,but not based on the primary port.
920 for (slave_port = 0; slave_port < internals->slave_count;
922 if (internals->slaves[slave_port].port_id ==
923 internals->primary_port)
927 /* Set MAC Address of Bonded Device */
928 if (mac_address_set(bonded_eth_dev,
929 &internals->slaves[slave_port].persisted_mac_addr)
931 RTE_BOND_LOG(ERR, "Failed to set MAC address on bonded device");
934 /* Update all slave devices MAC addresses */
935 return mac_address_slaves_update(bonded_eth_dev);
937 /* No need to update anything as no slaves present */
942 rte_eth_bond_xmit_policy_set(uint16_t bonded_port_id, uint8_t policy)
944 struct bond_dev_private *internals;
946 if (valid_bonded_port_id(bonded_port_id) != 0)
949 internals = rte_eth_devices[bonded_port_id].data->dev_private;
952 case BALANCE_XMIT_POLICY_LAYER2:
953 internals->balance_xmit_policy = policy;
954 internals->burst_xmit_hash = burst_xmit_l2_hash;
956 case BALANCE_XMIT_POLICY_LAYER23:
957 internals->balance_xmit_policy = policy;
958 internals->burst_xmit_hash = burst_xmit_l23_hash;
960 case BALANCE_XMIT_POLICY_LAYER34:
961 internals->balance_xmit_policy = policy;
962 internals->burst_xmit_hash = burst_xmit_l34_hash;
972 rte_eth_bond_xmit_policy_get(uint16_t bonded_port_id)
974 struct bond_dev_private *internals;
976 if (valid_bonded_port_id(bonded_port_id) != 0)
979 internals = rte_eth_devices[bonded_port_id].data->dev_private;
981 return internals->balance_xmit_policy;
985 rte_eth_bond_link_monitoring_set(uint16_t bonded_port_id, uint32_t internal_ms)
987 struct bond_dev_private *internals;
989 if (valid_bonded_port_id(bonded_port_id) != 0)
992 internals = rte_eth_devices[bonded_port_id].data->dev_private;
993 internals->link_status_polling_interval_ms = internal_ms;
999 rte_eth_bond_link_monitoring_get(uint16_t bonded_port_id)
1001 struct bond_dev_private *internals;
1003 if (valid_bonded_port_id(bonded_port_id) != 0)
1006 internals = rte_eth_devices[bonded_port_id].data->dev_private;
1008 return internals->link_status_polling_interval_ms;
1012 rte_eth_bond_link_down_prop_delay_set(uint16_t bonded_port_id,
1016 struct bond_dev_private *internals;
1018 if (valid_bonded_port_id(bonded_port_id) != 0)
1021 internals = rte_eth_devices[bonded_port_id].data->dev_private;
1022 internals->link_down_delay_ms = delay_ms;
1028 rte_eth_bond_link_down_prop_delay_get(uint16_t bonded_port_id)
1030 struct bond_dev_private *internals;
1032 if (valid_bonded_port_id(bonded_port_id) != 0)
1035 internals = rte_eth_devices[bonded_port_id].data->dev_private;
1037 return internals->link_down_delay_ms;
1041 rte_eth_bond_link_up_prop_delay_set(uint16_t bonded_port_id, uint32_t delay_ms)
1044 struct bond_dev_private *internals;
1046 if (valid_bonded_port_id(bonded_port_id) != 0)
1049 internals = rte_eth_devices[bonded_port_id].data->dev_private;
1050 internals->link_up_delay_ms = delay_ms;
1056 rte_eth_bond_link_up_prop_delay_get(uint16_t bonded_port_id)
1058 struct bond_dev_private *internals;
1060 if (valid_bonded_port_id(bonded_port_id) != 0)
1063 internals = rte_eth_devices[bonded_port_id].data->dev_private;
1065 return internals->link_up_delay_ms;