Lines Matching +full:slave +full:- +full:mode
1 /* SPDX-License-Identifier: GPL-1.0+ */
5 * Portions are (c) Copyright 1995 Simon "Guru Aleph-Null" Janes
43 netdev_info(bond_dev, "(slave %s): " fmt, (slave_dev)->name, ##__VA_ARGS__)
45 netdev_warn(bond_dev, "(slave %s): " fmt, (slave_dev)->name, ##__VA_ARGS__)
47 netdev_dbg(bond_dev, "(slave %s): " fmt, (slave_dev)->name, ##__VA_ARGS__)
49 netdev_err(bond_dev, "(slave %s): " fmt, (slave_dev)->name, ##__VA_ARGS__)
51 #define BOND_MODE(bond) ((bond)->params.mode)
53 /* slave list primitives */
54 #define bond_slave_list(bond) (&(bond)->dev->adj_list.lower)
61 netdev_adjacent_get_private(bond_slave_list(bond)->next) : \
65 netdev_adjacent_get_private(bond_slave_list(bond)->prev) : \
70 netdev_lower_get_first_private_rcu(bond->dev)
76 * bond_for_each_slave - iterate over all slaves
78 * @pos: current slave
84 netdev_for_each_lower_private((bond)->dev, pos, iter)
88 netdev_for_each_lower_private_rcu((bond)->dev, pos, iter)
121 int mode;
159 struct slave {
160 struct net_device *dev; /* first - useful for panic debug */
170 u8 backup:1, /* indicates backup slave. Value corresponds with
172 inactive:1, /* indicates inactive slave */
173 rx_disabled:1, /* indicates whether slave's Rx is disabled */
193 static inline struct slave *to_slave(struct kobject *kobj)
195 return container_of(kobj, struct slave, kobj);
201 struct slave *arr[];
205 * Link pseudo-state only used internally by monitors
207 #define BOND_LINK_NOCHANGE -1
216 * Get rcu_read_lock when reading or RTNL when writing slave list.
219 struct net_device *dev; /* first - useful for panic debug */
220 struct slave __rcu *curr_active_slave;
221 struct slave __rcu *current_arp_slave;
222 struct slave __rcu *primary_slave;
229 struct slave *);
230 /* mode_lock is used for mode-specific locking needs, currently used by:
231 * 3ad mode (4) - protect against running bond_3ad_unbind_slave() and
234 * TLB mode (5) - to sync the use and modifications of its hash table
235 * ALB mode (6) - to sync the use and modifications of its hash table
271 ((struct slave *) rcu_dereference(dev->rx_handler_data))
274 ((struct slave *) rtnl_dereference(dev->rx_handler_data))
276 void bond_queue_slave_event(struct slave *slave);
277 void bond_lower_state_changed(struct slave *slave);
289 static inline struct slave *bond_get_slave_by_dev(struct bonding *bond,
292 return netdev_lower_dev_get_private(bond->dev, slave_dev);
295 static inline struct bonding *bond_get_bond_by_slave(struct slave *slave)
297 return slave->bond;
319 return (bond_is_lb(bond) && bond->params.tlb_dynamic_lb == 0);
337 static inline bool bond_mode_uses_arp(int mode)
339 return mode != BOND_MODE_8023AD && mode != BOND_MODE_TLB &&
340 mode != BOND_MODE_ALB;
343 static inline bool bond_mode_uses_primary(int mode)
345 return mode == BOND_MODE_ACTIVEBACKUP || mode == BOND_MODE_TLB ||
346 mode == BOND_MODE_ALB;
356 struct slave *slave = rcu_dereference_rtnl(bond->curr_active_slave);
358 return bond_uses_primary(bond) && slave ? slave->dev : NULL;
361 static inline bool bond_slave_is_up(struct slave *slave)
363 return netif_running(slave->dev) && netif_carrier_ok(slave->dev);
366 static inline void bond_set_active_slave(struct slave *slave)
368 if (slave->backup) {
369 slave->backup = 0;
370 bond_queue_slave_event(slave);
371 bond_lower_state_changed(slave);
375 static inline void bond_set_backup_slave(struct slave *slave)
377 if (!slave->backup) {
378 slave->backup = 1;
379 bond_queue_slave_event(slave);
380 bond_lower_state_changed(slave);
384 static inline void bond_set_slave_state(struct slave *slave,
387 if (slave->backup == slave_state)
390 slave->backup = slave_state;
392 bond_lower_state_changed(slave);
393 bond_queue_slave_event(slave);
394 slave->should_notify = 0;
396 if (slave->should_notify)
397 slave->should_notify = 0;
399 slave->should_notify = 1;
406 struct slave *tmp;
409 if (tmp->link == BOND_LINK_UP)
411 else if (tmp->link == BOND_LINK_DOWN)
419 struct slave *tmp;
422 if (tmp->should_notify) {
424 tmp->should_notify = 0;
429 static inline int bond_slave_state(struct slave *slave)
431 return slave->backup;
434 static inline bool bond_is_active_slave(struct slave *slave)
436 return !bond_slave_state(slave);
439 static inline bool bond_slave_can_tx(struct slave *slave)
441 return bond_slave_is_up(slave) && slave->link == BOND_LINK_UP &&
442 bond_is_active_slave(slave);
447 struct slave *slave;
451 slave = bond_slave_get_rcu(slave_dev);
452 active = bond_is_active_slave(slave);
494 struct slave *slave)
496 return bond->params.arp_validate & (1 << bond_slave_state(slave));
501 return bond->params.arp_validate & BOND_ARP_FILTER;
518 /* Get the oldest arp which we've received on this slave for bond's
522 struct slave *slave)
525 unsigned long ret = slave->target_last_arp_rx[0];
527 for (; (i < BOND_MAX_ARP_TARGETS) && bond->params.arp_targets[i]; i++)
528 if (time_before(slave->target_last_arp_rx[i], ret))
529 ret = slave->target_last_arp_rx[i];
535 struct slave *slave)
537 if (bond->params.arp_all_targets == BOND_ARP_TARGETS_ALL)
538 return slave_oldest_target_arp_rx(bond, slave);
540 return slave->last_rx;
543 static inline void slave_update_last_tx(struct slave *slave)
545 WRITE_ONCE(slave->last_tx, jiffies);
548 static inline unsigned long slave_last_tx(struct slave *slave)
550 return READ_ONCE(slave->last_tx);
554 static inline netdev_tx_t bond_netpoll_send_skb(const struct slave *slave,
557 return netpoll_send_skb(slave->np, skb);
560 static inline netdev_tx_t bond_netpoll_send_skb(const struct slave *slave,
568 static inline void bond_set_slave_inactive_flags(struct slave *slave,
571 if (!bond_is_lb(slave->bond))
572 bond_set_slave_state(slave, BOND_STATE_BACKUP, notify);
573 if (!slave->bond->params.all_slaves_active)
574 slave->inactive = 1;
575 if (BOND_MODE(slave->bond) == BOND_MODE_8023AD)
576 slave->rx_disabled = 1;
579 static inline void bond_set_slave_tx_disabled_flags(struct slave *slave,
582 bond_set_slave_state(slave, BOND_STATE_BACKUP, notify);
585 static inline void bond_set_slave_active_flags(struct slave *slave,
588 bond_set_slave_state(slave, BOND_STATE_ACTIVE, notify);
589 slave->inactive = 0;
590 if (BOND_MODE(slave->bond) == BOND_MODE_8023AD)
591 slave->rx_disabled = 0;
594 static inline void bond_set_slave_rx_enabled_flags(struct slave *slave,
597 slave->rx_disabled = 0;
600 static inline bool bond_is_slave_inactive(struct slave *slave)
602 return slave->inactive;
605 static inline bool bond_is_slave_rx_disabled(struct slave *slave)
607 return slave->rx_disabled;
610 static inline void bond_propose_link_state(struct slave *slave, int state)
612 slave->link_new_state = state;
615 static inline void bond_commit_link_state(struct slave *slave, bool notify)
617 if (slave->link_new_state == BOND_LINK_NOCHANGE)
620 slave->link = slave->link_new_state;
622 bond_queue_slave_event(slave);
623 bond_lower_state_changed(slave);
624 slave->should_notify_link = 0;
626 if (slave->should_notify_link)
627 slave->should_notify_link = 0;
629 slave->should_notify_link = 1;
633 static inline void bond_set_slave_link_state(struct slave *slave, int state,
636 bond_propose_link_state(slave, state);
637 bond_commit_link_state(slave, notify);
643 struct slave *tmp;
646 if (tmp->should_notify_link) {
649 tmp->should_notify_link = 0;
678 int bond_rcv_validate(const struct sk_buff *skb, struct bonding *bond, struct slave *slave);
684 int bond_sysfs_slave_add(struct slave *slave);
685 void bond_sysfs_slave_del(struct slave *slave);
693 void bond_change_active_slave(struct bonding *bond, struct slave *new_active);
699 const char *bond_mode_name(int mode);
700 bool bond_xdp_check(struct bonding *bond, int mode);
710 int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave);
738 static inline struct slave *bond_slave_has_mac(struct bonding *bond,
742 struct slave *tmp;
745 if (ether_addr_equal_64bits(mac, tmp->dev->dev_addr))
755 struct slave *tmp;
758 if (ether_addr_equal_64bits(mac, tmp->dev->dev_addr))
764 * Returns -1 if not found, index if found
776 return -1;
794 return -1;