From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com [209.85.212.177]) by dpdk.org (Postfix) with ESMTP id 7404D9269 for ; Fri, 30 Oct 2015 19:53:34 +0100 (CET) Received: by wijp11 with SMTP id p11so17120878wij.0 for ; Fri, 30 Oct 2015 11:53:34 -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=6v9GsRqLl5tR762tsDUJwqx163bGH5LNaT1fXExBJjs=; b=S0f23UhDMWPSZWv/T/hYtCNWXW8sfPu7ZTVros4OTH7SN8vcPG2N+UaxefBpLM6SNi VxPyWqvRK3eVy+R4kksHZcsup16RqU5aVUj7W4VFVhOlgKIx313vGvT0lOX+lJ0z8DiR 1kIzjeUpBMDF43396/1NbkJIZkKC/QPy1Bilh3kxIZ4I3k5OYebO31Aq5fM1HTpHMUZM 9smr14YLof/PdHCRGDOxHf7KpuV8i7/Jo5YQVIMQwnhMnbJJOX6oHTaHA4JO3GSImXMs CmryXkjaHf0E02rMHnIVTVuleWRfC2jON8XIYzzWD/kS9xigMeuc38oVG5MPqLzVzKFW 9Mvw== 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=6v9GsRqLl5tR762tsDUJwqx163bGH5LNaT1fXExBJjs=; b=dIKbpRX8VKdmCCDz8n3RefLPrSzSInjQcl4oA3L72hwmzIRt4GDvv7DZWuRjP3pIIF NJ9HPCESrpjhjnjzu5nhM9mGbkIWyZeMkoCju6NQK/8RbRJ5JA34Q9IQ/jUo9ovZK2Pg DgJ/KYcMqjGS5GpXKc5qp0HjigrdZycAp6a3gin8qnL0Mf+krijGwQakWdTIHeI7cX2/ r+Dw9LhjJGeMTmJs0ou6Zamlmdh3qnCi0GBFTD4c/AupJdazd1qFjI3LSOABFIaHK9Ue PtEok2RITOo3HpxpX7aIzrbhhdTWQbyZXwKAcqEyat3j1+vgqiyydydsJ1v1CaphxpPu mLTw== X-Gm-Message-State: ALoCoQlT55bu9i2SUVnsPu9nTMMooZW6kkbZKGBRBRks/VDe96eJAvaEeJGRgByzd9onA2m+ONmV X-Received: by 10.194.92.138 with SMTP id cm10mr10300582wjb.6.1446231214318; Fri, 30 Oct 2015 11:53:34 -0700 (PDT) Received: from 6wind.com (guy78-3-82-239-227-177.fbx.proxad.net. [82.239.227.177]) by smtp.gmail.com with ESMTPSA id q141sm4236681wmg.3.2015.10.30.11.53.33 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 30 Oct 2015 11:53:33 -0700 (PDT) From: Adrien Mazarguil To: dev@dpdk.org Date: Fri, 30 Oct 2015 19:52:38 +0100 Message-Id: <1446231162-8075-10-git-send-email-adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1446231162-8075-1-git-send-email-adrien.mazarguil@6wind.com> References: <1444067589-29513-1-git-send-email-adrien.mazarguil@6wind.com> <1446231162-8075-1-git-send-email-adrien.mazarguil@6wind.com> Subject: [dpdk-dev] [PATCH v2 09/13] mlx5: add link update device operation 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: Fri, 30 Oct 2015 18:53:34 -0000 Link information is retrieved using ethtool ioctls. Signed-off-by: Adrien Mazarguil Signed-off-by: Nelio Laranjeiro --- drivers/net/mlx5/mlx5.c | 1 + drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_ethdev.c | 71 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index ee63bdf..5ed828d 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -137,6 +137,7 @@ static const struct eth_dev_ops mlx5_dev_ops = { .promiscuous_disable = mlx5_promiscuous_disable, .allmulticast_enable = mlx5_allmulticast_enable, .allmulticast_disable = mlx5_allmulticast_disable, + .link_update = mlx5_link_update, .stats_get = mlx5_stats_get, .stats_reset = mlx5_stats_reset, .dev_infos_get = mlx5_dev_infos_get, diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 56da43c..1a18326 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -164,6 +164,7 @@ int priv_get_mtu(struct priv *, uint16_t *); int priv_set_flags(struct priv *, unsigned int, unsigned int); int mlx5_dev_configure(struct rte_eth_dev *); void mlx5_dev_infos_get(struct rte_eth_dev *, struct rte_eth_dev_info *); +int mlx5_link_update(struct rte_eth_dev *, int); int mlx5_dev_set_mtu(struct rte_eth_dev *, uint16_t); int mlx5_ibv_device_to_pci_addr(const struct ibv_device *, struct rte_pci_addr *); diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c index 26b6d73..d01dee5 100644 --- a/drivers/net/mlx5/mlx5_ethdev.c +++ b/drivers/net/mlx5/mlx5_ethdev.c @@ -45,6 +45,8 @@ #include #include #include +#include +#include /* DPDK headers don't like -pedantic. */ #ifdef PEDANTIC @@ -535,6 +537,75 @@ mlx5_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info) } /** + * DPDK callback to retrieve physical link information (unlocked version). + * + * @param dev + * Pointer to Ethernet device structure. + * @param wait_to_complete + * Wait for request completion (ignored). + */ +static int +mlx5_link_update_unlocked(struct rte_eth_dev *dev, int wait_to_complete) +{ + struct priv *priv = dev->data->dev_private; + struct ethtool_cmd edata = { + .cmd = ETHTOOL_GSET + }; + struct ifreq ifr; + struct rte_eth_link dev_link; + int link_speed = 0; + + (void)wait_to_complete; + if (priv_ifreq(priv, SIOCGIFFLAGS, &ifr)) { + WARN("ioctl(SIOCGIFFLAGS) failed: %s", strerror(errno)); + return -1; + } + 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. */ + dev->data->dev_link = dev_link; + return 0; + } + /* Link status is still the same. */ + return -1; +} + +/** + * DPDK callback to retrieve physical link information. + * + * @param dev + * Pointer to Ethernet device structure. + * @param wait_to_complete + * Wait for request completion (ignored). + */ +int +mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete) +{ + struct priv *priv = dev->data->dev_private; + int ret; + + priv_lock(priv); + ret = mlx5_link_update_unlocked(dev, wait_to_complete); + priv_unlock(priv); + return ret; +} + +/** * DPDK callback to change the MTU. * * Setting the MTU affects hardware MRU (packets larger than the MTU cannot be -- 2.1.0