Add support to provide link type as part of link status if available from ethdev driver. Link type such as Fibre, Twisted-Pair etc is generally available information in PMD or lower layer software and is a useful information for DPDK applications. Similar info is also available via ethtool for Linux kernel netdevs.
Signed-off-by: Nithin Dabilpuram <ndabilpu...@marvell.com> --- lib/ethdev/ethdev_trace.h | 7 +++++ lib/ethdev/ethdev_trace_points.c | 3 +++ lib/ethdev/rte_ethdev.c | 44 ++++++++++++++++++++++++++++++-- lib/ethdev/rte_ethdev.h | 28 ++++++++++++++++++++ lib/ethdev/version.map | 1 + 5 files changed, 81 insertions(+), 2 deletions(-) diff --git a/lib/ethdev/ethdev_trace.h b/lib/ethdev/ethdev_trace.h index c65b78590a..a060e2de03 100644 --- a/lib/ethdev/ethdev_trace.h +++ b/lib/ethdev/ethdev_trace.h @@ -2110,6 +2110,13 @@ RTE_TRACE_POINT_FP( rte_trace_point_emit_string(ret); ) +RTE_TRACE_POINT_FP( + rte_eth_trace_link_type_to_str, + RTE_TRACE_POINT_ARGS(uint8_t link_type, const char *ret), + rte_trace_point_emit_u8(link_type); + rte_trace_point_emit_string(ret); +); + /* Called in loop in examples/bond and examples/ethtool */ RTE_TRACE_POINT_FP( rte_eth_trace_macaddr_get, diff --git a/lib/ethdev/ethdev_trace_points.c b/lib/ethdev/ethdev_trace_points.c index cb99cf91fc..e6dee5f668 100644 --- a/lib/ethdev/ethdev_trace_points.c +++ b/lib/ethdev/ethdev_trace_points.c @@ -199,6 +199,9 @@ RTE_TRACE_POINT_REGISTER(rte_eth_trace_link_speed_to_str, RTE_TRACE_POINT_REGISTER(rte_eth_trace_link_to_str, lib.ethdev.link_to_str) +RTE_TRACE_POINT_REGISTER(rte_eth_trace_link_type_to_str, + lib.ethdev.link_type_to_str) + RTE_TRACE_POINT_REGISTER(rte_eth_trace_stats_get, lib.ethdev.stats_get) diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index 85798d0ebc..9e993199f5 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -3221,18 +3221,58 @@ rte_eth_link_to_str(char *str, size_t len, const struct rte_eth_link *eth_link) if (eth_link->link_status == RTE_ETH_LINK_DOWN) ret = snprintf(str, len, "Link down"); else - ret = snprintf(str, len, "Link up at %s %s %s", + ret = snprintf(str, len, "Link up at %s %s %s %s", rte_eth_link_speed_to_str(eth_link->link_speed), (eth_link->link_duplex == RTE_ETH_LINK_FULL_DUPLEX) ? "FDX" : "HDX", (eth_link->link_autoneg == RTE_ETH_LINK_AUTONEG) ? - "Autoneg" : "Fixed"); + "Autoneg" : "Fixed", + rte_eth_link_type_to_str(eth_link->link_type)); rte_eth_trace_link_to_str(len, eth_link, str, ret); return ret; } +const char * +rte_eth_link_type_to_str(uint8_t link_type) +{ + const char *ret; + + switch (link_type) { + case RTE_ETH_LINK_TYPE_NONE: + ret = "None"; + break; + case RTE_ETH_LINK_TYPE_TP: + ret = "Twisted Pair"; + break; + case RTE_ETH_LINK_TYPE_AUI: + ret = "AUI"; + break; + case RTE_ETH_LINK_TYPE_MII: + ret = "MII"; + break; + case RTE_ETH_LINK_TYPE_FIBRE: + ret = "Fibre"; + break; + case RTE_ETH_LINK_TYPE_BNC: + ret = "BNC"; + break; + case RTE_ETH_LINK_TYPE_DA: + ret = "Direct Attach Copper"; + break; + case RTE_ETH_LINK_TYPE_OTHER: + ret = "Other"; + break; + default: + ret = "Invalid"; + } + + rte_eth_trace_link_type_to_str(link_type, ret); + + return ret; +} + int rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats) { diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h index ea7f8c4a1a..ccbb657fb9 100644 --- a/lib/ethdev/rte_ethdev.h +++ b/lib/ethdev/rte_ethdev.h @@ -329,6 +329,19 @@ struct rte_eth_stats { #define RTE_ETH_SPEED_NUM_UNKNOWN UINT32_MAX /**< Unknown */ /**@}*/ +/**@{@name PORT type + * Ethernet port type + */ +#define RTE_ETH_LINK_TYPE_NONE 0x00 /**< Not defined */ +#define RTE_ETH_LINK_TYPE_TP 0x01 /**< Twisted Pair */ +#define RTE_ETH_LINK_TYPE_AUI 0x02 /**< Attachment Unit Interface */ +#define RTE_ETH_LINK_TYPE_MII 0x03 /**< Media Independent Interface */ +#define RTE_ETH_LINK_TYPE_FIBRE 0x04 /**< Fibre */ +#define RTE_ETH_LINK_TYPE_BNC 0x05 /**< BNC */ +#define RTE_ETH_LINK_TYPE_DA 0x06 /**< Direct Attach copper */ +#define RTE_ETH_LINK_TYPE_OTHER 0x1F /**< Other type */ +/**@}*/ + /** * A structure used to retrieve link-level information of an Ethernet port. */ @@ -341,6 +354,7 @@ struct rte_eth_link { uint16_t link_duplex : 1; /**< RTE_ETH_LINK_[HALF/FULL]_DUPLEX */ uint16_t link_autoneg : 1; /**< RTE_ETH_LINK_[AUTONEG/FIXED] */ uint16_t link_status : 1; /**< RTE_ETH_LINK_[DOWN/UP] */ + uint16_t link_type : 5; /**< RTE_ETH_LINK_TYPE_* */ }; }; }; @@ -3113,6 +3127,20 @@ int rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *link) __rte_experimental const char *rte_eth_link_speed_to_str(uint32_t link_speed); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * This function converts an Ethernet link type to a string. + * + * @param link_type + * The link type to convert. + * @return + * The string representation of the link type. + */ +__rte_experimental +const char *rte_eth_link_type_to_str(uint8_t link_type); + /** * @warning * @b EXPERIMENTAL: this API may change without prior notice. diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map index 3aacba8614..5910ed10a5 100644 --- a/lib/ethdev/version.map +++ b/lib/ethdev/version.map @@ -216,6 +216,7 @@ EXPERIMENTAL { rte_eth_hairpin_unbind; rte_eth_link_speed_to_str; rte_eth_link_to_str; + rte_eth_link_type_to_str; rte_eth_fec_get_capability; rte_eth_fec_get; rte_eth_fec_set; -- 2.34.1