Lines Matching refs:slave
20 * the first slave bonded to the channel. All slaves will then use
27 * will attach eth0 to bond0 as a slave. eth0 hw mac address will either
146 MODULE_PARM_DESC(primary_reselect, "Reselect primary slave "
151 "2 for only on active slave "
190 MODULE_PARM_DESC(packets_per_slave, "Packets to send per slave in balance-rr "
191 "mode; 0 for a random slave, 1 packet per "
192 "slave (default), >1 packets per slave.");
287 * @slave_dev: slave that is supposed to xmit this skbuff
307 * We don't protect the slave list iteration with a lock because:
332 struct slave *slave, *rollback_slave;
336 bond_for_each_slave(bond, slave, iter) {
337 res = vlan_vid_add(slave->dev, proto, vid);
345 /* unwind to the slave that failed */
347 if (rollback_slave == slave)
367 struct slave *slave;
369 bond_for_each_slave(bond, slave, iter)
370 vlan_vid_del(slave->dev, proto, vid);
390 struct slave *slave;
398 slave = rcu_dereference(bond->curr_active_slave);
399 if (!slave) {
404 if (!slave->dev->xfrmdev_ops ||
405 !slave->dev->xfrmdev_ops->xdo_dev_state_add ||
406 netif_is_bond_master(slave->dev)) {
407 slave_warn(bond_dev, slave->dev, "Slave does not support ipsec offload\n");
417 xs->xso.real_dev = slave->dev;
419 err = slave->dev->xfrmdev_ops->xdo_dev_state_add(xs);
437 struct slave *slave;
440 slave = rcu_dereference(bond->curr_active_slave);
441 if (!slave)
444 if (!slave->dev->xfrmdev_ops ||
445 !slave->dev->xfrmdev_ops->xdo_dev_state_add ||
446 netif_is_bond_master(slave->dev)) {
449 slave_warn(bond_dev, slave->dev,
450 "%s: no slave xdo_dev_state_add\n",
458 ipsec->xs->xso.real_dev = slave->dev;
459 if (slave->dev->xfrmdev_ops->xdo_dev_state_add(ipsec->xs)) {
460 slave_warn(bond_dev, slave->dev, "%s: failed to add SA\n", __func__);
478 struct slave *slave;
485 slave = rcu_dereference(bond->curr_active_slave);
487 if (!slave)
493 WARN_ON(xs->xso.real_dev != slave->dev);
495 if (!slave->dev->xfrmdev_ops ||
496 !slave->dev->xfrmdev_ops->xdo_dev_state_delete ||
497 netif_is_bond_master(slave->dev)) {
498 slave_warn(bond_dev, slave->dev, "%s: no slave xdo_dev_state_delete\n", __func__);
502 slave->dev->xfrmdev_ops->xdo_dev_state_delete(xs);
520 struct slave *slave;
523 slave = rcu_dereference(bond->curr_active_slave);
524 if (!slave) {
534 if (!slave->dev->xfrmdev_ops ||
535 !slave->dev->xfrmdev_ops->xdo_dev_state_delete ||
536 netif_is_bond_master(slave->dev)) {
537 slave_warn(bond_dev, slave->dev,
538 "%s: no slave xdo_dev_state_delete\n",
541 slave->dev->xfrmdev_ops->xdo_dev_state_delete(ipsec->xs);
557 struct slave *curr_active;
609 struct slave *slave;
617 bond_for_each_slave(bond, slave, iter) {
618 if (slave->link == BOND_LINK_UP) {
635 /* Get link speed and duplex from the slave's base driver
641 static int bond_update_speed_duplex(struct slave *slave)
643 struct net_device *slave_dev = slave->dev;
647 slave->speed = SPEED_UNKNOWN;
648 slave->duplex = DUPLEX_UNKNOWN;
663 slave->speed = ecmd.base.speed;
664 slave->duplex = ecmd.base.duplex;
761 struct slave *curr_active = rtnl_dereference(bond->curr_active_slave);
766 struct slave *slave;
768 bond_for_each_slave(bond, slave, iter) {
769 err = dev_set_promiscuity(slave->dev, inc);
784 struct slave *curr_active = rtnl_dereference(bond->curr_active_slave);
789 struct slave *slave;
791 bond_for_each_slave(bond, slave, iter) {
792 err = dev_set_allmulti(slave->dev, inc);
802 * slave.
822 /* Flush bond's hardware addresses from slave */
835 /*--------------------------- Active slave change ---------------------------*/
842 static void bond_hw_addr_swap(struct bonding *bond, struct slave *new_active,
843 struct slave *old_active)
874 * bond_set_dev_addr - clone slave's address to bond
876 * @slave_dev: slave net device
897 static struct slave *bond_get_old_active(struct bonding *bond,
898 struct slave *new_active)
900 struct slave *slave;
903 bond_for_each_slave(bond, slave, iter) {
904 if (slave == new_active)
907 if (ether_addr_equal(bond->dev->dev_addr, slave->dev->dev_addr))
908 return slave;
921 struct slave *new_active,
922 struct slave *old_active)
933 slave_err(bond->dev, new_active->dev, "Error %d setting bond MAC from slave\n",
939 * if just old_active, do nothing (going to no active slave)
964 slave_err(bond->dev, new_active->dev, "Error %d setting MAC of new active slave\n",
979 slave_err(bond->dev, old_active->dev, "Error %d setting MAC of old active slave\n",
991 static struct slave *bond_choose_primary_or_current(struct bonding *bond)
993 struct slave *prim = rtnl_dereference(bond->primary_slave);
994 struct slave *curr = rtnl_dereference(bond->curr_active_slave);
1030 * bond_find_best_slave - select the best available slave to be the active one
1033 static struct slave *bond_find_best_slave(struct bonding *bond)
1035 struct slave *slave, *bestslave = NULL;
1039 slave = bond_choose_primary_or_current(bond);
1040 if (slave)
1041 return slave;
1043 bond_for_each_slave(bond, slave, iter) {
1044 if (slave->link == BOND_LINK_UP)
1045 return slave;
1046 if (slave->link == BOND_LINK_BACK && bond_slave_is_up(slave) &&
1047 slave->delay < mintime) {
1048 mintime = slave->delay;
1049 bestslave = slave;
1058 struct slave *slave;
1061 slave = rcu_dereference(bond->curr_active_slave);
1064 if (!slave || !bond->send_peer_notif ||
1068 test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state))
1071 netdev_dbg(bond->dev, "bond_should_notify_peers: slave %s\n",
1072 slave ? slave->dev->name : "NULL");
1078 * change_active_interface - change the active slave into the specified one
1080 * @new_active: the new slave to make the active one
1082 * Set the new slave to the bond's settings and unset them on the old
1087 * because it is apparently the best available slave we have, even though its
1092 void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
1094 struct slave *old_active;
1183 /* resend IGMP joins since active slave has changed or
1197 * bond_select_active_slave - select a new active slave, if needed
1203 * - A slave has got its link back and there's no old curr_active_slave.
1209 struct slave *best_slave;
1229 static inline int slave_enable_netpoll(struct slave *slave)
1239 err = __netpoll_setup(np, slave->dev);
1244 slave->np = np;
1248 static inline void slave_disable_netpoll(struct slave *slave)
1250 struct netpoll *np = slave->np;
1255 slave->np = NULL;
1263 struct slave *slave = NULL;
1271 bond_for_each_slave_rcu(bond, slave, iter) {
1272 if (!bond_slave_is_up(slave))
1277 SLAVE_AD_INFO(slave)->port.aggregator;
1284 netpoll_poll_dev(slave->dev);
1292 struct slave *slave;
1294 bond_for_each_slave(bond, slave, iter)
1295 if (bond_slave_is_up(slave))
1296 slave_disable_netpoll(slave);
1303 struct slave *slave;
1306 bond_for_each_slave(bond, slave, iter) {
1307 err = slave_enable_netpoll(slave);
1316 static inline int slave_enable_netpoll(struct slave *slave)
1320 static inline void slave_disable_netpoll(struct slave *slave)
1336 struct slave *slave;
1343 bond_for_each_slave(bond, slave, iter) {
1345 slave->dev->features,
1376 struct slave *slave;
1386 bond_for_each_slave(bond, slave, iter) {
1388 slave->dev->vlan_features, BOND_VLAN_FEATURES);
1391 slave->dev->hw_enc_features,
1396 slave->dev->hw_enc_features,
1401 slave->dev->mpls_features,
1404 dst_release_flag &= slave->dev->priv_flags;
1405 if (slave->dev->hard_header_len > max_hard_header_len)
1406 max_hard_header_len = slave->dev->hard_header_len;
1408 gso_max_size = min(gso_max_size, slave->dev->gso_max_size);
1409 gso_max_segs = min(gso_max_segs, slave->dev->gso_max_segs);
1459 /* On bonding slaves other than the currently active slave, suppress
1463 struct slave *slave,
1466 if (bond_is_slave_inactive(slave)) {
1479 struct slave *slave;
1482 struct slave *);
1491 slave = bond_slave_get_rcu(skb->dev);
1492 bond = slave->bond;
1496 ret = recv_probe(skb, bond, slave);
1507 * inactive slave links without being forced to bind to them
1514 if (bond_should_deliver_exact_match(skb, slave, bond)) {
1577 static int bond_master_upper_dev_link(struct bonding *bond, struct slave *slave,
1587 return netdev_master_upper_dev_link(slave->dev, bond->dev, slave,
1591 static void bond_upper_dev_unlink(struct bonding *bond, struct slave *slave)
1593 netdev_upper_dev_unlink(slave->dev, bond->dev);
1594 slave->dev->flags &= ~IFF_SLAVE;
1599 struct slave *slave = to_slave(kobj);
1600 struct bonding *bond = bond_get_bond_by_slave(slave);
1602 cancel_delayed_work_sync(&slave->notify_work);
1604 kfree(SLAVE_AD_INFO(slave));
1606 kfree(slave);
1616 static int bond_kobj_init(struct slave *slave)
1620 err = kobject_init_and_add(&slave->kobj, &slave_ktype,
1621 &(slave->dev->dev.kobj), "bonding_slave");
1623 kobject_put(&slave->kobj);
1628 static struct slave *bond_alloc_slave(struct bonding *bond,
1631 struct slave *slave = NULL;
1633 slave = kzalloc(sizeof(*slave), GFP_KERNEL);
1634 if (!slave)
1637 slave->bond = bond;
1638 slave->dev = slave_dev;
1639 INIT_DELAYED_WORK(&slave->notify_work, bond_netdev_notify_work);
1641 if (bond_kobj_init(slave))
1645 SLAVE_AD_INFO(slave) = kzalloc(sizeof(struct ad_slave_info),
1647 if (!SLAVE_AD_INFO(slave)) {
1648 kobject_put(&slave->kobj);
1653 return slave;
1663 static void bond_fill_ifslave(struct slave *slave, struct ifslave *info)
1665 strcpy(info->slave_name, slave->dev->name);
1666 info->link = slave->link;
1667 info->state = bond_slave_state(slave);
1668 info->link_failure_count = slave->link_failure_count;
1673 struct slave *slave = container_of(_work, struct slave,
1679 bond_fill_ifslave(slave, &binfo.slave);
1680 bond_fill_ifbond(slave->bond, &binfo.master);
1681 netdev_bonding_info_change(slave->dev, &binfo);
1684 queue_delayed_work(slave->bond->wq, &slave->notify_work, 1);
1688 void bond_queue_slave_event(struct slave *slave)
1690 queue_delayed_work(slave->bond->wq, &slave->notify_work, 0);
1693 void bond_lower_state_changed(struct slave *slave)
1697 info.link_up = slave->link == BOND_LINK_UP ||
1698 slave->link == BOND_LINK_FAIL;
1699 info.tx_enabled = bond_is_active_slave(slave);
1700 netdev_lower_state_changed(slave->dev, &info);
1703 /* enslave device <slave> to bond device <master> */
1709 struct slave *new_slave = NULL, *prev_slave;
1740 slave_err(bond_dev, slave_dev, "Error: cannot enslave VLAN challenged slave on VLAN enabled bond\n");
1743 slave_warn(bond_dev, slave_dev, "enslaved VLAN challenged slave. Adding VLANs will be blocked as long as it is part of bond.\n");
1753 * be identified with moderate accuracy by the state of the slave:
1759 slave_err(bond_dev, slave_dev, "slave is up - this may be due to an out of date ifenslave\n");
1763 /* set bonding device ether type by slave - bonding netdevices are
1764 * created with ether_setup, so when the slave type is not ARPHRD_ETHER
1815 slave_warn(bond_dev, slave_dev, "The slave device specified does not support setting the MAC address\n");
1823 slave_err(bond_dev, slave_dev, "The slave device specified does not support setting the MAC address, but fail_over_mac is not set to active\n");
1832 /* If this is the first slave, then we need to set the master's hardware
1833 * address to be the same as the slave's.
1853 /* Save slave's original mtu and then set it to match the bond */
1861 /* Save slave's original ("permanent") mac address for modes
1870 /* Set slave to master's mac address. The application already
1871 * set the master's mac address to that of the first slave
1883 /* set slave flag before open to prevent IPv6 addrconf */
1886 /* open the slave since the application closed it */
1889 slave_err(bond_dev, slave_dev, "Opening slave failed\n");
1894 /* initialize slave stats */
1938 slave_warn(bond_dev, slave_dev, "MII and ETHTOOL support not available for slave, and arp_interval/arp_ip_target module parameters not specified, thus bonding will not detect link failures! see bonding.txt for details\n");
1941 slave_warn(bond_dev, slave_dev, "can't get link status from slave; the network driver associated with this interface does not support MII or ETHTOOL link status reporting, thus miimon has no effect on this interface\n");
1975 slave_dbg(bond_dev, slave_dev, "Initial state of slave is BOND_LINK_%s\n",
1980 /* if there is a primary slave, remember it */
1998 /* if this is the first slave */
2018 slave_dbg(bond_dev, slave_dev, "This slave is always active in trunk mode\n");
2037 slave_info(bond_dev, slave_dev, "master_dev is using netpoll, but new slave device does not support netpoll\n");
2070 /* set promiscuity level to new slave */
2077 /* set allmulti level to new slave */
2154 * MAC if this slave's MAC is in use by the bond, or at
2170 /* Enslave of first slave has failed and we need to fix master's mac */
2186 /* Try to release the slave device <slave> from the bond device <master>
2191 * The rules for slave state should be:
2202 struct slave *slave, *oldcurrent;
2207 /* slave is not a slave or master is not master of this slave */
2210 slave_dbg(bond_dev, slave_dev, "cannot release slave\n");
2216 slave = bond_get_slave_by_dev(bond, slave_dev);
2217 if (!slave) {
2218 /* not a slave of this bond */
2224 bond_set_slave_inactive_flags(slave, BOND_SLAVE_NOTIFY_NOW);
2226 bond_sysfs_slave_del(slave);
2228 /* recompute stats just before removing the slave */
2232 * for this slave anymore.
2237 bond_3ad_unbind_slave(slave);
2239 bond_upper_dev_unlink(bond, slave);
2242 bond_update_slave_arr(bond, slave);
2245 bond_is_active_slave(slave) ? "active" : "backup");
2253 if (ether_addr_equal_64bits(bond_dev->dev_addr, slave->perm_hwaddr) &&
2255 slave_warn(bond_dev, slave_dev, "the permanent HWaddr of slave - %pM - is still in use by bond - set the HWaddr of slave to a different address to avoid conflicts\n",
2256 slave->perm_hwaddr);
2259 if (rtnl_dereference(bond->primary_slave) == slave)
2262 if (oldcurrent == slave)
2266 /* Must be called only after the slave has been
2269 * but before a new active slave is selected.
2271 bond_alb_deinit_slave(bond, slave);
2276 } else if (oldcurrent == slave) {
2278 * is no concern that another slave add/remove event
2300 slave_info(bond_dev, slave_dev, "last VLAN challenged slave left bond - VLAN blocking is removed\n");
2308 /* unset promiscuity level from slave
2312 * when this slave was attached, so we cache at the start of the
2318 /* unset allmulti level from slave */
2326 slave_disable_netpoll(slave);
2328 /* close slave before restoring its mac address */
2334 bond_hw_addr_copy(ss.__data, slave->perm_hwaddr,
2335 slave->dev->addr_len);
2341 __dev_set_mtu(slave_dev, slave->original_mtu);
2343 dev_set_mtu(slave_dev, slave->original_mtu);
2348 kobject_put(&slave->kobj);
2359 /* First release a slave and then destroy the bond if no more slaves are left.
2390 struct slave *slave;
2392 bond_for_each_slave(bond, slave, iter) {
2395 bond_fill_ifslave(slave, info);
2411 struct slave *slave;
2424 bond_for_each_slave_rcu(bond, slave, iter) {
2425 bond_propose_link_state(slave, BOND_LINK_NOCHANGE);
2427 link_state = bond_check_dev_link(bond, slave->dev, 0);
2429 switch (slave->link) {
2434 bond_propose_link_state(slave, BOND_LINK_FAIL);
2436 slave->delay = bond->params.downdelay;
2437 if (slave->delay) {
2438 slave_info(bond->dev, slave->dev, "link status down for %sinterface, disabling it in %d ms\n",
2441 (bond_is_active_slave(slave) ?
2449 bond_propose_link_state(slave, BOND_LINK_UP);
2450 slave->last_link_up = jiffies;
2451 slave_info(bond->dev, slave->dev, "link status up again after %d ms\n",
2452 (bond->params.downdelay - slave->delay) *
2458 if (slave->delay <= 0) {
2459 bond_propose_link_state(slave, BOND_LINK_DOWN);
2464 slave->delay--;
2471 bond_propose_link_state(slave, BOND_LINK_BACK);
2473 slave->delay = bond->params.updelay;
2475 if (slave->delay) {
2476 slave_info(bond->dev, slave->dev, "link status up, enabling it in %d ms\n",
2484 bond_propose_link_state(slave, BOND_LINK_DOWN);
2485 slave_info(bond->dev, slave->dev, "link status down again after %d ms\n",
2486 (bond->params.updelay - slave->delay) *
2493 slave->delay = 0;
2495 if (slave->delay <= 0) {
2496 bond_propose_link_state(slave, BOND_LINK_UP);
2502 slave->delay--;
2511 struct slave *slave,
2516 bond_3ad_handle_link_change(slave, link);
2520 bond_alb_handle_link_change(bond, slave, link);
2531 struct slave *slave, *primary;
2533 bond_for_each_slave(bond, slave, iter) {
2534 switch (slave->link_new_state) {
2536 /* For 802.3ad mode, check current slave speed and
2543 slave->link == BOND_LINK_UP)
2544 bond_3ad_adapter_speed_duplex_changed(slave);
2548 if (bond_update_speed_duplex(slave) &&
2550 slave->link = BOND_LINK_DOWN;
2552 slave_warn(bond->dev, slave->dev,
2556 bond_set_slave_link_state(slave, BOND_LINK_UP,
2558 slave->last_link_up = jiffies;
2563 bond_set_backup_slave(slave);
2566 bond_set_active_slave(slave);
2569 slave_info(bond->dev, slave->dev, "link status definitely up, %u Mbps %s duplex\n",
2570 slave->speed == SPEED_UNKNOWN ? 0 : slave->speed,
2571 slave->duplex ? "full" : "half");
2573 bond_miimon_link_change(bond, slave, BOND_LINK_UP);
2575 if (!bond->curr_active_slave || slave == primary)
2581 if (slave->link_failure_count < UINT_MAX)
2582 slave->link_failure_count++;
2584 bond_set_slave_link_state(slave, BOND_LINK_DOWN,
2589 bond_set_slave_inactive_flags(slave,
2592 slave_info(bond->dev, slave->dev, "link status definitely down, disabling slave\n");
2594 bond_miimon_link_change(bond, slave, BOND_LINK_DOWN);
2596 if (slave == rcu_access_pointer(bond->curr_active_slave))
2602 slave_err(bond->dev, slave->dev, "invalid new link %d on slave\n",
2603 slave->link_new_state);
2604 bond_propose_link_state(slave, BOND_LINK_NOCHANGE);
2632 struct slave *slave;
2661 bond_for_each_slave(bond, slave, iter) {
2662 bond_commit_link_state(slave, BOND_SLAVE_NOTIFY_LATER);
2711 static void bond_arp_send(struct slave *slave, int arp_op, __be32 dest_ip,
2716 struct net_device *slave_dev = slave->dev;
2717 struct net_device *bond_dev = slave->bond->dev;
2719 slave_dbg(bond_dev, slave_dev, "arp %d on slave: dst %pI4 src %pI4\n",
2805 static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
2813 slave_dbg(bond->dev, slave->dev, "%s: target %pI4\n",
2828 bond_arp_send(slave, ARPOP_REQUEST, targets[i],
2845 slave_dbg(bond->dev, slave->dev, "no path to arp_ip_target %pI4 via rt.dev %s\n",
2854 bond_arp_send(slave, ARPOP_REQUEST, targets[i], addr, tags);
2859 static void bond_validate_arp(struct bonding *bond, struct slave *slave, __be32 sip, __be32 tip)
2864 slave_dbg(bond->dev, slave->dev, "%s: sip %pI4 tip %pI4 not found\n",
2871 slave_dbg(bond->dev, slave->dev, "%s: sip %pI4 not found in targets\n",
2875 slave->last_rx = jiffies;
2876 slave->target_last_arp_rx[i] = jiffies;
2880 struct slave *slave)
2883 struct slave *curr_active_slave, *curr_arp_slave;
2889 if (!slave_do_arp_validate(bond, slave)) {
2892 slave->last_rx = jiffies;
2900 slave_dbg(bond->dev, slave->dev, "%s: skb->dev %s\n",
2925 slave_dbg(bond->dev, slave->dev, "%s: %s/%d av %d sv %d sip %pI4 tip %pI4\n",
2926 __func__, slave->dev->name, bond_slave_state(slave),
2927 bond->params.arp_validate, slave_do_arp_validate(bond, slave),
2935 * (a) the slave receiving the ARP is active (which includes the
2936 * current ARP slave, if any), or
2938 * (b) the receiving slave isn't active, but there is a currently
2939 * active slave and it received valid arp reply(s) after it became
2940 * the currently active slave, or
2942 * (c) there is an ARP slave that sent an ARP during the prior ARP
2943 * interval, and we receive an ARP reply on any slave. We accept
2945 * reply to a slave other than the sender of the ARP request.
2949 * slave through the L2 switch(es) to the receiving slave. Since
2956 if (bond_is_active_slave(slave))
2957 bond_validate_arp(bond, slave, sip, tip);
2961 bond_validate_arp(bond, slave, tip, sip);
2965 bond_validate_arp(bond, slave, sip, tip);
2987 /* This function is called regularly to monitor each slave's link
2995 struct slave *slave, *oldcurrent;
3007 * the picture unless it is null. also, slave->last_link_up is not
3008 * needed here because we send an arp on each slave and give a slave
3013 bond_for_each_slave_rcu(bond, slave, iter) {
3014 unsigned long trans_start = dev_trans_start(slave->dev);
3016 bond_propose_link_state(slave, BOND_LINK_NOCHANGE);
3018 if (slave->link != BOND_LINK_UP) {
3020 bond_time_in_interval(bond, slave->last_rx, 1)) {
3022 bond_propose_link_state(slave, BOND_LINK_UP);
3026 * mode. the window of a slave being up and
3031 slave_info(bond->dev, slave->dev, "link status definitely up\n");
3034 slave_info(bond->dev, slave->dev, "interface is now up\n");
3038 /* slave->link == BOND_LINK_UP */
3045 !bond_time_in_interval(bond, slave->last_rx, 2)) {
3047 bond_propose_link_state(slave, BOND_LINK_DOWN);
3050 if (slave->link_failure_count < UINT_MAX)
3051 slave->link_failure_count++;
3053 slave_info(bond->dev, slave->dev, "interface is now down\n");
3055 if (slave == oldcurrent)
3067 if (bond_slave_is_up(slave))
3068 bond_arp_send_all(bond, slave);
3077 bond_for_each_slave(bond, slave, iter) {
3078 if (slave->link_new_state != BOND_LINK_NOCHANGE)
3079 slave->link = slave->link_new_state;
3103 * should take place for the slave. Returns 0 if no changes are found, >0
3112 struct slave *slave;
3115 bond_for_each_slave_rcu(bond, slave, iter) {
3116 bond_propose_link_state(slave, BOND_LINK_NOCHANGE);
3117 last_rx = slave_last_rx(bond, slave);
3119 if (slave->link != BOND_LINK_UP) {
3121 bond_propose_link_state(slave, BOND_LINK_UP);
3123 } else if (slave->link == BOND_LINK_BACK) {
3124 bond_propose_link_state(slave, BOND_LINK_FAIL);
3134 if (bond_time_in_interval(bond, slave->last_link_up, 2))
3137 /* Backup slave is down if:
3146 * gives each slave a chance to tx/rx traffic
3149 if (!bond_is_active_slave(slave) &&
3152 bond_propose_link_state(slave, BOND_LINK_DOWN);
3156 /* Active slave is down if:
3161 trans_start = dev_trans_start(slave->dev);
3162 if (bond_is_active_slave(slave) &&
3165 bond_propose_link_state(slave, BOND_LINK_DOWN);
3182 struct slave *slave;
3184 bond_for_each_slave(bond, slave, iter) {
3185 switch (slave->link_new_state) {
3190 trans_start = dev_trans_start(slave->dev);
3191 if (rtnl_dereference(bond->curr_active_slave) != slave ||
3194 struct slave *current_arp_slave;
3197 bond_set_slave_link_state(slave, BOND_LINK_UP,
3206 slave_info(bond->dev, slave->dev, "link status definitely up\n");
3209 slave == rtnl_dereference(bond->primary_slave))
3217 if (slave->link_failure_count < UINT_MAX)
3218 slave->link_failure_count++;
3220 bond_set_slave_link_state(slave, BOND_LINK_DOWN,
3222 bond_set_slave_inactive_flags(slave,
3225 slave_info(bond->dev, slave->dev, "link status definitely down, disabling slave\n");
3227 if (slave == rtnl_dereference(bond->curr_active_slave)) {
3235 bond_set_slave_link_state(slave, BOND_LINK_FAIL,
3237 bond_set_slave_inactive_flags(slave,
3240 /* A slave has just been enslaved and has become
3241 * the current active slave.
3248 slave_err(bond->dev, slave->dev,
3249 "impossible: link_new_state %d on slave\n",
3250 slave->link_new_state);
3269 struct slave *slave, *before = NULL, *new_slave = NULL,
3287 * backup slave from the current_arp_slave and make it the candidate
3297 bond_for_each_slave_rcu(bond, slave, iter) {
3298 if (!found && !before && bond_slave_is_up(slave))
3299 before = slave;
3301 if (found && !new_slave && bond_slave_is_up(slave))
3302 new_slave = slave;
3307 * one the current slave so it is still marked
3310 if (!bond_slave_is_up(slave) && slave->link == BOND_LINK_UP) {
3311 bond_set_slave_link_state(slave, BOND_LINK_DOWN,
3313 if (slave->link_failure_count < UINT_MAX)
3314 slave->link_failure_count++;
3316 bond_set_slave_inactive_flags(slave,
3319 slave_info(bond->dev, slave->dev, "backup interface is now down\n");
3321 if (slave == curr_arp_slave)
3339 bond_for_each_slave_rcu(bond, slave, iter) {
3340 if (slave->should_notify || slave->should_notify_link) {
3457 struct slave *slave = bond_slave_get_rtnl(slave_dev), *primary;
3463 * slave will be NULL
3465 if (!slave) {
3466 netdev_dbg(slave_dev, "%s called on NULL slave\n", __func__);
3470 bond_dev = slave->bond->dev;
3471 bond = slave->bond;
3486 * Getting invalid Speed/Duplex values here will put slave
3492 if (bond_update_speed_duplex(slave) &&
3494 if (slave->last_link_up)
3495 slave->link = BOND_LINK_FAIL;
3497 slave->link = BOND_LINK_DOWN;
3501 bond_3ad_adapter_speed_duplex_changed(slave);
3504 /* Refresh slave-array if applicable!
3506 * then these events will not cause the slave-array to be
3507 * refreshed. This will cause xmit to use a slave that is not
3523 * take over the slave's change_mtu
3534 if (slave == primary) {
3535 /* slave's name changed - he's no longer primary */
3538 /* we have a new primary slave */
3539 rcu_assign_pointer(bond->primary_slave, slave);
3544 netdev_info(bond->dev, "Primary slave changed to %s, reselecting active slave\n",
3560 call_netdevice_notifiers(event, slave->bond->dev);
3573 * locks for us to safely manipulate the slave devices (RTNL lock,
3759 struct slave *slave;
3761 /* reset slave->backup and slave->inactive */
3763 bond_for_each_slave(bond, slave, iter) {
3765 slave != rcu_access_pointer(bond->curr_active_slave)) {
3766 bond_set_slave_inactive_flags(slave,
3769 bond_set_slave_active_flags(slave,
3799 bond_for_each_slave(bond, slave, iter)
3800 dev_mc_add(slave->dev, lacpdu_mcast_addr);
3812 struct slave *slave;
3822 slave = rcu_dereference(bond->curr_active_slave);
3823 if (slave)
3824 bond_hw_addr_flush(bond_dev, slave->dev);
3829 bond_for_each_slave(bond, slave, iter)
3830 bond_hw_addr_flush(bond_dev, slave->dev);
3912 struct slave *slave;
3924 bond_for_each_slave_rcu(bond, slave, iter) {
3926 dev_get_stats(slave->dev, &temp);
3928 bond_fold_stats(stats, new, &slave->slave_stats);
3930 /* save off the slave stats for the next run */
3931 memcpy(&slave->slave_stats, new, sizeof(*new));
4061 struct slave *slave;
4065 slave = rcu_dereference(bond->curr_active_slave);
4066 if (slave) {
4067 dev_uc_sync(slave->dev, bond_dev);
4068 dev_mc_sync(slave->dev, bond_dev);
4071 bond_for_each_slave_rcu(bond, slave, iter) {
4072 dev_uc_sync_multiple(slave->dev, bond_dev);
4073 dev_mc_sync_multiple(slave->dev, bond_dev);
4084 struct slave *slave;
4088 slave = bond_first_slave_rcu(bond);
4089 if (!slave)
4091 slave_ops = slave->dev->netdev_ops;
4104 ret = slave_ops->ndo_neigh_setup(slave->dev, &parms);
4117 * slave exists. So we must declare proxy setup function which will
4118 * be used at run time to resolve the actual slave neigh param setup.
4138 struct slave *slave, *rollback_slave;
4144 bond_for_each_slave(bond, slave, iter) {
4145 slave_dbg(bond_dev, slave->dev, "s %p c_m %p\n",
4146 slave, slave->dev->netdev_ops->ndo_change_mtu);
4148 res = dev_set_mtu(slave->dev, new_mtu);
4151 /* If we failed to set the slave's mtu to the new value
4154 * different mtu values than the active slave we'll
4159 slave_dbg(bond_dev, slave->dev, "err %d setting mtu to %d\n",
4170 /* unwind from head to the slave that failed */
4174 if (rollback_slave == slave)
4195 struct slave *slave, *rollback_slave;
4216 bond_for_each_slave(bond, slave, iter) {
4217 slave_dbg(bond_dev, slave->dev, "%s: slave=%p\n",
4218 __func__, slave);
4219 res = dev_set_mac_address(slave->dev, addr, NULL);
4221 /* TODO: consider downing the slave
4227 slave_dbg(bond_dev, slave->dev, "%s: err %d\n",
4241 /* unwind from head to the slave that failed */
4245 if (rollback_slave == slave)
4260 * bond_get_slave_by_id - get xmit slave with slave_id
4262 * @slave_id: slave id up to slave_cnt-1 through which to transmit
4264 * This function tries to get slave with slave_id but in case
4265 * it fails, it tries to find the first available slave for transmission.
4267 static struct slave *bond_get_slave_by_id(struct bonding *bond,
4271 struct slave *slave;
4274 /* Here we start from the slave with slave_id */
4275 bond_for_each_slave_rcu(bond, slave, iter) {
4277 if (bond_slave_can_tx(slave))
4278 return slave;
4282 /* Here we start from the first slave up to slave_id */
4284 bond_for_each_slave_rcu(bond, slave, iter) {
4287 if (bond_slave_can_tx(slave))
4288 return slave;
4290 /* no slave that can tx has been found */
4295 * bond_rr_gen_slave_id - generate slave id based on packets_per_slave
4299 * this function generates a slave id, which is usually used as the next
4300 * slave to transmit through.
4327 static struct slave *bond_xmit_roundrobin_slave_get(struct bonding *bond,
4330 struct slave *slave;
4349 slave = rcu_dereference(bond->curr_active_slave);
4350 if (slave)
4351 return slave;
4369 struct slave *slave;
4371 slave = bond_xmit_roundrobin_slave_get(bond, skb);
4372 if (likely(slave))
4373 return bond_dev_queue_xmit(bond, skb, slave->dev);
4378 static struct slave *bond_xmit_activebackup_slave_get(struct bonding *bond,
4391 struct slave *slave;
4393 slave = bond_xmit_activebackup_slave_get(bond, skb);
4394 if (slave)
4395 return bond_dev_queue_xmit(bond, skb, slave->dev);
4422 pr_warn_ratelimited("Failed to update slave array from WT\n");
4432 struct slave *skipslave)
4437 * slave but allocation failed (most likely!). BTW this is
4442 * this to-be-skipped slave to send a packet out.
4487 * to determine the slave interface -
4494 int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave)
4497 struct slave *slave;
4527 bond_for_each_slave(bond, slave, iter) {
4528 if (skipslave == slave)
4531 all_slaves->arr[all_slaves->count++] = slave;
4535 agg = SLAVE_AD_INFO(slave)->port.aggregator;
4539 if (!bond_slave_can_tx(slave))
4542 slave_dbg(bond->dev, slave->dev, "Adding slave to tx hash array[%d]\n",
4545 usable_slaves->arr[usable_slaves->count++] = slave;
4563 static struct slave *bond_xmit_3ad_xor_slave_get(struct bonding *bond,
4567 struct slave *slave;
4576 slave = slaves->arr[hash % count];
4577 return slave;
4581 * usable slave array is formed in the control path. The xmit function
4589 struct slave *slave;
4592 slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves);
4593 if (likely(slave))
4594 return bond_dev_queue_xmit(bond, skb, slave->dev);
4604 struct slave *slave = NULL;
4609 bond_for_each_slave_rcu(bond, slave, iter) {
4612 if (!(bond_slave_is_up(slave) && slave->link == BOND_LINK_UP))
4615 if (bond_is_last_slave(bond, slave)) {
4627 if (bond_dev_queue_xmit(bond, skb2, slave->dev) == NETDEV_TX_OK)
4643 /* Lookup the slave that corresponds to a qid */
4647 struct slave *slave = NULL;
4654 bond_for_each_slave_rcu(bond, slave, iter) {
4655 if (slave->queue_id == skb_get_queue_mapping(skb)) {
4656 if (bond_slave_is_up(slave) &&
4657 slave->link == BOND_LINK_UP) {
4658 bond_dev_queue_xmit(bond, skb, slave->dev);
4661 /* If the slave isn't UP, use default transmit policy. */
4697 struct slave *slave = NULL;
4701 slave = bond_xmit_roundrobin_slave_get(bond, skb);
4704 slave = bond_xmit_activebackup_slave_get(bond, skb);
4712 slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves);
4717 slave = bond_xmit_alb_slave_get(bond, skb);
4720 slave = bond_xmit_tlb_slave_get(bond, skb);
4728 if (slave)
4729 return slave->dev;
4784 static u32 bond_mode_bcast_speed(struct slave *slave, u32 speed)
4787 speed = slave->speed;
4789 speed = min(speed, slave->speed);
4799 struct slave *slave;
4810 bond_for_each_slave(bond, slave, iter) {
4811 if (bond_slave_can_tx(slave)) {
4812 if (slave->speed != SPEED_UNKNOWN) {
4814 speed = bond_mode_bcast_speed(slave,
4817 speed += slave->speed;
4820 slave->duplex != DUPLEX_UNKNOWN)
4821 cmd->base.duplex = slave->duplex;
4955 struct slave *slave;
4960 bond_for_each_slave(bond, slave, iter)
4961 __bond_release_one(bond_dev, slave->dev, true, true);