Skip to content

Commit

Permalink
netdev-dpdk: Add link speed to get_status().
Browse files Browse the repository at this point in the history
Report the link speed of the device in netdev_dpdk_get_status()
function.

Link speed is already reported as part of the netdev_get_features()
function. However only link speeds defined in the OpenFlow specs are
supported so speeds such as 25 Gbps etc. are not shown. The link
speed for the device is available in Mbps in rte_eth_link.
This commit converts the link speed for a given dpdk device to an
easy to read string and reports it in get_status().

Suggested-by: Flavio Leitner <[email protected]>
Acked-by: Ilya Maximets <[email protected]>
Signed-off-by: Ian Stokes <[email protected]>
  • Loading branch information
istokes committed Nov 2, 2018
1 parent dfcb5b8 commit 31154f9
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/netdev-dpdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -3021,18 +3021,44 @@ netdev_dpdk_vhost_user_get_status(const struct netdev *netdev,
return 0;
}

/*
* Convert a given uint32_t link speed defined in DPDK to a string
* equivalent.
*/
static const char *
netdev_dpdk_link_speed_to_str__(uint32_t link_speed)
{
switch (link_speed) {
case ETH_SPEED_NUM_10M: return "10Mbps";
case ETH_SPEED_NUM_100M: return "100Mbps";
case ETH_SPEED_NUM_1G: return "1Gbps";
case ETH_SPEED_NUM_2_5G: return "2.5Gbps";
case ETH_SPEED_NUM_5G: return "5Gbps";
case ETH_SPEED_NUM_10G: return "10Gbps";
case ETH_SPEED_NUM_20G: return "20Gbps";
case ETH_SPEED_NUM_25G: return "25Gbps";
case ETH_SPEED_NUM_40G: return "40Gbps";
case ETH_SPEED_NUM_50G: return "50Gbps";
case ETH_SPEED_NUM_56G: return "56Gbps";
case ETH_SPEED_NUM_100G: return "100Gbps";
default: return "Not Defined";
}
}

static int
netdev_dpdk_get_status(const struct netdev *netdev, struct smap *args)
{
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
struct rte_eth_dev_info dev_info;
uint32_t link_speed;

if (!rte_eth_dev_is_valid_port(dev->port_id)) {
return ENODEV;
}

ovs_mutex_lock(&dev->mutex);
rte_eth_dev_info_get(dev->port_id, &dev_info);
link_speed = dev->link.link_speed;
ovs_mutex_unlock(&dev->mutex);

smap_add_format(args, "port_no", DPDK_PORT_ID_FMT, dev->port_id);
Expand Down Expand Up @@ -3064,6 +3090,14 @@ netdev_dpdk_get_status(const struct netdev *netdev, struct smap *args)
dev_info.pci_dev->id.device_id);
}

/* Not all link speeds are defined in the OpenFlow specs e.g. 25 Gbps.
* In that case the speed will not be reported as part of the usual
* call to get_features(). Get the link speed of the device and add it
* to the device status in an easy to read string format.
*/
smap_add(args, "link_speed",
netdev_dpdk_link_speed_to_str__(link_speed));

return 0;
}

Expand Down

0 comments on commit 31154f9

Please sign in to comment.