Lines Matching +full:slave +full:- +full:dev
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright(c) 1999 - 2004 Intel Corporation. All rights reserved.
37 u8 padding[ETH_ZLEN - ETH_HLEN];
54 static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[],
77 entry->load_history = 1 + entry->tx_bytes / in tlb_init_table_entry()
79 entry->tx_bytes = 0; in tlb_init_table_entry()
82 entry->tx_slave = NULL; in tlb_init_table_entry()
83 entry->next = TLB_NULL_INDEX; in tlb_init_table_entry()
84 entry->prev = TLB_NULL_INDEX; in tlb_init_table_entry()
87 static inline void tlb_init_slave(struct slave *slave) in tlb_init_slave() argument
89 SLAVE_TLB_INFO(slave).load = 0; in tlb_init_slave()
90 SLAVE_TLB_INFO(slave).head = TLB_NULL_INDEX; in tlb_init_slave()
93 static void __tlb_clear_slave(struct bonding *bond, struct slave *slave, in __tlb_clear_slave() argument
99 /* clear slave from tx_hashtbl */ in __tlb_clear_slave()
104 index = SLAVE_TLB_INFO(slave).head; in __tlb_clear_slave()
112 tlb_init_slave(slave); in __tlb_clear_slave()
115 static void tlb_clear_slave(struct bonding *bond, struct slave *slave, in tlb_clear_slave() argument
118 spin_lock_bh(&bond->mode_lock); in tlb_clear_slave()
119 __tlb_clear_slave(bond, slave, save_load); in tlb_clear_slave()
120 spin_unlock_bh(&bond->mode_lock); in tlb_clear_slave()
133 return -ENOMEM; in tlb_initialize()
135 spin_lock_bh(&bond->mode_lock); in tlb_initialize()
137 bond_info->tx_hashtbl = new_hashtbl; in tlb_initialize()
140 tlb_init_table_entry(&bond_info->tx_hashtbl[i], 0); in tlb_initialize()
142 spin_unlock_bh(&bond->mode_lock); in tlb_initialize()
152 spin_lock_bh(&bond->mode_lock); in tlb_deinitialize()
154 kfree(bond_info->tx_hashtbl); in tlb_deinitialize()
155 bond_info->tx_hashtbl = NULL; in tlb_deinitialize()
157 spin_unlock_bh(&bond->mode_lock); in tlb_deinitialize()
160 static long long compute_gap(struct slave *slave) in compute_gap() argument
162 return (s64) (slave->speed << 20) - /* Convert to Megabit per sec */ in compute_gap()
163 (s64) (SLAVE_TLB_INFO(slave).load << 3); /* Bytes to bits */ in compute_gap()
166 static struct slave *tlb_get_least_loaded_slave(struct bonding *bond) in tlb_get_least_loaded_slave()
168 struct slave *slave, *least_loaded; in tlb_get_least_loaded_slave() local
175 /* Find the slave with the largest gap */ in tlb_get_least_loaded_slave()
176 bond_for_each_slave_rcu(bond, slave, iter) { in tlb_get_least_loaded_slave()
177 if (bond_slave_can_tx(slave)) { in tlb_get_least_loaded_slave()
178 long long gap = compute_gap(slave); in tlb_get_least_loaded_slave()
181 least_loaded = slave; in tlb_get_least_loaded_slave()
190 static struct slave *__tlb_choose_channel(struct bonding *bond, u32 hash_index, in __tlb_choose_channel()
195 struct slave *assigned_slave; in __tlb_choose_channel()
197 hash_table = bond_info->tx_hashtbl; in __tlb_choose_channel()
205 u32 next_index = slave_info->head; in __tlb_choose_channel()
214 slave_info->head = hash_index; in __tlb_choose_channel()
215 slave_info->load += in __tlb_choose_channel()
226 static struct slave *tlb_choose_channel(struct bonding *bond, u32 hash_index, in tlb_choose_channel()
229 struct slave *tx_slave; in tlb_choose_channel()
235 spin_lock(&bond->mode_lock); in tlb_choose_channel()
237 spin_unlock(&bond->mode_lock); in tlb_choose_channel()
253 spin_lock_bh(&bond->mode_lock); in rlb_update_entry_from_arp()
255 hash_index = _simple_hash((u8 *)&(arp->ip_src), sizeof(arp->ip_src)); in rlb_update_entry_from_arp()
256 client_info = &(bond_info->rx_hashtbl[hash_index]); in rlb_update_entry_from_arp()
258 if ((client_info->assigned) && in rlb_update_entry_from_arp()
259 (client_info->ip_src == arp->ip_dst) && in rlb_update_entry_from_arp()
260 (client_info->ip_dst == arp->ip_src) && in rlb_update_entry_from_arp()
261 (!ether_addr_equal_64bits(client_info->mac_dst, arp->mac_src))) { in rlb_update_entry_from_arp()
263 ether_addr_copy(client_info->mac_dst, arp->mac_src); in rlb_update_entry_from_arp()
264 client_info->ntt = 1; in rlb_update_entry_from_arp()
265 bond_info->rx_ntt = 1; in rlb_update_entry_from_arp()
268 spin_unlock_bh(&bond->mode_lock); in rlb_update_entry_from_arp()
272 struct slave *slave) in rlb_arp_recv() argument
276 if (skb->protocol != cpu_to_be16(ETH_P_ARP)) in rlb_arp_recv()
283 /* We received an ARP from arp->ip_src. in rlb_arp_recv()
286 * However, if arp->mac_src is different than what is stored in in rlb_arp_recv()
295 if (arp->op_code == htons(ARPOP_REPLY)) { in rlb_arp_recv()
298 slave_dbg(bond->dev, slave->dev, "Server received an ARP Reply from client\n"); in rlb_arp_recv()
305 static struct slave *__rlb_next_rx_slave(struct bonding *bond) in __rlb_next_rx_slave()
308 struct slave *before = NULL, *rx_slave = NULL, *slave; in __rlb_next_rx_slave() local
312 bond_for_each_slave_rcu(bond, slave, iter) { in __rlb_next_rx_slave()
313 if (!bond_slave_can_tx(slave)) in __rlb_next_rx_slave()
316 if (!before || before->speed < slave->speed) in __rlb_next_rx_slave()
317 before = slave; in __rlb_next_rx_slave()
319 if (!rx_slave || rx_slave->speed < slave->speed) in __rlb_next_rx_slave()
320 rx_slave = slave; in __rlb_next_rx_slave()
322 if (slave == bond_info->rx_slave) in __rlb_next_rx_slave()
326 * better before and up to the current slave in __rlb_next_rx_slave()
328 if (!rx_slave || (before && rx_slave->speed < before->speed)) in __rlb_next_rx_slave()
332 bond_info->rx_slave = rx_slave; in __rlb_next_rx_slave()
338 static struct slave *rlb_next_rx_slave(struct bonding *bond) in rlb_next_rx_slave()
340 struct slave *rx_slave; in rlb_next_rx_slave()
351 /* teach the switch the mac of a disabled slave
358 struct slave *curr_active = rtnl_dereference(bond->curr_active_slave); in rlb_teach_disabled_mac_on_primary()
363 if (!bond->alb_info.primary_is_promisc) { in rlb_teach_disabled_mac_on_primary()
364 if (!dev_set_promiscuity(curr_active->dev, 1)) in rlb_teach_disabled_mac_on_primary()
365 bond->alb_info.primary_is_promisc = 1; in rlb_teach_disabled_mac_on_primary()
367 bond->alb_info.primary_is_promisc = 0; in rlb_teach_disabled_mac_on_primary()
370 bond->alb_info.rlb_promisc_timeout_counter = 0; in rlb_teach_disabled_mac_on_primary()
375 /* slave being removed should not be active at this point
379 static void rlb_clear_slave(struct bonding *bond, struct slave *slave) in rlb_clear_slave() argument
385 /* clear slave from rx_hashtbl */ in rlb_clear_slave()
386 spin_lock_bh(&bond->mode_lock); in rlb_clear_slave()
388 rx_hash_table = bond_info->rx_hashtbl; in rlb_clear_slave()
389 index = bond_info->rx_hashtbl_used_head; in rlb_clear_slave()
392 if (rx_hash_table[index].slave == slave) { in rlb_clear_slave()
393 struct slave *assigned_slave = rlb_next_rx_slave(bond); in rlb_clear_slave()
396 rx_hash_table[index].slave = assigned_slave; in rlb_clear_slave()
398 bond_info->rx_hashtbl[index].ntt = 1; in rlb_clear_slave()
399 bond_info->rx_ntt = 1; in rlb_clear_slave()
400 /* A slave has been removed from the in rlb_clear_slave()
407 bond_info->rlb_update_retry_counter = in rlb_clear_slave()
410 } else { /* there is no active slave */ in rlb_clear_slave()
411 rx_hash_table[index].slave = NULL; in rlb_clear_slave()
416 spin_unlock_bh(&bond->mode_lock); in rlb_clear_slave()
418 if (slave != rtnl_dereference(bond->curr_active_slave)) in rlb_clear_slave()
419 rlb_teach_disabled_mac_on_primary(bond, slave->dev->dev_addr); in rlb_clear_slave()
426 if (!client_info->slave || !is_valid_ether_addr(client_info->mac_dst)) in rlb_update_client()
433 client_info->ip_dst, in rlb_update_client()
434 client_info->slave->dev, in rlb_update_client()
435 client_info->ip_src, in rlb_update_client()
436 client_info->mac_dst, in rlb_update_client()
437 client_info->slave->dev->dev_addr, in rlb_update_client()
438 client_info->mac_dst); in rlb_update_client()
440 slave_err(client_info->slave->bond->dev, in rlb_update_client()
441 client_info->slave->dev, in rlb_update_client()
446 skb->dev = client_info->slave->dev; in rlb_update_client()
448 if (client_info->vlan_id) { in rlb_update_client()
450 client_info->vlan_id); in rlb_update_client()
464 spin_lock_bh(&bond->mode_lock); in rlb_update_rx_clients()
466 hash_index = bond_info->rx_hashtbl_used_head; in rlb_update_rx_clients()
468 hash_index = client_info->used_next) { in rlb_update_rx_clients()
469 client_info = &(bond_info->rx_hashtbl[hash_index]); in rlb_update_rx_clients()
470 if (client_info->ntt) { in rlb_update_rx_clients()
472 if (bond_info->rlb_update_retry_counter == 0) in rlb_update_rx_clients()
473 client_info->ntt = 0; in rlb_update_rx_clients()
480 bond_info->rlb_update_delay_counter = RLB_UPDATE_DELAY; in rlb_update_rx_clients()
482 spin_unlock_bh(&bond->mode_lock); in rlb_update_rx_clients()
485 /* The slave was assigned a new mac address - update the clients */
486 static void rlb_req_update_slave_clients(struct bonding *bond, struct slave *slave) in rlb_req_update_slave_clients() argument
493 spin_lock_bh(&bond->mode_lock); in rlb_req_update_slave_clients()
495 hash_index = bond_info->rx_hashtbl_used_head; in rlb_req_update_slave_clients()
497 hash_index = client_info->used_next) { in rlb_req_update_slave_clients()
498 client_info = &(bond_info->rx_hashtbl[hash_index]); in rlb_req_update_slave_clients()
500 if ((client_info->slave == slave) && in rlb_req_update_slave_clients()
501 is_valid_ether_addr(client_info->mac_dst)) { in rlb_req_update_slave_clients()
502 client_info->ntt = 1; in rlb_req_update_slave_clients()
509 bond_info->rx_ntt = 1; in rlb_req_update_slave_clients()
511 bond_info->rlb_update_retry_counter = RLB_UPDATE_RETRY; in rlb_req_update_slave_clients()
514 spin_unlock_bh(&bond->mode_lock); in rlb_req_update_slave_clients()
524 spin_lock(&bond->mode_lock); in rlb_req_update_subnet_clients()
526 hash_index = bond_info->rx_hashtbl_used_head; in rlb_req_update_subnet_clients()
528 hash_index = client_info->used_next) { in rlb_req_update_subnet_clients()
529 client_info = &(bond_info->rx_hashtbl[hash_index]); in rlb_req_update_subnet_clients()
531 if (!client_info->slave) { in rlb_req_update_subnet_clients()
532 netdev_err(bond->dev, "found a client with no channel in the client's hash table\n"); in rlb_req_update_subnet_clients()
539 if ((client_info->ip_src == src_ip) && in rlb_req_update_subnet_clients()
540 !ether_addr_equal_64bits(client_info->slave->dev->dev_addr, in rlb_req_update_subnet_clients()
541 bond->dev->dev_addr) && in rlb_req_update_subnet_clients()
542 is_valid_ether_addr(client_info->mac_dst)) { in rlb_req_update_subnet_clients()
543 client_info->ntt = 1; in rlb_req_update_subnet_clients()
544 bond_info->rx_ntt = 1; in rlb_req_update_subnet_clients()
548 spin_unlock(&bond->mode_lock); in rlb_req_update_subnet_clients()
551 static struct slave *rlb_choose_channel(struct sk_buff *skb, in rlb_choose_channel()
556 struct slave *assigned_slave, *curr_active_slave; in rlb_choose_channel()
560 spin_lock(&bond->mode_lock); in rlb_choose_channel()
562 curr_active_slave = rcu_dereference(bond->curr_active_slave); in rlb_choose_channel()
564 hash_index = _simple_hash((u8 *)&arp->ip_dst, sizeof(arp->ip_dst)); in rlb_choose_channel()
565 client_info = &(bond_info->rx_hashtbl[hash_index]); in rlb_choose_channel()
567 if (client_info->assigned) { in rlb_choose_channel()
568 if ((client_info->ip_src == arp->ip_src) && in rlb_choose_channel()
569 (client_info->ip_dst == arp->ip_dst)) { in rlb_choose_channel()
571 if (!is_broadcast_ether_addr(arp->mac_dst)) { in rlb_choose_channel()
573 ether_addr_copy(client_info->mac_dst, arp->mac_dst); in rlb_choose_channel()
575 ether_addr_copy(client_info->mac_src, arp->mac_src); in rlb_choose_channel()
577 assigned_slave = client_info->slave; in rlb_choose_channel()
579 spin_unlock(&bond->mode_lock); in rlb_choose_channel()
588 client_info->slave != curr_active_slave) { in rlb_choose_channel()
589 client_info->slave = curr_active_slave; in rlb_choose_channel()
594 /* assign a new slave */ in rlb_choose_channel()
598 if (!(client_info->assigned && in rlb_choose_channel()
599 client_info->ip_src == arp->ip_src)) { in rlb_choose_channel()
603 u32 hash_src = _simple_hash((u8 *)&arp->ip_src, in rlb_choose_channel()
604 sizeof(arp->ip_src)); in rlb_choose_channel()
609 client_info->ip_src = arp->ip_src; in rlb_choose_channel()
610 client_info->ip_dst = arp->ip_dst; in rlb_choose_channel()
611 /* arp->mac_dst is broadcast for arp reqeusts. in rlb_choose_channel()
615 ether_addr_copy(client_info->mac_dst, arp->mac_dst); in rlb_choose_channel()
616 ether_addr_copy(client_info->mac_src, arp->mac_src); in rlb_choose_channel()
617 client_info->slave = assigned_slave; in rlb_choose_channel()
619 if (is_valid_ether_addr(client_info->mac_dst)) { in rlb_choose_channel()
620 client_info->ntt = 1; in rlb_choose_channel()
621 bond->alb_info.rx_ntt = 1; in rlb_choose_channel()
623 client_info->ntt = 0; in rlb_choose_channel()
626 if (vlan_get_tag(skb, &client_info->vlan_id)) in rlb_choose_channel()
627 client_info->vlan_id = 0; in rlb_choose_channel()
629 if (!client_info->assigned) { in rlb_choose_channel()
630 u32 prev_tbl_head = bond_info->rx_hashtbl_used_head; in rlb_choose_channel()
631 bond_info->rx_hashtbl_used_head = hash_index; in rlb_choose_channel()
632 client_info->used_next = prev_tbl_head; in rlb_choose_channel()
634 bond_info->rx_hashtbl[prev_tbl_head].used_prev = in rlb_choose_channel()
637 client_info->assigned = 1; in rlb_choose_channel()
641 spin_unlock(&bond->mode_lock); in rlb_choose_channel()
650 static struct slave *rlb_arp_xmit(struct sk_buff *skb, struct bonding *bond) in rlb_arp_xmit()
652 struct slave *tx_slave = NULL; in rlb_arp_xmit()
662 if (!bond_slave_has_mac_rcu(bond, arp->mac_src)) in rlb_arp_xmit()
665 if (arp->op_code == htons(ARPOP_REPLY)) { in rlb_arp_xmit()
669 bond_hw_addr_copy(arp->mac_src, tx_slave->dev->dev_addr, in rlb_arp_xmit()
670 tx_slave->dev->addr_len); in rlb_arp_xmit()
671 netdev_dbg(bond->dev, "(slave %s): Server sent ARP Reply packet\n", in rlb_arp_xmit()
672 tx_slave ? tx_slave->dev->name : "NULL"); in rlb_arp_xmit()
673 } else if (arp->op_code == htons(ARPOP_REQUEST)) { in rlb_arp_xmit()
684 bond->alb_info.rlb_update_delay_counter = RLB_UPDATE_DELAY; in rlb_arp_xmit()
688 * the primary slave. We must register these clients to be in rlb_arp_xmit()
691 rlb_req_update_subnet_clients(bond, arp->ip_src); in rlb_arp_xmit()
692 netdev_dbg(bond->dev, "(slave %s): Server sent ARP Request packet\n", in rlb_arp_xmit()
693 tx_slave ? tx_slave->dev->name : "NULL"); in rlb_arp_xmit()
702 struct slave *assigned_slave; in rlb_rebalance()
707 spin_lock_bh(&bond->mode_lock); in rlb_rebalance()
710 hash_index = bond_info->rx_hashtbl_used_head; in rlb_rebalance()
712 hash_index = client_info->used_next) { in rlb_rebalance()
713 client_info = &(bond_info->rx_hashtbl[hash_index]); in rlb_rebalance()
715 if (assigned_slave && (client_info->slave != assigned_slave)) { in rlb_rebalance()
716 client_info->slave = assigned_slave; in rlb_rebalance()
717 if (!is_zero_ether_addr(client_info->mac_dst)) { in rlb_rebalance()
718 client_info->ntt = 1; in rlb_rebalance()
726 bond_info->rx_ntt = 1; in rlb_rebalance()
727 spin_unlock_bh(&bond->mode_lock); in rlb_rebalance()
733 entry->used_next = RLB_NULL_INDEX; in rlb_init_table_entry_dst()
734 entry->used_prev = RLB_NULL_INDEX; in rlb_init_table_entry_dst()
735 entry->assigned = 0; in rlb_init_table_entry_dst()
736 entry->slave = NULL; in rlb_init_table_entry_dst()
737 entry->vlan_id = 0; in rlb_init_table_entry_dst()
741 entry->src_first = RLB_NULL_INDEX; in rlb_init_table_entry_src()
742 entry->src_prev = RLB_NULL_INDEX; in rlb_init_table_entry_src()
743 entry->src_next = RLB_NULL_INDEX; in rlb_init_table_entry_src()
756 u32 next_index = bond_info->rx_hashtbl[index].used_next; in rlb_delete_table_entry_dst()
757 u32 prev_index = bond_info->rx_hashtbl[index].used_prev; in rlb_delete_table_entry_dst()
759 if (index == bond_info->rx_hashtbl_used_head) in rlb_delete_table_entry_dst()
760 bond_info->rx_hashtbl_used_head = next_index; in rlb_delete_table_entry_dst()
762 bond_info->rx_hashtbl[prev_index].used_next = next_index; in rlb_delete_table_entry_dst()
764 bond_info->rx_hashtbl[next_index].used_prev = prev_index; in rlb_delete_table_entry_dst()
771 u32 next_index = bond_info->rx_hashtbl[index].src_next; in rlb_src_unlink()
772 u32 prev_index = bond_info->rx_hashtbl[index].src_prev; in rlb_src_unlink()
774 bond_info->rx_hashtbl[index].src_next = RLB_NULL_INDEX; in rlb_src_unlink()
775 bond_info->rx_hashtbl[index].src_prev = RLB_NULL_INDEX; in rlb_src_unlink()
778 bond_info->rx_hashtbl[next_index].src_prev = prev_index; in rlb_src_unlink()
784 if (bond_info->rx_hashtbl[prev_index].src_first == index) in rlb_src_unlink()
785 bond_info->rx_hashtbl[prev_index].src_first = next_index; in rlb_src_unlink()
787 bond_info->rx_hashtbl[prev_index].src_next = next_index; in rlb_src_unlink()
794 struct rlb_client_info *entry = &(bond_info->rx_hashtbl[index]); in rlb_delete_table_entry()
810 bond_info->rx_hashtbl[ip_dst_hash].src_prev = ip_src_hash; in rlb_src_link()
811 next = bond_info->rx_hashtbl[ip_src_hash].src_first; in rlb_src_link()
812 bond_info->rx_hashtbl[ip_dst_hash].src_next = next; in rlb_src_link()
814 bond_info->rx_hashtbl[next].src_prev = ip_dst_hash; in rlb_src_link()
815 bond_info->rx_hashtbl[ip_src_hash].src_first = ip_dst_hash; in rlb_src_link()
818 /* deletes all rx_hashtbl entries with arp->ip_src if their mac_src does
819 * not match arp->mac_src
824 u32 ip_src_hash = _simple_hash((u8 *)&(arp->ip_src), sizeof(arp->ip_src)); in rlb_purge_src_ip()
827 spin_lock_bh(&bond->mode_lock); in rlb_purge_src_ip()
829 index = bond_info->rx_hashtbl[ip_src_hash].src_first; in rlb_purge_src_ip()
831 struct rlb_client_info *entry = &(bond_info->rx_hashtbl[index]); in rlb_purge_src_ip()
832 u32 next_index = entry->src_next; in rlb_purge_src_ip()
833 if (entry->ip_src == arp->ip_src && in rlb_purge_src_ip()
834 !ether_addr_equal_64bits(arp->mac_src, entry->mac_src)) in rlb_purge_src_ip()
838 spin_unlock_bh(&bond->mode_lock); in rlb_purge_src_ip()
850 return -1; in rlb_initialize()
852 spin_lock_bh(&bond->mode_lock); in rlb_initialize()
854 bond_info->rx_hashtbl = new_hashtbl; in rlb_initialize()
856 bond_info->rx_hashtbl_used_head = RLB_NULL_INDEX; in rlb_initialize()
859 rlb_init_table_entry(bond_info->rx_hashtbl + i); in rlb_initialize()
861 spin_unlock_bh(&bond->mode_lock); in rlb_initialize()
864 bond->recv_probe = rlb_arp_recv; in rlb_initialize()
873 spin_lock_bh(&bond->mode_lock); in rlb_deinitialize()
875 kfree(bond_info->rx_hashtbl); in rlb_deinitialize()
876 bond_info->rx_hashtbl = NULL; in rlb_deinitialize()
877 bond_info->rx_hashtbl_used_head = RLB_NULL_INDEX; in rlb_deinitialize()
879 spin_unlock_bh(&bond->mode_lock); in rlb_deinitialize()
887 spin_lock_bh(&bond->mode_lock); in rlb_clear_vlan()
889 curr_index = bond_info->rx_hashtbl_used_head; in rlb_clear_vlan()
891 struct rlb_client_info *curr = &(bond_info->rx_hashtbl[curr_index]); in rlb_clear_vlan()
892 u32 next_index = bond_info->rx_hashtbl[curr_index].used_next; in rlb_clear_vlan()
894 if (curr->vlan_id == vlan_id) in rlb_clear_vlan()
900 spin_unlock_bh(&bond->mode_lock); in rlb_clear_vlan()
905 static void alb_send_lp_vid(struct slave *slave, u8 mac_addr[], in alb_send_lp_vid() argument
924 skb->network_header = skb->mac_header + ETH_HLEN; in alb_send_lp_vid()
925 skb->protocol = pkt.type; in alb_send_lp_vid()
926 skb->priority = TC_PRIO_CONTROL; in alb_send_lp_vid()
927 skb->dev = slave->dev; in alb_send_lp_vid()
929 slave_dbg(slave->bond->dev, slave->dev, in alb_send_lp_vid()
940 struct slave *slave; member
948 struct alb_walk_data *data = (struct alb_walk_data *)priv->data; in alb_upper_dev_walk()
949 bool strict_match = data->strict_match; in alb_upper_dev_walk()
950 struct bonding *bond = data->bond; in alb_upper_dev_walk()
951 struct slave *slave = data->slave; in alb_upper_dev_walk() local
952 u8 *mac_addr = data->mac_addr; in alb_upper_dev_walk()
956 bond->dev->lower_level == upper->lower_level - 1) { in alb_upper_dev_walk()
957 if (upper->addr_assign_type == NET_ADDR_STOLEN) { in alb_upper_dev_walk()
958 alb_send_lp_vid(slave, mac_addr, in alb_upper_dev_walk()
962 alb_send_lp_vid(slave, upper->dev_addr, in alb_upper_dev_walk()
972 tags = bond_verify_device_path(bond->dev, upper, 0); in alb_upper_dev_walk()
974 return -ENOMEM; in alb_upper_dev_walk()
976 alb_send_lp_vid(slave, upper->dev_addr, in alb_upper_dev_walk()
984 static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[], in alb_send_learning_packets() argument
987 struct bonding *bond = bond_get_bond_by_slave(slave); in alb_send_learning_packets()
992 .slave = slave, in alb_send_learning_packets()
998 alb_send_lp_vid(slave, mac_addr, 0, 0); in alb_send_learning_packets()
1004 netdev_walk_all_upper_dev_rcu(bond->dev, alb_upper_dev_walk, &priv); in alb_send_learning_packets()
1008 static int alb_set_slave_mac_addr(struct slave *slave, u8 addr[], in alb_set_slave_mac_addr() argument
1011 struct net_device *dev = slave->dev; in alb_set_slave_mac_addr() local
1014 if (BOND_MODE(slave->bond) == BOND_MODE_TLB) { in alb_set_slave_mac_addr()
1015 memcpy(dev->dev_addr, addr, len); in alb_set_slave_mac_addr()
1019 /* for rlb each slave must have a unique hw mac addresses so that in alb_set_slave_mac_addr()
1020 * each slave will receive packets destined to a different mac in alb_set_slave_mac_addr()
1023 ss.ss_family = dev->type; in alb_set_slave_mac_addr()
1024 if (dev_set_mac_address(dev, (struct sockaddr *)&ss, NULL)) { in alb_set_slave_mac_addr()
1025 …slave_err(slave->bond->dev, dev, "dev_set_mac_address on slave failed! ALB mode requires that the … in alb_set_slave_mac_addr()
1026 return -EOPNOTSUPP; in alb_set_slave_mac_addr()
1035 static void alb_swap_mac_addr(struct slave *slave1, struct slave *slave2) in alb_swap_mac_addr()
1039 bond_hw_addr_copy(tmp_mac_addr, slave1->dev->dev_addr, in alb_swap_mac_addr()
1040 slave1->dev->addr_len); in alb_swap_mac_addr()
1041 alb_set_slave_mac_addr(slave1, slave2->dev->dev_addr, in alb_swap_mac_addr()
1042 slave2->dev->addr_len); in alb_swap_mac_addr()
1044 slave1->dev->addr_len); in alb_swap_mac_addr()
1052 static void alb_fasten_mac_swap(struct bonding *bond, struct slave *slave1, in alb_fasten_mac_swap()
1053 struct slave *slave2) in alb_fasten_mac_swap()
1056 struct slave *disabled_slave = NULL; in alb_fasten_mac_swap()
1062 alb_send_learning_packets(slave1, slave1->dev->dev_addr, false); in alb_fasten_mac_swap()
1063 if (bond->alb_info.rlb_enabled) { in alb_fasten_mac_swap()
1074 alb_send_learning_packets(slave2, slave2->dev->dev_addr, false); in alb_fasten_mac_swap()
1075 if (bond->alb_info.rlb_enabled) { in alb_fasten_mac_swap()
1085 if (bond->alb_info.rlb_enabled && slaves_state_differ) { in alb_fasten_mac_swap()
1086 /* A disabled slave was assigned an active mac addr */ in alb_fasten_mac_swap()
1088 disabled_slave->dev->dev_addr); in alb_fasten_mac_swap()
1095 * @slave: the slave that was just detached
1097 * We assume that @slave was already detached from the slave list.
1099 * If @slave's permanent hw address is different both from its current
1101 * a slave that has @slave's permanet address as its current address.
1102 * We'll make sure that that slave no longer uses @slave's permanent address.
1106 static void alb_change_hw_addr_on_detach(struct bonding *bond, struct slave *slave) in alb_change_hw_addr_on_detach() argument
1110 struct slave *found_slave; in alb_change_hw_addr_on_detach()
1112 perm_curr_diff = !ether_addr_equal_64bits(slave->perm_hwaddr, in alb_change_hw_addr_on_detach()
1113 slave->dev->dev_addr); in alb_change_hw_addr_on_detach()
1114 perm_bond_diff = !ether_addr_equal_64bits(slave->perm_hwaddr, in alb_change_hw_addr_on_detach()
1115 bond->dev->dev_addr); in alb_change_hw_addr_on_detach()
1118 found_slave = bond_slave_has_mac(bond, slave->perm_hwaddr); in alb_change_hw_addr_on_detach()
1121 alb_swap_mac_addr(slave, found_slave); in alb_change_hw_addr_on_detach()
1122 alb_fasten_mac_swap(bond, slave, found_slave); in alb_change_hw_addr_on_detach()
1130 * @slave: the slave that was just attached
1132 * checks uniqueness of slave's mac address and handles the case the
1133 * new slave uses the bonds mac address.
1135 * If the permanent hw address of @slave is @bond's hw address, we need to
1136 * find a different hw address to give @slave, that isn't in use by any other
1137 * slave in the bond. This address must be, of course, one of the permanent
1140 * We go over the slave list, and for each slave there we compare its
1142 * If no match was found, then we've found a slave with a permanent address
1143 * that isn't used by any other slave in the bond, so we can assign it to
1144 * @slave.
1146 * assumption: this function is called before @slave is attached to the
1147 * bond slave list.
1149 static int alb_handle_addr_collision_on_attach(struct bonding *bond, struct slave *slave) in alb_handle_addr_collision_on_attach() argument
1151 struct slave *has_bond_addr = rcu_access_pointer(bond->curr_active_slave); in alb_handle_addr_collision_on_attach()
1152 struct slave *tmp_slave1, *free_mac_slave = NULL; in alb_handle_addr_collision_on_attach()
1156 /* this is the first slave */ in alb_handle_addr_collision_on_attach()
1160 /* if slave's mac address differs from bond's mac address in alb_handle_addr_collision_on_attach()
1161 * check uniqueness of slave's mac address against the other in alb_handle_addr_collision_on_attach()
1164 if (!ether_addr_equal_64bits(slave->perm_hwaddr, bond->dev->dev_addr)) { in alb_handle_addr_collision_on_attach()
1165 if (!bond_slave_has_mac(bond, slave->dev->dev_addr)) in alb_handle_addr_collision_on_attach()
1168 /* Try setting slave mac to bond address and fall-through in alb_handle_addr_collision_on_attach()
1171 alb_set_slave_mac_addr(slave, bond->dev->dev_addr, in alb_handle_addr_collision_on_attach()
1172 bond->dev->addr_len); in alb_handle_addr_collision_on_attach()
1175 /* The slave's address is equal to the address of the bond. in alb_handle_addr_collision_on_attach()
1176 * Search for a spare address in the bond for this slave. in alb_handle_addr_collision_on_attach()
1179 if (!bond_slave_has_mac(bond, tmp_slave1->perm_hwaddr)) { in alb_handle_addr_collision_on_attach()
1180 /* no slave has tmp_slave1's perm addr in alb_handle_addr_collision_on_attach()
1188 if (ether_addr_equal_64bits(tmp_slave1->dev->dev_addr, in alb_handle_addr_collision_on_attach()
1189 bond->dev->dev_addr)) { in alb_handle_addr_collision_on_attach()
1197 alb_set_slave_mac_addr(slave, free_mac_slave->perm_hwaddr, in alb_handle_addr_collision_on_attach()
1198 free_mac_slave->dev->addr_len); in alb_handle_addr_collision_on_attach()
1200 …slave_warn(bond->dev, slave->dev, "the slave hw address is in use by the bond; giving it the hw ad… in alb_handle_addr_collision_on_attach()
1201 free_mac_slave->dev->name); in alb_handle_addr_collision_on_attach()
1204 …slave_err(bond->dev, slave->dev, "the slave hw address is in use by the bond; couldn't find a slav… in alb_handle_addr_collision_on_attach()
1205 return -EFAULT; in alb_handle_addr_collision_on_attach()
1220 * For each slave, this function sets the interface to the new address and then
1227 struct slave *slave, *rollback_slave; in alb_set_mac_address() local
1233 if (bond->alb_info.rlb_enabled) in alb_set_mac_address()
1236 bond_for_each_slave(bond, slave, iter) { in alb_set_mac_address()
1238 bond_hw_addr_copy(tmp_addr, slave->dev->dev_addr, in alb_set_mac_address()
1239 slave->dev->addr_len); in alb_set_mac_address()
1241 res = dev_set_mac_address(slave->dev, addr, NULL); in alb_set_mac_address()
1244 bond_hw_addr_copy(slave->dev->dev_addr, tmp_addr, in alb_set_mac_address()
1245 slave->dev->addr_len); in alb_set_mac_address()
1254 memcpy(ss.__data, bond->dev->dev_addr, bond->dev->addr_len); in alb_set_mac_address()
1255 ss.ss_family = bond->dev->type; in alb_set_mac_address()
1257 /* unwind from head to the slave that failed */ in alb_set_mac_address()
1259 if (rollback_slave == slave) in alb_set_mac_address()
1261 bond_hw_addr_copy(tmp_addr, rollback_slave->dev->dev_addr, in alb_set_mac_address()
1262 rollback_slave->dev->addr_len); in alb_set_mac_address()
1263 dev_set_mac_address(rollback_slave->dev, in alb_set_mac_address()
1265 bond_hw_addr_copy(rollback_slave->dev->dev_addr, tmp_addr, in alb_set_mac_address()
1266 rollback_slave->dev->addr_len); in alb_set_mac_address()
1288 bond->alb_info.rlb_enabled = 1; in bond_alb_initialize()
1290 bond->alb_info.rlb_enabled = 0; in bond_alb_initialize()
1302 if (bond_info->rlb_enabled) in bond_alb_deinitialize()
1307 struct slave *tx_slave) in bond_do_alb_xmit()
1314 tx_slave = rcu_dereference(bond->curr_active_slave); in bond_do_alb_xmit()
1315 if (bond->params.tlb_dynamic_lb) in bond_do_alb_xmit()
1316 bond_info->unbalanced_load += skb->len; in bond_do_alb_xmit()
1320 if (tx_slave != rcu_access_pointer(bond->curr_active_slave)) { in bond_do_alb_xmit()
1321 ether_addr_copy(eth_data->h_source, in bond_do_alb_xmit()
1322 tx_slave->dev->dev_addr); in bond_do_alb_xmit()
1325 return bond_dev_queue_xmit(bond, skb, tx_slave->dev); in bond_do_alb_xmit()
1328 if (tx_slave && bond->params.tlb_dynamic_lb) { in bond_do_alb_xmit()
1329 spin_lock(&bond->mode_lock); in bond_do_alb_xmit()
1331 spin_unlock(&bond->mode_lock); in bond_do_alb_xmit()
1335 return bond_tx_drop(bond->dev, skb); in bond_do_alb_xmit()
1338 struct slave *bond_xmit_tlb_slave_get(struct bonding *bond, in bond_xmit_tlb_slave_get()
1341 struct slave *tx_slave = NULL; in bond_xmit_tlb_slave_get()
1349 if (!is_multicast_ether_addr(eth_data->h_dest)) { in bond_xmit_tlb_slave_get()
1350 switch (skb->protocol) { in bond_xmit_tlb_slave_get()
1356 if (bond->params.tlb_dynamic_lb) { in bond_xmit_tlb_slave_get()
1359 skb->len); in bond_xmit_tlb_slave_get()
1364 slaves = rcu_dereference(bond->usable_slaves); in bond_xmit_tlb_slave_get()
1365 count = slaves ? READ_ONCE(slaves->count) : 0; in bond_xmit_tlb_slave_get()
1367 tx_slave = slaves->arr[hash_index % in bond_xmit_tlb_slave_get()
1379 struct slave *tx_slave; in bond_tlb_xmit()
1385 struct slave *bond_xmit_alb_slave_get(struct bonding *bond, in bond_xmit_alb_slave_get()
1390 struct slave *tx_slave = NULL; in bond_xmit_alb_slave_get()
1400 switch (ntohs(skb->protocol)) { in bond_xmit_alb_slave_get()
1404 if (is_broadcast_ether_addr(eth_data->h_dest) || in bond_xmit_alb_slave_get()
1410 if (iph->daddr == ip_bcast || iph->protocol == IPPROTO_IGMP) { in bond_xmit_alb_slave_get()
1414 hash_start = (char *)&(iph->daddr); in bond_xmit_alb_slave_get()
1415 hash_size = sizeof(iph->daddr); in bond_xmit_alb_slave_get()
1424 if (is_broadcast_ether_addr(eth_data->h_dest)) { in bond_xmit_alb_slave_get()
1429 /* IPv6 uses all-nodes multicast as an equivalent to in bond_xmit_alb_slave_get()
1432 if (ether_addr_equal_64bits(eth_data->h_dest, mac_v6_allmcast)) { in bond_xmit_alb_slave_get()
1441 /* Additionally, DAD probes should not be tx-balanced as that in bond_xmit_alb_slave_get()
1446 if (ipv6_addr_any(&ip6hdr->saddr)) { in bond_xmit_alb_slave_get()
1451 hash_start = (char *)&ip6hdr->daddr; in bond_xmit_alb_slave_get()
1452 hash_size = sizeof(ip6hdr->daddr); in bond_xmit_alb_slave_get()
1464 if (ipxhdr->ipx_checksum != IPX_NO_CHECKSUM) { in bond_xmit_alb_slave_get()
1470 if (ipxhdr->ipx_type != IPX_TYPE_NCP) { in bond_xmit_alb_slave_get()
1480 hash_start = (char *)eth_data->h_dest; in bond_xmit_alb_slave_get()
1486 if (bond_info->rlb_enabled) in bond_xmit_alb_slave_get()
1495 if (bond->params.tlb_dynamic_lb) { in bond_xmit_alb_slave_get()
1497 tx_slave = tlb_choose_channel(bond, hash_index, skb->len); in bond_xmit_alb_slave_get()
1507 slaves = rcu_dereference(bond->usable_slaves); in bond_xmit_alb_slave_get()
1508 count = slaves ? READ_ONCE(slaves->count) : 0; in bond_xmit_alb_slave_get()
1510 tx_slave = slaves->arr[bond_xmit_hash(bond, skb) % in bond_xmit_alb_slave_get()
1520 struct slave *tx_slave = NULL; in bond_alb_xmit()
1532 struct slave *slave; in bond_alb_monitor() local
1535 atomic_set(&bond_info->tx_rebalance_counter, 0); in bond_alb_monitor()
1536 bond_info->lp_counter = 0; in bond_alb_monitor()
1542 atomic_inc(&bond_info->tx_rebalance_counter); in bond_alb_monitor()
1543 bond_info->lp_counter++; in bond_alb_monitor()
1546 if (bond_info->lp_counter >= BOND_ALB_LP_TICKS(bond)) { in bond_alb_monitor()
1549 bond_for_each_slave_rcu(bond, slave, iter) { in bond_alb_monitor()
1552 * use mac of the slave device. in bond_alb_monitor()
1555 strict_match = (slave != rcu_access_pointer(bond->curr_active_slave) || in bond_alb_monitor()
1556 bond_info->rlb_enabled); in bond_alb_monitor()
1557 alb_send_learning_packets(slave, slave->dev->dev_addr, in bond_alb_monitor()
1560 bond_info->lp_counter = 0; in bond_alb_monitor()
1564 if (atomic_read(&bond_info->tx_rebalance_counter) >= BOND_TLB_REBALANCE_TICKS) { in bond_alb_monitor()
1565 bond_for_each_slave_rcu(bond, slave, iter) { in bond_alb_monitor()
1566 tlb_clear_slave(bond, slave, 1); in bond_alb_monitor()
1567 if (slave == rcu_access_pointer(bond->curr_active_slave)) { in bond_alb_monitor()
1568 SLAVE_TLB_INFO(slave).load = in bond_alb_monitor()
1569 bond_info->unbalanced_load / in bond_alb_monitor()
1571 bond_info->unbalanced_load = 0; in bond_alb_monitor()
1574 atomic_set(&bond_info->tx_rebalance_counter, 0); in bond_alb_monitor()
1577 if (bond_info->rlb_enabled) { in bond_alb_monitor()
1578 if (bond_info->primary_is_promisc && in bond_alb_monitor()
1579 (++bond_info->rlb_promisc_timeout_counter >= RLB_PROMISC_TIMEOUT)) { in bond_alb_monitor()
1588 bond_info->rlb_promisc_timeout_counter = 0; in bond_alb_monitor()
1591 * because a slave was disabled then in bond_alb_monitor()
1594 dev_set_promiscuity(rtnl_dereference(bond->curr_active_slave)->dev, in bond_alb_monitor()
1595 -1); in bond_alb_monitor()
1596 bond_info->primary_is_promisc = 0; in bond_alb_monitor()
1602 if (bond_info->rlb_rebalance) { in bond_alb_monitor()
1603 bond_info->rlb_rebalance = 0; in bond_alb_monitor()
1608 if (bond_info->rx_ntt) { in bond_alb_monitor()
1609 if (bond_info->rlb_update_delay_counter) { in bond_alb_monitor()
1610 --bond_info->rlb_update_delay_counter; in bond_alb_monitor()
1613 if (bond_info->rlb_update_retry_counter) in bond_alb_monitor()
1614 --bond_info->rlb_update_retry_counter; in bond_alb_monitor()
1616 bond_info->rx_ntt = 0; in bond_alb_monitor()
1622 queue_delayed_work(bond->wq, &bond->alb_work, alb_delta_in_ticks); in bond_alb_monitor()
1625 /* assumption: called before the slave is attached to the bond
1628 int bond_alb_init_slave(struct bonding *bond, struct slave *slave) in bond_alb_init_slave() argument
1632 res = alb_set_slave_mac_addr(slave, slave->perm_hwaddr, in bond_alb_init_slave()
1633 slave->dev->addr_len); in bond_alb_init_slave()
1637 res = alb_handle_addr_collision_on_attach(bond, slave); in bond_alb_init_slave()
1641 tlb_init_slave(slave); in bond_alb_init_slave()
1644 atomic_set(&bond->alb_info.tx_rebalance_counter, in bond_alb_init_slave()
1647 if (bond->alb_info.rlb_enabled) in bond_alb_init_slave()
1648 bond->alb_info.rlb_rebalance = 1; in bond_alb_init_slave()
1653 /* Remove slave from tlb and rlb hash tables, and fix up MAC addresses
1658 void bond_alb_deinit_slave(struct bonding *bond, struct slave *slave) in bond_alb_deinit_slave() argument
1661 alb_change_hw_addr_on_detach(bond, slave); in bond_alb_deinit_slave()
1663 tlb_clear_slave(bond, slave, 0); in bond_alb_deinit_slave()
1665 if (bond->alb_info.rlb_enabled) { in bond_alb_deinit_slave()
1666 bond->alb_info.rx_slave = NULL; in bond_alb_deinit_slave()
1667 rlb_clear_slave(bond, slave); in bond_alb_deinit_slave()
1672 void bond_alb_handle_link_change(struct bonding *bond, struct slave *slave, char link) in bond_alb_handle_link_change() argument
1677 tlb_clear_slave(bond, slave, 0); in bond_alb_handle_link_change()
1678 if (bond->alb_info.rlb_enabled) in bond_alb_handle_link_change()
1679 rlb_clear_slave(bond, slave); in bond_alb_handle_link_change()
1682 atomic_set(&bond_info->tx_rebalance_counter, in bond_alb_handle_link_change()
1684 if (bond->alb_info.rlb_enabled) { in bond_alb_handle_link_change()
1685 bond->alb_info.rlb_rebalance = 1; in bond_alb_handle_link_change()
1696 pr_err("Failed to build slave-array for TLB mode.\n"); in bond_alb_handle_link_change()
1701 * bond_alb_handle_active_change - assign new curr_active_slave
1703 * @new_slave: new slave to assign
1705 * Set the bond->curr_active_slave to @new_slave and handle
1710 void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave) in bond_alb_handle_active_change()
1712 struct slave *swap_slave; in bond_alb_handle_active_change()
1713 struct slave *curr_active; in bond_alb_handle_active_change()
1715 curr_active = rtnl_dereference(bond->curr_active_slave); in bond_alb_handle_active_change()
1719 if (curr_active && bond->alb_info.primary_is_promisc) { in bond_alb_handle_active_change()
1720 dev_set_promiscuity(curr_active->dev, -1); in bond_alb_handle_active_change()
1721 bond->alb_info.primary_is_promisc = 0; in bond_alb_handle_active_change()
1722 bond->alb_info.rlb_promisc_timeout_counter = 0; in bond_alb_handle_active_change()
1726 rcu_assign_pointer(bond->curr_active_slave, new_slave); in bond_alb_handle_active_change()
1735 swap_slave = bond_slave_has_mac(bond, bond->dev->dev_addr); in bond_alb_handle_active_change()
1745 /* in TLB mode, the slave might flip down/up with the old dev_addr, in bond_alb_handle_active_change()
1746 * and thus filter bond->dev_addr's packets, so force bond's mac in bond_alb_handle_active_change()
1752 bond_hw_addr_copy(tmp_addr, new_slave->dev->dev_addr, in bond_alb_handle_active_change()
1753 new_slave->dev->addr_len); in bond_alb_handle_active_change()
1755 bond_hw_addr_copy(ss.__data, bond->dev->dev_addr, in bond_alb_handle_active_change()
1756 bond->dev->addr_len); in bond_alb_handle_active_change()
1757 ss.ss_family = bond->dev->type; in bond_alb_handle_active_change()
1759 dev_set_mac_address(new_slave->dev, (struct sockaddr *)&ss, in bond_alb_handle_active_change()
1762 bond_hw_addr_copy(new_slave->dev->dev_addr, tmp_addr, in bond_alb_handle_active_change()
1763 new_slave->dev->addr_len); in bond_alb_handle_active_change()
1773 alb_set_slave_mac_addr(new_slave, bond->dev->dev_addr, in bond_alb_handle_active_change()
1774 bond->dev->addr_len); in bond_alb_handle_active_change()
1775 alb_send_learning_packets(new_slave, bond->dev->dev_addr, in bond_alb_handle_active_change()
1785 struct slave *curr_active; in bond_alb_set_mac_address()
1786 struct slave *swap_slave; in bond_alb_set_mac_address()
1789 if (!is_valid_ether_addr(ss->__data)) in bond_alb_set_mac_address()
1790 return -EADDRNOTAVAIL; in bond_alb_set_mac_address()
1796 bond_hw_addr_copy(bond_dev->dev_addr, ss->__data, bond_dev->addr_len); in bond_alb_set_mac_address()
1802 curr_active = rtnl_dereference(bond->curr_active_slave); in bond_alb_set_mac_address()
1806 swap_slave = bond_slave_has_mac(bond, bond_dev->dev_addr); in bond_alb_set_mac_address()
1812 alb_set_slave_mac_addr(curr_active, bond_dev->dev_addr, in bond_alb_set_mac_address()
1813 bond_dev->addr_len); in bond_alb_set_mac_address()
1816 bond_dev->dev_addr, false); in bond_alb_set_mac_address()
1817 if (bond->alb_info.rlb_enabled) { in bond_alb_set_mac_address()
1828 if (bond->alb_info.rlb_enabled) in bond_alb_clear_vlan()