- {
- /*
- * Extra set up for bond interfaces:
- * 1. Setup MACs for bond interfaces and their slave links which was set
- * in dpdk_device_setup() but needs to be done again here to take
- * effect.
- * 2. Set up info and register slave link state change callback handling.
- * 3. Set up info for bond interface related CLI support.
- */
- int nports = rte_eth_dev_count ();
- if (nports > 0)
- {
- for (i = 0; i < nports; i++)
- {
- xd = &dm->devices[i];
- ASSERT (i == xd->device_index);
- if (xd->pmd == VNET_DPDK_PMD_BOND)
- {
- u8 addr[6];
- dpdk_portid_t slink[16];
- int nlink = rte_eth_bond_slaves_get (i, slink, 16);
- if (nlink > 0)
- {
- vnet_hw_interface_t *bhi;
- ethernet_interface_t *bei;
- int rv;
-
- /* Get MAC of 1st slave link */
- rte_eth_macaddr_get
- (slink[0], (struct ether_addr *) addr);
-
- /* Set MAC of bounded interface to that of 1st slave link */
- clib_warning ("Set MAC for bond port %d BondEthernet%d",
- i, xd->port_id);
- rv = rte_eth_bond_mac_address_set
- (i, (struct ether_addr *) addr);
- if (rv)
- clib_warning ("Set MAC addr failure rv=%d", rv);
-
- /* Populate MAC of bonded interface in VPP hw tables */
- bhi = vnet_get_hw_interface
- (vnm, dm->devices[i].hw_if_index);
- bei = pool_elt_at_index
- (em->interfaces, bhi->hw_instance);
- clib_memcpy (bhi->hw_address, addr, 6);
- clib_memcpy (bei->address, addr, 6);
-
- /* Init l3 packet size allowed on bonded interface */
- bhi->max_packet_bytes = ETHERNET_MAX_PACKET_BYTES;
- bhi->max_l3_packet_bytes[VLIB_RX] =
- bhi->max_l3_packet_bytes[VLIB_TX] =
- ETHERNET_MAX_PACKET_BYTES - sizeof (ethernet_header_t);
- while (nlink >= 1)
- { /* for all slave links */
- int slave = slink[--nlink];
- dpdk_device_t *sdev = &dm->devices[slave];
- vnet_hw_interface_t *shi;
- vnet_sw_interface_t *ssi;
- ethernet_interface_t *sei;
- /* Add MAC to all slave links except the first one */
- if (nlink)
- {
- clib_warning ("Add MAC for slave port %d", slave);
- rv = rte_eth_dev_mac_addr_add
- (slave, (struct ether_addr *) addr, 0);
- if (rv)
- clib_warning ("Add MAC addr failure rv=%d", rv);
- }
- /* Setup slave link state change callback handling */
- rte_eth_dev_callback_register
- (slave, RTE_ETH_EVENT_INTR_LSC,
- dpdk_port_state_callback, NULL);
- dpdk_device_t *sxd = &dm->devices[slave];
- sxd->flags |= DPDK_DEVICE_FLAG_BOND_SLAVE;
- sxd->bond_port = i;
- /* Set slaves bitmap for bonded interface */
- bhi->bond_info = clib_bitmap_set
- (bhi->bond_info, sdev->hw_if_index, 1);
- /* Set MACs and slave link flags on slave interface */
- shi = vnet_get_hw_interface (vnm, sdev->hw_if_index);
- ssi = vnet_get_sw_interface
- (vnm, sdev->vlib_sw_if_index);
- sei = pool_elt_at_index
- (em->interfaces, shi->hw_instance);
- shi->bond_info = VNET_HW_INTERFACE_BOND_INFO_SLAVE;
- ssi->flags |= VNET_SW_INTERFACE_FLAG_BOND_SLAVE;
- clib_memcpy (shi->hw_address, addr, 6);
- clib_memcpy (sei->address, addr, 6);
- /* Set l3 packet size allowed as the lowest of slave */
- if (bhi->max_l3_packet_bytes[VLIB_RX] >
- shi->max_l3_packet_bytes[VLIB_RX])
- bhi->max_l3_packet_bytes[VLIB_RX] =
- bhi->max_l3_packet_bytes[VLIB_TX] =
- shi->max_l3_packet_bytes[VLIB_RX];
- /* Set max packet size allowed as the lowest of slave */
- if (bhi->max_packet_bytes > shi->max_packet_bytes)
- bhi->max_packet_bytes = shi->max_packet_bytes;
- }
- }
- }
- }
- }
- }
-