From patchwork Fri Jul 19 05:31:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slava Ovsiienko X-Patchwork-Id: 56750 X-Patchwork-Delegate: rasland@nvidia.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 98082374E; Fri, 19 Jul 2019 07:32:04 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id F14121B53 for ; Fri, 19 Jul 2019 07:32:03 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE2 (envelope-from viacheslavo@mellanox.com) with ESMTPS (AES256-SHA encrypted); 19 Jul 2019 08:32:01 +0300 Received: from pegasus12.mtr.labs.mlnx. (pegasus12.mtr.labs.mlnx [10.210.17.40]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x6J5VwI5017766; Fri, 19 Jul 2019 08:32:01 +0300 From: Viacheslav Ovsiienko To: dev@dpdk.org Cc: yskoh@mellanox.com, shahafs@mellanox.com, stephen@networkplumber.org Date: Fri, 19 Jul 2019 05:31:44 +0000 Message-Id: <1563514305-27405-2-git-send-email-viacheslavo@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1563514305-27405-1-git-send-email-viacheslavo@mellanox.com> References: <20190712205425.17781-3-stephen@networkplumber.org> <1563514305-27405-1-git-send-email-viacheslavo@mellanox.com> Subject: [dpdk-dev] [PATCH 1/2] net/mlx5: cache the associated network device ifindex X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The associated device index is retrieved via Netlink request to underlying Infiniband device driver. This network device index is permanent throughout the lifetime of device. We do not spawn the rte_eth_dev ports without associated network device, and if network device is being unbound we get the remove notification message and rte_eth_dev port is also detached. So, we may store the ifindex in mlx5_device_spawn() routine at rte_eth_dev port creation and initialization time and use the cached value further instead of doing actual Netlink request. Signed-off-by: Viacheslav Ovsiienko --- drivers/net/mlx5/mlx5.c | 11 +++++++++++ drivers/net/mlx5/mlx5.h | 1 + drivers/net/mlx5/mlx5_ethdev.c | 19 +++++++------------ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 608daed..4d1edd8 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -1630,6 +1630,17 @@ struct mlx5_dev_spawn_data { eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR; eth_dev->data->representor_id = priv->representor_id; } + /* + * Store associated network device interface index. This index + * is permanent throughout the lifetime of device. We do not spawn + * rte_eth_dev ports without associated network device, and if + * network device is being unbound we get the remove notification + * message and rte_eth_dev port is also detached. So, we may store + * the ifindex here and use the cached value further. The network + * device name can be changed dynamically and should not be cached. + */ + assert(spawn->ifindex); + priv->if_index = spawn->ifindex; eth_dev->data->dev_private = priv; priv->dev_data = eth_dev->data; eth_dev->data->mac_addrs = priv->mac; diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index f254c8d..4ae6738 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -465,6 +465,7 @@ struct mlx5_priv { uint16_t domain_id; /* Switch domain identifier. */ uint16_t vport_id; /* Associated VF vport index (if any). */ int32_t representor_id; /* Port representor identifier. */ + unsigned int if_index; /* Associated kernel network device index. */ /* RX/TX queues. */ unsigned int rxqs_n; /* RX queues array size. */ unsigned int txqs_n; /* TX queues array size. */ diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c index fdd6e03..3803be3 100644 --- a/drivers/net/mlx5/mlx5_ethdev.c +++ b/drivers/net/mlx5/mlx5_ethdev.c @@ -225,10 +225,7 @@ struct ethtool_link_settings { assert(priv); assert(priv->sh); - ifindex = priv->nl_socket_rdma >= 0 ? - mlx5_nl_ifindex(priv->nl_socket_rdma, - priv->sh->ibdev_name, - priv->ibv_port) : 0; + ifindex = mlx5_ifindex(dev); if (!ifindex) { if (!priv->representor) return mlx5_get_master_ifname(priv->sh->ibdev_path, @@ -299,14 +296,14 @@ struct ethtool_link_settings { unsigned int mlx5_ifindex(const struct rte_eth_dev *dev) { - char ifname[IF_NAMESIZE]; + struct mlx5_priv *priv = dev->data->dev_private; unsigned int ifindex; - if (mlx5_get_ifname(dev, &ifname)) - return 0; - ifindex = if_nametoindex(ifname); + assert(priv); + assert(priv->if_index); + ifindex = priv->if_index; if (!ifindex) - rte_errno = errno; + rte_errno = ENXIO; return ifindex; } @@ -641,7 +638,6 @@ struct ethtool_link_settings { struct mlx5_priv *priv = dev->data->dev_private; struct mlx5_dev_config *config = &priv->config; unsigned int max; - char ifname[IF_NAMESIZE]; /* FIXME: we should ask the device for these values. */ info->min_rx_bufsize = 32; @@ -662,8 +658,7 @@ struct ethtool_link_settings { info->rx_offload_capa = (mlx5_get_rx_port_offloads() | info->rx_queue_offload_capa); info->tx_offload_capa = mlx5_get_tx_port_offloads(dev); - if (mlx5_get_ifname(dev, &ifname) == 0) - info->if_index = if_nametoindex(ifname); + info->if_index = mlx5_ifindex(dev); info->reta_size = priv->reta_idx_n ? priv->reta_idx_n : config->ind_table_max_size; info->hash_key_size = MLX5_RSS_HASH_KEY_LEN; From patchwork Fri Jul 19 05:31:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slava Ovsiienko X-Patchwork-Id: 56751 X-Patchwork-Delegate: rasland@nvidia.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1CF267CBC; Fri, 19 Jul 2019 07:32:10 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 90ED61B53 for ; Fri, 19 Jul 2019 07:32:08 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE2 (envelope-from viacheslavo@mellanox.com) with ESMTPS (AES256-SHA encrypted); 19 Jul 2019 08:32:06 +0300 Received: from pegasus12.mtr.labs.mlnx. (pegasus12.mtr.labs.mlnx [10.210.17.40]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x6J5VwI6017766; Fri, 19 Jul 2019 08:32:06 +0300 From: Viacheslav Ovsiienko To: dev@dpdk.org Cc: yskoh@mellanox.com, shahafs@mellanox.com, stephen@networkplumber.org Date: Fri, 19 Jul 2019 05:31:45 +0000 Message-Id: <1563514305-27405-3-git-send-email-viacheslavo@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1563514305-27405-1-git-send-email-viacheslavo@mellanox.com> References: <20190712205425.17781-3-stephen@networkplumber.org> <1563514305-27405-1-git-send-email-viacheslavo@mellanox.com> Subject: [dpdk-dev] [PATCH 2/2] Revert "net/mlx5: fix master device Netlink socket sharing" X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This reverts commit e28111ac9864af09e826241a915dfff87a9c00ad. The netlink requests are replaced by ifindex caching and not needed anymore. Signed-off-by: Viacheslav Ovsiienko Fixes: e28111ac9864 ("net/mlx5: fix master device Netlink socket sharing") --- drivers/net/mlx5/mlx5.h | 6 --- drivers/net/mlx5/mlx5_ethdev.c | 109 ++--------------------------------------- 2 files changed, 3 insertions(+), 112 deletions(-) diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 4ae6738..b150107 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -518,15 +518,9 @@ struct mlx5_priv { /* mlx5_ethdev.c */ int mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[IF_NAMESIZE]); -int mlx5_get_ifname_base(const struct rte_eth_dev *base, - const struct rte_eth_dev *dev, - char (*ifname)[IF_NAMESIZE]); int mlx5_get_master_ifname(const char *ibdev_path, char (*ifname)[IF_NAMESIZE]); unsigned int mlx5_ifindex(const struct rte_eth_dev *dev); int mlx5_ifreq(const struct rte_eth_dev *dev, int req, struct ifreq *ifr); -int mlx5_ifreq_base(const struct rte_eth_dev *base, - const struct rte_eth_dev *dev, - int req, struct ifreq *ifr); int mlx5_get_mtu(struct rte_eth_dev *dev, uint16_t *mtu); int mlx5_set_flags(struct rte_eth_dev *dev, unsigned int keep, unsigned int flags); diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c index 3803be3..e418676 100644 --- a/drivers/net/mlx5/mlx5_ethdev.c +++ b/drivers/net/mlx5/mlx5_ethdev.c @@ -240,51 +240,6 @@ struct ethtool_link_settings { } /** - * Get interface name for the specified device, uses the extra base - * device resources to perform Netlink requests. - * - * This is a port representor-aware version of mlx5_get_master_ifname(). - * - * @param[in] base - * Pointer to Ethernet device to use Netlink socket from - * to perfrom requests. - * @param[in] dev - * Pointer to Ethernet device. - * @param[out] ifname - * Interface name output buffer. - * - * @return - * 0 on success, a negative errno value otherwise and rte_errno is set. - */ -int -mlx5_get_ifname_base(const struct rte_eth_dev *base, - const struct rte_eth_dev *dev, - char (*ifname)[IF_NAMESIZE]) -{ - struct mlx5_priv *priv = dev->data->dev_private; - struct mlx5_priv *priv_base = base->data->dev_private; - unsigned int ifindex; - - assert(priv); - assert(priv->sh); - assert(priv_base); - ifindex = priv_base->nl_socket_rdma >= 0 ? - mlx5_nl_ifindex(priv_base->nl_socket_rdma, - priv->sh->ibdev_name, - priv->ibv_port) : 0; - if (!ifindex) { - if (!priv->representor) - return mlx5_get_master_ifname(priv->sh->ibdev_path, - ifname); - rte_errno = ENXIO; - return -rte_errno; - } - if (if_indextoname(ifindex, &(*ifname)[0])) - return 0; - rte_errno = errno; - return -rte_errno; -} -/** * Get the interface index from device name. * * @param[in] dev @@ -346,51 +301,6 @@ struct ethtool_link_settings { } /** - * Perform ifreq ioctl() on specified Ethernet device, - * ifindex, name and other attributes are requested - * on the base device to avoid specified device Netlink - * socket sharing (this is not thread-safe). - * - * @param[in] base - * Pointer to Ethernet device to get dev attributes. - * @param[in] dev - * Pointer to Ethernet device to perform ioctl. - * @param req - * Request number to pass to ioctl(). - * @param[out] ifr - * Interface request structure output buffer. - * - * @return - * 0 on success, a negative errno value otherwise and rte_errno is set. - */ -int -mlx5_ifreq_base(const struct rte_eth_dev *base, - const struct rte_eth_dev *dev, - int req, struct ifreq *ifr) -{ - int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); - int ret = 0; - - if (sock == -1) { - rte_errno = errno; - return -rte_errno; - } - ret = mlx5_get_ifname_base(base, dev, &ifr->ifr_name); - if (ret) - goto error; - ret = ioctl(sock, req, ifr); - if (ret == -1) { - rte_errno = errno; - goto error; - } - close(sock); - return 0; -error: - close(sock); - return -rte_errno; -} - -/** * Get device MTU. * * @param dev @@ -872,15 +782,7 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size) ifr = (struct ifreq) { .ifr_data = (void *)&edata, }; - /* - * Use special version of mlx5_ifreq() - * to get master device name with local - * device Netlink socket. Using master - * device Netlink socket is not thread - * safe. - */ - ret = mlx5_ifreq_base(dev, master, - SIOCETHTOOL, &ifr); + ret = mlx5_ifreq(master, SIOCETHTOOL, &ifr); } } if (ret) { @@ -977,12 +879,7 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size) ifr = (struct ifreq) { .ifr_data = (void *)&gcmd, }; - /* - * Avoid using master Netlink socket. - * This is not thread-safe. - */ - ret = mlx5_ifreq_base(dev, master, - SIOCETHTOOL, &ifr); + ret = mlx5_ifreq(master, SIOCETHTOOL, &ifr); } } if (ret) { @@ -1003,7 +900,7 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size) *ecmd = gcmd; ifr.ifr_data = (void *)ecmd; - ret = mlx5_ifreq_base(dev, master ? master : dev, SIOCETHTOOL, &ifr); + ret = mlx5_ifreq(master ? master : dev, SIOCETHTOOL, &ifr); if (ret) { DRV_LOG(DEBUG, "port %u ioctl(SIOCETHTOOL,"