From: Marc Sune <marcde...@gmail.com>

It is a helper for the bitmap configuration.

Signed-off-by: Marc Sune <marcdevel at gmail.com>
Signed-off-by: Thomas Monjalon <thomas.monjalon at 6wind.com>
---
 lib/librte_ether/rte_ethdev.c          | 31 +++++++++++++++++++++++++++++++
 lib/librte_ether/rte_ethdev.h          | 13 +++++++++++++
 lib/librte_ether/rte_ether_version.map |  1 +
 3 files changed, 45 insertions(+)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index db35102..4dbea4e 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -866,6 +866,37 @@ rte_eth_dev_tx_queue_config(struct rte_eth_dev *dev, 
uint16_t nb_queues)
        return 0;
 }

+uint32_t
+rte_eth_speed_bitflag(uint32_t speed, int duplex)
+{
+       switch (speed) {
+       case ETH_SPEED_NUM_10M:
+               return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD;
+       case ETH_SPEED_NUM_100M:
+               return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD;
+       case ETH_SPEED_NUM_1G:
+               return ETH_LINK_SPEED_1G;
+       case ETH_SPEED_NUM_2_5G:
+               return ETH_LINK_SPEED_2_5G;
+       case ETH_SPEED_NUM_5G:
+               return ETH_LINK_SPEED_5G;
+       case ETH_SPEED_NUM_10G:
+               return ETH_LINK_SPEED_10G;
+       case ETH_SPEED_NUM_20G:
+               return ETH_LINK_SPEED_20G;
+       case ETH_SPEED_NUM_25G:
+               return ETH_LINK_SPEED_25G;
+       case ETH_SPEED_NUM_40G:
+               return ETH_LINK_SPEED_40G;
+       case ETH_SPEED_NUM_50G:
+               return ETH_LINK_SPEED_50G;
+       case ETH_SPEED_NUM_56G:
+               return ETH_LINK_SPEED_56G;
+       default:
+               return 0;
+       }
+}
+
 int
 rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
                      const struct rte_eth_conf *dev_conf)
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index 470e434..4b37cd0 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -1871,6 +1871,19 @@ struct eth_driver {
 void rte_eth_driver_register(struct eth_driver *eth_drv);

 /**
+ * Convert a numerical speed in Mbps to a bitmap flag that can be used in
+ * the bitmap link_speeds of the struct rte_eth_conf
+ *
+ * @param speed
+ *   Numerical speed value in Mbps
+ * @param duplex
+ *   ETH_LINK_[HALF/FULL]_DUPLEX (only for 10/100M speeds)
+ * @return
+ *   0 if the speed cannot be mapped
+ */
+uint32_t rte_eth_speed_bitflag(uint32_t speed, int duplex);
+
+/**
  * Configure an Ethernet device.
  * This function must be invoked first before any other function in the
  * Ethernet API. This function can also be re-invoked when a device is in the
diff --git a/lib/librte_ether/rte_ether_version.map 
b/lib/librte_ether/rte_ether_version.map
index 5cb4d79..13d9f2e 100644
--- a/lib/librte_ether/rte_ether_version.map
+++ b/lib/librte_ether/rte_ether_version.map
@@ -124,6 +124,7 @@ DPDK_16.04 {
        rte_eth_dev_set_vlan_ether_type;
        rte_eth_dev_udp_tunnel_port_add;
        rte_eth_dev_udp_tunnel_port_delete;
+       rte_eth_speed_bitflag;
        rte_eth_tx_buffer_count_callback;
        rte_eth_tx_buffer_drop_callback;
        rte_eth_tx_buffer_init;
-- 
2.7.0

Reply via email to