DPDK patches and discussions
 help / color / mirror / Atom feed
From: Vipin Varghese <vipin.varghese@intel.com>
To: dev@dpdk.org
Cc: ferruh.yigit@intel.com, amol.patel@intel.com,
	david.hunt@intel.com, deepak.k.jain@intel.com,
	Vipin Varghese <vipin.varghese@intel.com>
Subject: [dpdk-dev] [PATCH v1] [net/tap] add logic to assign speed from user
Date: Thu, 21 Dec 2017 22:23:20 +0530	[thread overview]
Message-ID: <1513875200-5061-1-git-send-email-vipin.varghese@intel.com> (raw)

TAP speed is passed as user argument, but never set to interface.
New logic brings speed get and set to LOCAL and REMOTE interfaces.

Updated the default PMD speeed to 10M as per Linux Kernel default
value.

Signed-off-by: Vipin Varghese <vipin.varghese@intel.com>
---
 drivers/net/tap/rte_eth_tap.c | 185 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 182 insertions(+), 3 deletions(-)

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index 6b27679..7238504 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -62,6 +62,8 @@
 #include <linux/if_ether.h>
 #include <linux/version.h>
 #include <fcntl.h>
+#include <linux/ethtool.h>
+#include <linux/sockios.h>
 
 #include <rte_eth_tap.h>
 #include <tap_flow.h>
@@ -96,7 +98,7 @@
 static volatile uint32_t tap_trigger;	/* Rx trigger */
 
 static struct rte_eth_link pmd_link = {
-	.link_speed = ETH_SPEED_NUM_10G,
+	.link_speed = ETH_SPEED_NUM_10M,
 	.link_duplex = ETH_LINK_FULL_DUPLEX,
 	.link_status = ETH_LINK_DOWN,
 	.link_autoneg = ETH_LINK_SPEED_AUTONEG
@@ -1229,6 +1231,178 @@ enum ioctl_mode {
 };
 
 static int
+tap_speed_set(struct pmd_internals *pmd, const char *iface_name,
+enum ioctl_mode mode, uint32_t speed)
+{
+	int err;
+	struct ifreq ifr;
+	struct ethtool_cmd edataCmd = {0};
+#ifdef ETHTOOL_SLINKSETTINGS
+	struct ethtool_link_settings edataLink = {0};
+#endif
+
+	if ((pmd == NULL) || (iface_name == NULL) ||
+		(speed == ETH_SPEED_NUM_NONE))
+		return -1;
+
+	RTE_LOG(DEBUG, PMD,
+		"SET speed %u for %s iface_name %s\n",
+		speed,
+		(mode == REMOTE_ONLY)?"REMOTE":"LOCAL",
+		iface_name);
+
+	switch (speed) {
+	case (ETH_SPEED_NUM_10M):
+	case (ETH_SPEED_NUM_100M):
+	case (ETH_SPEED_NUM_1G):
+	case (ETH_SPEED_NUM_2_5G):
+	case (ETH_SPEED_NUM_5G):
+	case (ETH_SPEED_NUM_10G):
+	case (ETH_SPEED_NUM_20G):
+	case (ETH_SPEED_NUM_25G):
+	case (ETH_SPEED_NUM_40G):
+	case (ETH_SPEED_NUM_50G):
+	case (ETH_SPEED_NUM_56G):
+	case (ETH_SPEED_NUM_100G):
+	break;
+
+	default:
+		RTE_LOG(ERR, PMD,
+			"Unsupported SET speed %u for %s iface_name %s.\n",
+			speed,
+			(mode == REMOTE_ONLY)?"REMOTE":"LOCAL",
+			iface_name);
+
+		return -2;
+	}
+
+#ifdef ETHTOOL_SLINKSETTINGS
+	edataLink.speed = speed;
+	edataLink.cmd = ETHTOOL_SLINKSETTINGS;
+	ifr.ifr_data = (caddr_t)&edataLink;
+
+	err = tap_ioctl(pmd, SIOCETHTOOL, &ifr, 0,
+		(mode == REMOTE_ONLY)?REMOTE_ONLY:LOCAL_ONLY);
+	if (err == 0)
+		return speed;
+#endif
+
+	edataCmd.speed = speed;
+	edataCmd.cmd = ETHTOOL_SSET;
+	ifr.ifr_data = (caddr_t)&edataCmd;
+
+	err = tap_ioctl(pmd, SIOCETHTOOL, &ifr, 0,
+		(mode == REMOTE_ONLY)?REMOTE_ONLY:LOCAL_ONLY);
+
+	if (err == 0)
+		return speed;
+
+	RTE_LOG(ERR, PMD,
+		"Failed to SET speed %u for %s iface_name %s.\n",
+		speed, (mode == REMOTE_ONLY)?"REMOTE":"LOCAL", iface_name);
+
+	return -2;
+}
+
+static int
+tap_speed_get(struct pmd_internals *pmd, const char *iface_name,
+enum ioctl_mode mode)
+{
+	int err;
+	struct ifreq ifr;
+	struct ethtool_cmd edataCmd = {0};
+#ifdef ETHTOOL_GLINKSETTINGS
+	struct ethtool_link_settings edataLink = {0};
+#endif
+
+	if ((pmd == NULL) || (iface_name == NULL))
+		return -1;
+
+	RTE_LOG(DEBUG, PMD,
+		"Retrive speed for %s iface_name %s.\n",
+		(mode == REMOTE_ONLY)?"REMOTE":"LOCAL", iface_name);
+
+#ifdef ETHTOOL_GLINKSETTINGS
+	edataLink.speed = 0;
+	edataLink.cmd = ETHTOOL_GLINKSETTINGS;
+	ifr.ifr_data = (caddr_t)&edataLink;
+
+	err = tap_ioctl(pmd, SIOCETHTOOL, &ifr, 0,
+		(mode == REMOTE_ONLY)?REMOTE_ONLY:LOCAL_ONLY);
+
+	if ((err == 0) && (edataLink.speed))
+		return edataLink.speed;
+#endif
+
+	edataCmd.speed = 0;
+	edataCmd.cmd = ETHTOOL_GSET;
+	ifr.ifr_data = (caddr_t)&edataCmd;
+
+	err = tap_ioctl(pmd, SIOCETHTOOL, &ifr, 0,
+		(mode == REMOTE_ONLY)?REMOTE_ONLY:LOCAL_ONLY);
+	if ((err == 0) && (edataCmd.speed))
+		return edataCmd.speed;
+
+	RTE_LOG(ERR, PMD,
+		"Failed to retrive speed for %s iface_name %s.\n",
+		(mode == REMOTE_ONLY)?"REMOTE":"LOCAL", iface_name);
+
+	return -2;
+}
+
+static int
+eth_dev_tap_config_speed(struct pmd_internals *pmd)
+{
+	int err = 0, remoteSpeed = 0, localSpeed = 0;
+
+	err = tap_speed_get(pmd,
+		pmd->name, LOCAL_ONLY);
+	if (err <= ETH_SPEED_NUM_NONE)
+		return err;
+	localSpeed = err;
+
+	RTE_LOG(DEBUG, PMD,
+		"Local interface %s speed got %d desired %u\n",
+		pmd->name, localSpeed, pmd_link.link_speed);
+
+	if (localSpeed != (int) pmd_link.link_speed) {
+		err = tap_speed_set(pmd, pmd->name, LOCAL_ONLY,
+			pmd_link.link_speed);
+		if (err <= ETH_SPEED_NUM_NONE)
+			return 0;
+		localSpeed = err;
+	}
+	pmd_link.link_speed = (unsigned int) localSpeed;
+
+	RTE_LOG(INFO, PMD,
+		"speed %u for ifindex for %s.\n",
+		pmd_link.link_speed, pmd->name);
+
+	/*If remote interface is passed as argument, update speed*/
+	if (strlen(pmd->remote_iface)) {
+		err = tap_speed_get(pmd, pmd->remote_iface, REMOTE_ONLY);
+		if (err <= ETH_SPEED_NUM_NONE)
+			return err;
+		remoteSpeed = (unsigned int) err;
+
+		if ((unsigned int) remoteSpeed != pmd_link.link_speed) {
+			err = tap_speed_set(pmd, pmd->remote_iface,
+				REMOTE_ONLY, pmd_link.link_speed);
+			if (err <= ETH_SPEED_NUM_NONE)
+				return 0;
+
+			remoteSpeed = (int) pmd_link.link_speed;
+		}
+
+		RTE_LOG(INFO, PMD,
+			"Remote ifindex %s; speed %u matches to PMD\n",
+			pmd->remote_iface, remoteSpeed);
+	}
+
+	return pmd_link.link_speed;
+}
+
+static int
 eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 		   char *remote_iface, int fixed_mac_type)
 {
@@ -1403,6 +1577,11 @@ enum ioctl_mode {
 		}
 	}
 
+	if (eth_dev_tap_config_speed(pmd) > 0)
+		data->dev_link = pmd_link;
+	else
+		goto error_exit;
+
 	return 0;
 
 disable_rte_flow:
@@ -1448,7 +1627,7 @@ enum ioctl_mode {
 		    const char *value,
 		    void *extra_args)
 {
-	*(int *)extra_args = (value) ? atoi(value) : ETH_SPEED_NUM_10G;
+	*(int *)extra_args = (value) ? atoi(value) : ETH_SPEED_NUM_10M;
 
 	return 0;
 }
@@ -1493,7 +1672,7 @@ enum ioctl_mode {
 	name = rte_vdev_device_name(dev);
 	params = rte_vdev_device_args(dev);
 
-	speed = ETH_SPEED_NUM_10G;
+	speed = ETH_SPEED_NUM_10M;
 	snprintf(tap_name, sizeof(tap_name), "%s%d",
 		 DEFAULT_TAP_NAME, tap_unit++);
 	memset(remote_iface, 0, RTE_ETH_NAME_MAX_LEN);
-- 
1.9.1

             reply	other threads:[~2017-12-21 11:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-21 16:53 Vipin Varghese [this message]
2017-12-21 13:38 ` Wiles, Keith
2018-01-17 16:06   ` Ferruh Yigit
2018-01-17 16:14     ` Wiles, Keith
2018-01-17 16:22       ` Ferruh Yigit
2018-01-18 14:04         ` Pascal Mazon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1513875200-5061-1-git-send-email-vipin.varghese@intel.com \
    --to=vipin.varghese@intel.com \
    --cc=amol.patel@intel.com \
    --cc=david.hunt@intel.com \
    --cc=deepak.k.jain@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).