From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <thomas.monjalon@6wind.com>
Received: from mail-wm0-f45.google.com (mail-wm0-f45.google.com [74.125.82.45])
 by dpdk.org (Postfix) with ESMTP id C71965A17
 for <dev@dpdk.org>; Thu, 17 Mar 2016 19:10:56 +0100 (CET)
Received: by mail-wm0-f45.google.com with SMTP id p65so37769572wmp.1
 for <dev@dpdk.org>; Thu, 17 Mar 2016 11:10:56 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=6wind-com.20150623.gappssmtp.com; s=20150623;
 h=from:to:cc:subject:date:message-id:in-reply-to:references;
 bh=3jaXFeXS/eUIAXBpL4pDtN1YyB2l7r3qIcmpdeZZtX4=;
 b=OiYJJPCaNAcjO6bKkMackBMB+vnMh1QsIkUftDEZwO49q0HII9ngZ0aGSoQtcfVRzs
 WauFpbhx/7AXUY0rLFDAtuyna80E770cJv1T3KeDqSG5xZGcGQaXpSb2DfGko7z0Vnax
 c4iU90VoaxhD4Q88RCkwRZnNlaRJwu3o/GMVkH83khDwllv/GsUKuiqSJqL/doC2ty6N
 nSIafN0n0dhQINStVYMGxTeTSMaG2E87X5WC8XlHy3LSk7luI5p42IiwybA/OGzJlcUb
 CSsWvIoDrbu6wnRfsGUao3gyf1e/Pe/+C65zP58aUj/UrGgYkuh5qj4jSSFTLoqonzxh
 RRjA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20130820;
 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
 :references;
 bh=3jaXFeXS/eUIAXBpL4pDtN1YyB2l7r3qIcmpdeZZtX4=;
 b=DWs7Dyw6r5u5l2qLLb7ZkqviNaayqikq17ZQ7/3QLu34Eawvta7AFm5ERu5JsDRyWw
 5cxQ0bcmEvnrSev4HAbQDQufx85N9As5MjGmsCamjHDQipquL4SIVY66u10OUeyUAmtE
 k9NOIPZnum660Z0F143ejPQ5/sJPug58jX0JWncUI20sBvj4GzKJMeGqgN9YihhuNna4
 jKapRtu+SWd2TjhdWA1E0XPEn1FwO0POl4okVpWKKjVvDbAQbltYiyIBc7FbBIfD3c22
 nLrcp/aWF9mLLO4wGX/2YuU3QP8lM8eYz2SIPdKO0I/1wRJ3juQjVH/AaG7ib81wB/ji
 mHGA==
X-Gm-Message-State: AD7BkJKmAoT7TMzbPCWUm4WI4ulzYuPlhAAUVY/UbYkvrlmz4dNrX5AH+Yz5RcrHZDRMbTqI
X-Received: by 10.194.201.166 with SMTP id kb6mr11691089wjc.125.1458238256697; 
 Thu, 17 Mar 2016 11:10:56 -0700 (PDT)
Received: from XPS13.localdomain (91.111.75.86.rev.sfr.net. [86.75.111.91])
 by smtp.gmail.com with ESMTPSA id u14sm31196179wmu.8.2016.03.17.11.10.54
 (version=TLSv1/SSLv3 cipher=OTHER);
 Thu, 17 Mar 2016 11:10:56 -0700 (PDT)
From: Thomas Monjalon <thomas.monjalon@6wind.com>
To: marcdevel@gmail.com, bruce.richardson@intel.com, declan.doherty@intel.com,
 konstantin.ananyev@intel.com, wenzhuo.lu@intel.com, helin.zhang@intel.com,
 jing.d.chen@intel.com, harish.patil@qlogic.com,
 rahul.lakkireddy@chelsio.com, johndale@cisco.com, vido@cesnet.cz,
 adrien.mazarguil@6wind.com, alejandro.lucero@netronome.com
Cc: dev@dpdk.org
Date: Thu, 17 Mar 2016 19:09:04 +0100
Message-Id: <1458238145-7496-8-git-send-email-thomas.monjalon@6wind.com>
X-Mailer: git-send-email 2.7.0
In-Reply-To: <1458238145-7496-1-git-send-email-thomas.monjalon@6wind.com>
References: <1457992546-32230-1-git-send-email-thomas.monjalon@6wind.com>
 <1458238145-7496-1-git-send-email-thomas.monjalon@6wind.com>
Subject: [dpdk-dev] [PATCH v11 7/8] ethdev: convert speed number to bitmap
	flag
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches and discussions about DPDK <dev.dpdk.org>
List-Unsubscribe: <http://dpdk.org/ml/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://dpdk.org/ml/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <http://dpdk.org/ml/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Thu, 17 Mar 2016 18:10:56 -0000

From: Marc Sune <marcdevel@gmail.com>

It is a helper for the bitmap configuration.

Signed-off-by: Marc Sune <marcdevel@gmail.com>
Signed-off-by: Thomas Monjalon <thomas.monjalon@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