diff options
author | Damjan Marion <damarion@cisco.com> | 2018-11-08 15:30:16 +0100 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2018-11-08 17:08:11 +0000 |
commit | 5100aa9cb9e7acff35fa3bfde8aa95b5ace60344 (patch) | |
tree | a42bb046ea2933042b2722e7b4fe229e3070cac5 | |
parent | a71844f27a0be91fcda25b19604d16122ccc3e73 (diff) |
vnet: store hw interface speed in kbps instead of using flags
Change-Id: Idd4471a3adf7023e48e85717f00c786b1dde0cca
Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r-- | src/plugins/avf/device.c | 12 | ||||
-rw-r--r-- | src/plugins/dpdk/device/format.c | 4 | ||||
-rw-r--r-- | src/plugins/dpdk/device/init.c | 52 | ||||
-rw-r--r-- | src/vnet/interface.api | 8 | ||||
-rw-r--r-- | src/vnet/interface.c | 3 | ||||
-rw-r--r-- | src/vnet/interface.h | 31 | ||||
-rw-r--r-- | src/vnet/interface_api.c | 3 | ||||
-rw-r--r-- | src/vnet/interface_format.c | 21 | ||||
-rw-r--r-- | src/vnet/interface_funcs.h | 8 | ||||
-rw-r--r-- | src/vnet/unix/tapcli.c | 6 |
10 files changed, 54 insertions, 94 deletions
diff --git a/src/plugins/avf/device.c b/src/plugins/avf/device.c index 713953fe4c6..6bf1fe05f05 100644 --- a/src/plugins/avf/device.c +++ b/src/plugins/avf/device.c @@ -899,6 +899,7 @@ avf_process_one_device (vlib_main_t * vm, avf_device_t * ad, int is_irq) int link_up = e->event_data.link_event.link_status; virtchnl_link_speed_t speed = e->event_data.link_event.link_speed; u32 flags = 0; + u32 kbps = 0; if (link_up && (ad->flags & AVF_DEVICE_F_LINK_UP) == 0) { @@ -906,16 +907,17 @@ avf_process_one_device (vlib_main_t * vm, avf_device_t * ad, int is_irq) flags |= (VNET_HW_INTERFACE_FLAG_FULL_DUPLEX | VNET_HW_INTERFACE_FLAG_LINK_UP); if (speed == VIRTCHNL_LINK_SPEED_40GB) - flags |= VNET_HW_INTERFACE_FLAG_SPEED_40G; + kbps = 40000000; else if (speed == VIRTCHNL_LINK_SPEED_25GB) - flags |= VNET_HW_INTERFACE_FLAG_SPEED_25G; + kbps = 25000000; else if (speed == VIRTCHNL_LINK_SPEED_10GB) - flags |= VNET_HW_INTERFACE_FLAG_SPEED_10G; + kbps = 10000000; else if (speed == VIRTCHNL_LINK_SPEED_1GB) - flags |= VNET_HW_INTERFACE_FLAG_SPEED_1G; + kbps = 1000000; else if (speed == VIRTCHNL_LINK_SPEED_100MB) - flags |= VNET_HW_INTERFACE_FLAG_SPEED_100M; + kbps = 100000; vnet_hw_interface_set_flags (vnm, ad->hw_if_index, flags); + vnet_hw_interface_set_link_speed (vnm, ad->hw_if_index, kbps); ad->link_speed = speed; } else if (!link_up && (ad->flags & AVF_DEVICE_F_LINK_UP) != 0) diff --git a/src/plugins/dpdk/device/format.c b/src/plugins/dpdk/device/format.c index ef15055094a..fdc2850e7e0 100644 --- a/src/plugins/dpdk/device/format.c +++ b/src/plugins/dpdk/device/format.c @@ -398,8 +398,8 @@ format_dpdk_link_status (u8 * s, va_list * args) s = format (s, "%s duplex ", (l->link_duplex == ETH_LINK_FULL_DUPLEX) ? "full" : "half"); - s = format (s, "speed %u mtu %d %s\n", l->link_speed, - hi->max_packet_bytes, promisc ? " promisc" : ""); + s = format (s, "mtu %d %s\n", hi->max_packet_bytes, promisc ? + " promisc" : ""); } else s = format (s, "\n"); diff --git a/src/plugins/dpdk/device/init.c b/src/plugins/dpdk/device/init.c index c130dbce5df..fcdc29bfdc4 100644 --- a/src/plugins/dpdk/device/init.c +++ b/src/plugins/dpdk/device/init.c @@ -1584,54 +1584,10 @@ dpdk_update_link_state (dpdk_device_t * xd, f64 now) break; } } - if (hw_flags_chg || (xd->link.link_speed != prev_link.link_speed)) - { - hw_flags_chg = 1; - switch (xd->link.link_speed) - { - case ETH_SPEED_NUM_10M: - hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10M; - break; - case ETH_SPEED_NUM_100M: - hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_100M; - break; - case ETH_SPEED_NUM_1G: - hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_1G; - break; - case ETH_SPEED_NUM_2_5G: - hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_2_5G; - break; - case ETH_SPEED_NUM_5G: - hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_5G; - break; - case ETH_SPEED_NUM_10G: - hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_10G; - break; - case ETH_SPEED_NUM_20G: - hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_20G; - break; - case ETH_SPEED_NUM_25G: - hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_25G; - break; - case ETH_SPEED_NUM_40G: - hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_40G; - break; - case ETH_SPEED_NUM_50G: - hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_50G; - break; - case ETH_SPEED_NUM_56G: - hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_56G; - break; - case ETH_SPEED_NUM_100G: - hw_flags |= VNET_HW_INTERFACE_FLAG_SPEED_100G; - break; - case 0: - break; - default: - dpdk_log_warn ("unknown link speed %d", xd->link.link_speed); - break; - } - } + if (xd->link.link_speed != prev_link.link_speed) + vnet_hw_interface_set_link_speed (vnm, xd->hw_if_index, + xd->link.link_speed * 1000); + if (hw_flags_chg) { if (LINK_STATE_ELOGS) diff --git a/src/vnet/interface.api b/src/vnet/interface.api index fdf34f0da34..2010d8b5f54 100644 --- a/src/vnet/interface.api +++ b/src/vnet/interface.api @@ -1,4 +1,4 @@ -option version = "2.1.0"; +option version = "2.2.0"; service { rpc want_interface_events returns want_interface_events_reply @@ -99,7 +99,7 @@ autoreply define want_interface_events @param pid - the interface's l2 address @param interface_name - name of the interface @param link_duplex - 1 if half duplex, 2 if full duplex - @param link_speed - 1 = 10M, 2 = 100M, 4 = 1G, 8 = 10G, 16 = 40G, 32 = 100G + @param link_speed - value in kbps @param link_MTU - max. transmission unit @param sub_if_id - A number 0-N to uniquely identify this subif on super if @param sub_dot1ad - 0 = dot1q, 1 = dot1ad @@ -144,8 +144,8 @@ define sw_interface_details /* 1 = half duplex, 2 = full duplex */ u8 link_duplex; - /* 1 = 10M, 2 = 100M, 4 = 1G, 8 = 10G, 16 = 40G, 32 = 100G */ - u8 link_speed; + /* link speed in kbps */ + u32 link_speed; /* MTU */ u16 link_mtu; diff --git a/src/vnet/interface.c b/src/vnet/interface.c index 0ee3093f383..37f27ea49ea 100644 --- a/src/vnet/interface.c +++ b/src/vnet/interface.c @@ -305,8 +305,7 @@ vnet_hw_interface_set_flags_helper (vnet_main_t * vnm, u32 hw_if_index, (helper_flags & VNET_INTERFACE_SET_FLAGS_HELPER_IS_CREATE) != 0; mask = - (VNET_HW_INTERFACE_FLAG_LINK_UP | VNET_HW_INTERFACE_FLAG_DUPLEX_MASK | - VNET_HW_INTERFACE_FLAG_SPEED_MASK); + (VNET_HW_INTERFACE_FLAG_LINK_UP | VNET_HW_INTERFACE_FLAG_DUPLEX_MASK); flags &= mask; /* Call hardware interface add/del callbacks. */ diff --git a/src/vnet/interface.h b/src/vnet/interface.h index 9be38709020..01d61afb5e8 100644 --- a/src/vnet/interface.h +++ b/src/vnet/interface.h @@ -491,20 +491,6 @@ typedef enum vnet_hw_interface_flags_t_ VNET_HW_INTERFACE_FLAG_HALF_DUPLEX = (1 << 1), VNET_HW_INTERFACE_FLAG_FULL_DUPLEX = (1 << 2), - /* Hardware link speed */ - VNET_HW_INTERFACE_FLAG_SPEED_10M = (1 << 3), - VNET_HW_INTERFACE_FLAG_SPEED_100M = (1 << 4), - VNET_HW_INTERFACE_FLAG_SPEED_1G = (1 << 5), - VNET_HW_INTERFACE_FLAG_SPEED_2_5G = (1 << 6), - VNET_HW_INTERFACE_FLAG_SPEED_5G = (1 << 7), - VNET_HW_INTERFACE_FLAG_SPEED_10G = (1 << 8), - VNET_HW_INTERFACE_FLAG_SPEED_20G = (1 << 9), - VNET_HW_INTERFACE_FLAG_SPEED_25G = (1 << 10), - VNET_HW_INTERFACE_FLAG_SPEED_40G = (1 << 11), - VNET_HW_INTERFACE_FLAG_SPEED_50G = (1 << 12), - VNET_HW_INTERFACE_FLAG_SPEED_56G = (1 << 13), - VNET_HW_INTERFACE_FLAG_SPEED_100G = (1 << 14), - /* rx mode flags */ VNET_HW_INTERFACE_FLAG_SUPPORTS_INT_MODE = (1 << 16), @@ -517,19 +503,6 @@ typedef enum vnet_hw_interface_flags_t_ #define VNET_HW_INTERFACE_FLAG_DUPLEX_MASK \ (VNET_HW_INTERFACE_FLAG_HALF_DUPLEX | \ VNET_HW_INTERFACE_FLAG_FULL_DUPLEX) -#define VNET_HW_INTERFACE_FLAG_SPEED_MASK \ - (VNET_HW_INTERFACE_FLAG_SPEED_10M | \ - VNET_HW_INTERFACE_FLAG_SPEED_100M | \ - VNET_HW_INTERFACE_FLAG_SPEED_1G | \ - VNET_HW_INTERFACE_FLAG_SPEED_2_5G | \ - VNET_HW_INTERFACE_FLAG_SPEED_5G | \ - VNET_HW_INTERFACE_FLAG_SPEED_10G | \ - VNET_HW_INTERFACE_FLAG_SPEED_20G | \ - VNET_HW_INTERFACE_FLAG_SPEED_25G | \ - VNET_HW_INTERFACE_FLAG_SPEED_40G | \ - VNET_HW_INTERFACE_FLAG_SPEED_50G | \ - VNET_HW_INTERFACE_FLAG_SPEED_56G | \ - VNET_HW_INTERFACE_FLAG_SPEED_100G) /* Hardware-interface. This corresponds to a physical wire that packets flow over. */ @@ -541,6 +514,10 @@ typedef struct vnet_hw_interface_t /* flags */ vnet_hw_interface_flags_t flags; + + /* link speed in kbps */ + u32 link_speed; + /* Hardware address as vector. Zero (e.g. zero-length vector) if no address for this class (e.g. PPP). */ u8 *hw_address; diff --git a/src/vnet/interface_api.c b/src/vnet/interface_api.c index c27f3e87975..e4faeed76b0 100644 --- a/src/vnet/interface_api.c +++ b/src/vnet/interface_api.c @@ -202,8 +202,7 @@ send_sw_interface_details (vpe_api_main_t * am, mp->link_up_down = (hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP) ? 1 : 0; mp->link_duplex = ((hi->flags & VNET_HW_INTERFACE_FLAG_DUPLEX_MASK) >> VNET_HW_INTERFACE_FLAG_DUPLEX_SHIFT); - mp->link_speed = ((hi->flags & VNET_HW_INTERFACE_FLAG_SPEED_MASK) >> - VNET_HW_INTERFACE_FLAG_SPEED_SHIFT); + mp->link_speed = hi->link_speed; mp->link_mtu = ntohs (hi->max_packet_bytes); mp->mtu[VNET_MTU_L3] = ntohl (swif->mtu[VNET_MTU_L3]); mp->mtu[VNET_MTU_IP4] = ntohl (swif->mtu[VNET_MTU_IP4]); diff --git a/src/vnet/interface_format.c b/src/vnet/interface_format.c index 631120b96ac..c62e770e57b 100644 --- a/src/vnet/interface_format.c +++ b/src/vnet/interface_format.c @@ -78,6 +78,24 @@ format_vnet_hw_interface_rx_mode (u8 * s, va_list * args) } u8 * +format_vnet_hw_interface_link_speed (u8 * s, va_list * args) +{ + u32 link_speed = va_arg (*args, u32); + + if (link_speed == 0) + return format (s, "unknown"); + + if (link_speed >= 1000000) + return format (s, "%f Gbps", (f64) link_speed / 1000000); + + if (link_speed >= 1000) + return format (s, "%f Mbps", (f64) link_speed / 1000); + + return format (s, "%u Kbps", link_speed); +} + + +u8 * format_vnet_hw_interface (u8 * s, va_list * args) { vnet_main_t *vnm = va_arg (*args, vnet_main_t *); @@ -115,6 +133,9 @@ format_vnet_hw_interface (u8 * s, va_list * args) else s = format (s, "%s%d", dev_class->name, hi->dev_instance); + s = format (s, "\n%ULink speed: %U", format_white_space, indent + 2, + format_vnet_hw_interface_link_speed, hi->link_speed); + if (verbose) { if (hw_class->format_device) diff --git a/src/vnet/interface_funcs.h b/src/vnet/interface_funcs.h index b7d900740d5..c4c66179bb5 100644 --- a/src/vnet/interface_funcs.h +++ b/src/vnet/interface_funcs.h @@ -325,6 +325,14 @@ vnet_put_frame_to_sw_interface (vnet_main_t * vnm, u32 sw_if_index, return vlib_put_frame_to_node (vlib_get_main (), hw->output_node_index, f); } +always_inline void +vnet_hw_interface_set_link_speed (vnet_main_t * vnm, u32 hw_if_index, + u32 link_speed) +{ + vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index); + hw->link_speed = link_speed; +} + /* Change interface flags (e.g. up, down, enable, disable). */ clib_error_t *vnet_hw_interface_set_flags (vnet_main_t * vnm, u32 hw_if_index, vnet_hw_interface_flags_t flags); diff --git a/src/vnet/unix/tapcli.c b/src/vnet/unix/tapcli.c index d183c3a9ea8..765e857f387 100644 --- a/src/vnet/unix/tapcli.c +++ b/src/vnet/unix/tapcli.c @@ -746,13 +746,11 @@ tapcli_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags) { uword is_admin_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0; u32 hw_flags; - u32 speed_duplex = VNET_HW_INTERFACE_FLAG_FULL_DUPLEX - | VNET_HW_INTERFACE_FLAG_SPEED_1G; if (is_admin_up) - hw_flags = VNET_HW_INTERFACE_FLAG_LINK_UP | speed_duplex; + hw_flags = VNET_HW_INTERFACE_FLAG_LINK_UP; else - hw_flags = speed_duplex; + hw_flags = 0; vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags); return 0; |