From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wg0-f53.google.com (mail-wg0-f53.google.com [74.125.82.53]) by dpdk.org (Postfix) with ESMTP id 53D88C444 for ; Tue, 30 Jun 2015 11:28:39 +0200 (CEST) Received: by wguu7 with SMTP id u7so4195128wgu.3 for ; Tue, 30 Jun 2015 02:28:39 -0700 (PDT) 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=FmV1mzr5drhojvEwqVvUjue8vt3lf/J+a/sakAnVBC8=; b=Xl8N8Cf5NRFMA8sWhicOaeMQ7P3dNhrAQWH+UfIY7yEAjzbxVn+3WsrlZiZUahFIZg CEwK0LkU7BQZVINlwjfG/36DQjm+gRjf+003p391Efu7VrQc5fhcgM5opSTiTzzZq+4d 4rgxWl9nrUzUr3BNW7clpOFX1lRtfGAgnf0BstRO695eoECy7v2W9ZNpWDkSttuK7azu XOdznrk166FYam8FUp8DmO6ZoKLAlvcn5ldghG277SCDvtKVs5PiY2yXM0/cGL8Xf8+w QPGL36vY44OzrnqZF0+L6fUUA3HbZymrt2SLnMF7Z9gybuP7YYDY3MIbxo4fXH9OPLSI PCjg== X-Gm-Message-State: ALoCoQkafZlhIRuCvF39IKRWUkmITibjWdY77YKUnJFG5S25YNMd5zegtXi804H5mgMZm6iDxdej X-Received: by 10.194.109.229 with SMTP id hv5mr39452382wjb.119.1435656519189; Tue, 30 Jun 2015 02:28:39 -0700 (PDT) Received: from 6wind.com (6wind.net2.nerim.net. [213.41.151.210]) by mx.google.com with ESMTPSA id p2sm16079753wix.11.2015.06.30.02.28.38 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 30 Jun 2015 02:28:38 -0700 (PDT) From: Adrien Mazarguil To: dev@dpdk.org Date: Tue, 30 Jun 2015 11:27:53 +0200 Message-Id: <1435656489-27986-8-git-send-email-adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1435656489-27986-1-git-send-email-adrien.mazarguil@6wind.com> References: <1433546120-2254-1-git-send-email-adrien.mazarguil@6wind.com> <1435656489-27986-1-git-send-email-adrien.mazarguil@6wind.com> Cc: Alex Rosenbaum Subject: [dpdk-dev] [PATCH v2 07/23] mlx4: improve accuracy of link status information X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Jun 2015 09:28:39 -0000 From: Olga Shern Query interface properties using the ethtool API instead of Verbs through ibv_query_port(). The returned information is more accurate for Ethernet links since several link speeds cannot be mapped to Verbs semantics. Signed-off-by: Olga Shern Signed-off-by: Alex Rosenbaum Signed-off-by: Adrien Mazarguil --- drivers/net/mlx4/mlx4.c | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c index ed68beb..02dd894 100644 --- a/drivers/net/mlx4/mlx4.c +++ b/drivers/net/mlx4/mlx4.c @@ -254,7 +254,6 @@ struct priv { struct rte_eth_dev *dev; /* Ethernet device. */ struct ibv_context *ctx; /* Verbs context. */ struct ibv_device_attr device_attr; /* Device properties. */ - struct ibv_port_attr port_attr; /* Physical port properties. */ struct ibv_pd *pd; /* Protection Domain. */ /* * MAC addresses array and configuration bit-field. @@ -3820,29 +3819,37 @@ static int mlx4_link_update_unlocked(struct rte_eth_dev *dev, int wait_to_complete) { struct priv *priv = dev->data->dev_private; - struct ibv_port_attr port_attr; - static const uint8_t width_mult[] = { - /* Multiplier values taken from devinfo.c in libibverbs. */ - 0, 1, 4, 0, 8, 0, 0, 0, 12, 0 + struct ethtool_cmd edata = { + .cmd = ETHTOOL_GSET }; + struct ifreq ifr; + struct rte_eth_link dev_link; + int link_speed = 0; (void)wait_to_complete; - errno = ibv_query_port(priv->ctx, priv->port, &port_attr); - if (errno) { - WARN("port query failed: %s", strerror(errno)); + if (priv_ifreq(priv, SIOCGIFFLAGS, &ifr)) { + WARN("ioctl(SIOCGIFFLAGS) failed: %s", strerror(errno)); return -1; } - dev->data->dev_link = (struct rte_eth_link){ - .link_speed = (ibv_rate_to_mbps(mult_to_ibv_rate - (port_attr.active_speed)) * - width_mult[(port_attr.active_width % - sizeof(width_mult))]), - .link_duplex = ETH_LINK_FULL_DUPLEX, - .link_status = (port_attr.state == IBV_PORT_ACTIVE) - }; - if (memcmp(&port_attr, &priv->port_attr, sizeof(port_attr))) { + memset(&dev_link, 0, sizeof(dev_link)); + dev_link.link_status = ((ifr.ifr_flags & IFF_UP) && + (ifr.ifr_flags & IFF_RUNNING)); + ifr.ifr_data = &edata; + if (priv_ifreq(priv, SIOCETHTOOL, &ifr)) { + WARN("ioctl(SIOCETHTOOL, ETHTOOL_GSET) failed: %s", + strerror(errno)); + return -1; + } + link_speed = ethtool_cmd_speed(&edata); + if (link_speed == -1) + dev_link.link_speed = 0; + else + dev_link.link_speed = link_speed; + dev_link.link_duplex = ((edata.duplex == DUPLEX_HALF) ? + ETH_LINK_HALF_DUPLEX : ETH_LINK_FULL_DUPLEX); + if (memcmp(&dev_link, &dev->data->dev_link, sizeof(dev_link))) { /* Link status changed. */ - priv->port_attr = port_attr; + dev->data->dev_link = dev_link; return 0; } /* Link status is still the same. */ @@ -4487,7 +4494,6 @@ mlx4_pci_devinit(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) priv->ctx = ctx; priv->device_attr = device_attr; - priv->port_attr = port_attr; priv->port = port; priv->pd = pd; priv->mtu = ETHER_MTU; -- 2.1.0