switch (policy) {
case BALANCE_XMIT_POLICY_LAYER2:
- eth_hdr = (struct ether_hdr *)buf->pkt.data;
+ eth_hdr = rte_pktmbuf_mtod(buf, struct ether_hdr *);
hash = ether_hash(eth_hdr);
hash ^= hash >> 8;
return hash % slave_count;
case BALANCE_XMIT_POLICY_LAYER23:
- eth_hdr = (struct ether_hdr *)buf->pkt.data;
+ eth_hdr = rte_pktmbuf_mtod(buf, struct ether_hdr *);
if (buf->ol_flags & PKT_RX_VLAN_PKT)
eth_offset = sizeof(struct ether_hdr) + sizeof(struct vlan_hdr);
for (i = 0; i < internals->slave_count; i++) {
if (slave_configure(eth_dev, &(rte_eth_devices[internals->slaves[i]]))
!= 0) {
- RTE_LOG(ERR, PMD,
- "bonded port (%d) failed to reconfigure slave device %d)",
+ RTE_LOG(ERR, PMD, "bonded port "
+ "(%d) failed to reconfigure slave device (%d)\n)",
eth_dev->data->port_id, internals->slaves[i]);
return -1;
}
{
}
-static int
-bond_ethdev_configure(struct rte_eth_dev *dev __rte_unused)
-{
- return 0;
-}
+/* forward declaration */
+static int bond_ethdev_configure(struct rte_eth_dev *dev);
static void
bond_ethdev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
struct bond_dev_private *internals;
struct rte_eth_link link;
- int i, bonded_port_id, valid_slave, active_pos = -1;
-
- if (type != RTE_ETH_EVENT_INTR_LSC)
- return;
+ int i, valid_slave = 0, active_pos = -1;
- if (param == NULL)
+ if (type != RTE_ETH_EVENT_INTR_LSC || param == NULL)
return;
- bonded_port_id = *(uint8_t *)param;
-
- bonded_eth_dev = &rte_eth_devices[bonded_port_id];
+ bonded_eth_dev = &rte_eth_devices[*(uint8_t *)param];
slave_eth_dev = &rte_eth_devices[port_id];
if (valid_bonded_ethdev(bonded_eth_dev))
rte_eth_link_get_nowait(port_id, &link);
if (link.link_status) {
- if (active_pos == -1) {
- /* if no active slave ports then set this port to be primary port */
- if (internals->active_slave_count == 0) {
- /* If first active slave, then change link status */
- bonded_eth_dev->data->dev_link.link_status = 1;
- internals->current_primary_port = port_id;
+ if (active_pos >= 0)
+ return;
+
+ /* if no active slave ports then set this port to be primary port */
+ if (internals->active_slave_count < 1) {
+ /* If first active slave, then change link status */
+ bonded_eth_dev->data->dev_link.link_status = 1;
+ internals->current_primary_port = port_id;
+
+ /* Inherit eth dev link properties from first active slave */
+ link_properties_set(bonded_eth_dev,
+ &(slave_eth_dev->data->dev_link));
+ }
+ internals->active_slaves[internals->active_slave_count++] = port_id;
- /* Inherit eth dev link properties from first active slave */
- link_properties_set(bonded_eth_dev,
- &(slave_eth_dev->data->dev_link));
+ /* If user has defined the primary port then default to using it */
+ if (internals->user_defined_primary_port &&
+ internals->primary_port == port_id)
+ bond_ethdev_primary_set(internals, port_id);
+ } else {
+ if (active_pos < 0)
+ return;
- }
- internals->active_slaves[internals->active_slave_count++] = port_id;
+ /* Remove from active slave list */
+ for (i = active_pos; i < (internals->active_slave_count - 1); i++)
+ internals->active_slaves[i] = internals->active_slaves[i+1];
+
+ internals->active_slave_count--;
- /* If user has defined the primary port then default to using it */
- if (internals->user_defined_primary_port &&
- internals->primary_port == port_id)
- bond_ethdev_primary_set(internals, port_id);
+ /* No active slaves, change link status to down and reset other
+ * link properties */
+ if (internals->active_slave_count < 1) {
+ bonded_eth_dev->data->dev_link.link_status = 0;
+ link_properties_reset(bonded_eth_dev);
}
- } else {
- if (active_pos != -1) {
- /* Remove from active slave list */
- for (i = active_pos; i < (internals->active_slave_count - 1); i++)
- internals->active_slaves[i] = internals->active_slaves[i+1];
-
- internals->active_slave_count--;
-
- /* No active slaves, change link status to down and reset other
- * link properties */
- if (internals->active_slave_count == 0)
- link_properties_reset(bonded_eth_dev);
-
- /* Update primary id, take first active slave from list or if none
- * available set to -1 */
- if (port_id == internals->current_primary_port) {
- if (internals->active_slave_count > 0)
- bond_ethdev_primary_set(internals,
- internals->active_slaves[0]);
- else
- internals->current_primary_port = internals->primary_port;
- }
+
+ /* Update primary id, take first active slave from list or if none
+ * available set to -1 */
+ if (port_id == internals->current_primary_port) {
+ if (internals->active_slave_count > 0)
+ bond_ethdev_primary_set(internals,
+ internals->active_slaves[0]);
+ else
+ internals->current_primary_port = internals->primary_port;
}
}
}
static int
bond_init(const char *name, const char *params)
{
+ struct bond_dev_private *internals;
struct rte_kvargs *kvlist;
uint8_t bonding_mode, socket_id;
int arg_count, port_id;
name, bonding_mode, socket_id);
return -1;
}
+ internals = rte_eth_devices[port_id].data->dev_private;
+ internals->kvlist = kvlist;
RTE_LOG(INFO, EAL,
"Create bonded device %s on port %d in mode %u on socket %u.\n",
name, port_id, bonding_mode, socket_id);
+ return 0;
+}
+
+/* this part will resolve the slave portids after all the other pdev and vdev
+ * have been allocated */
+static int
+bond_ethdev_configure(struct rte_eth_dev *dev)
+{
+ char *name = dev->data->name;
+ struct bond_dev_private *internals = dev->data->dev_private;
+ struct rte_kvargs *kvlist = internals->kvlist;
+ int arg_count, port_id = dev - rte_eth_devices;
+
+ /*
+ * if no kvlist, it means that this bonded device has been created
+ * through the bonding api.
+ */
+ if (!kvlist)
+ return 0;
/* Parse MAC address for bonded device */
arg_count = rte_kvargs_count(kvlist, PMD_BOND_MAC_ADDR_KVARG);
}
static struct rte_driver bond_drv = {
- .name = PMD_BOND_NAME,
- .type = PMD_BDEV,
+ .name = "eth_bond",
+ .type = PMD_VDEV,
.init = bond_init,
};