From patchwork Tue Mar 13 12:50:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?N=C3=A9lio_Laranjeiro?= X-Patchwork-Id: 36055 X-Patchwork-Delegate: shahafs@mellanox.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 07F6CA49C; Tue, 13 Mar 2018 13:52:04 +0100 (CET) Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by dpdk.org (Postfix) with ESMTP id C8CCF7272 for ; Tue, 13 Mar 2018 13:51:59 +0100 (CET) Received: by mail-wr0-f193.google.com with SMTP id z12so22342923wrg.4 for ; Tue, 13 Mar 2018 05:51:59 -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 :in-reply-to:references; bh=9FrTFi4hj97UMw4wkcf633WE6E70ji/wgIui/TeuUuY=; b=mE044uPhlCNwHn56p+1bErDg0DPG4+5cNjVF7zu5sYOdTBLTkQcSd8LU/fxMPH2CXH HiWfE4ZHuGnVBqrRHPuIMLgdM5ZbEOYxMJTyJv3z85hndYBFKxOBVhykJMGsN5q/5xkG JvxT8O4vm0e30nueKNM6obt6pK7WN+x0yBPsN6z/s+PB9IxSoyBaaUTBNHDa/dLBGrAZ nD66uIm3HXSMle2KlW9aMzTqvMm6H4PyAvUAHBn0WvQt9rNDGL6SO1khULk+s2f/At75 sCU3dpXkzKwLMZAgbttFfvXOpD2qEKCdVjiNMQCp7kUd9o8VywZBfan18z/FvrcEf9eu X4og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=9FrTFi4hj97UMw4wkcf633WE6E70ji/wgIui/TeuUuY=; b=pJ9qrPKLmVlJsUQ+mUhcZ7GJAodvkpqemM5dp+vE0vcU2Byut8Kxz8NaZ/Bn3mSSmM 4mf6mLb0mNHkWhBavYVHbWuzHOTO8zgU9diLvfLFSj9l0WbTSKonwyYogHWuatx/hTBe GvP9rRgoYRwIuBvrPYhsx0MK9oyfiX6Xnu2HeHitAkYeV8lEmki7H8/3G0bT/dDzDSJf LHFIud8CEtTzaeuYiOt+AhVtQ+/1HlDSqAX64A4uqW3xRkLiO3Uecv1d04C8XcUGFTod P9Z/NsqIT1ecYhVQ1ATOT5OcUDPfvpvaOBc/uggmSAg2447FDRY9+wtn/jsoE6rqghO0 Rafw== X-Gm-Message-State: AElRT7EBjK8PfdRMNRnJV6Jv8iegXjC7BqvHle/yRKtOyYt2eLrb+zb2 0WythCn/V73YHoAzfU4Vbg/V X-Google-Smtp-Source: AG47ELtRuA1gZnmk0zJ9LDPe8eiJA/5IRmI68Y/C3G6pqLWh7IkUGCefL/XLe+P8yqmL8daRMS1szQ== X-Received: by 10.28.230.147 with SMTP id e19mr750355wmi.2.1520945519427; Tue, 13 Mar 2018 05:51:59 -0700 (PDT) Received: from laranjeiro-vm.dev.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id f8sm202350wmc.1.2018.03.13.05.51.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Mar 2018 05:51:58 -0700 (PDT) From: Nelio Laranjeiro To: Adrien Mazarguil , Yongseok Koh Cc: dev@dpdk.org Date: Tue, 13 Mar 2018 13:50:36 +0100 Message-Id: <205f899062e6acf2d8886bbbd6dac159023a2c04.1520944256.git.nelio.laranjeiro@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH 2/5] net/mlx5: retrieve device index from Netlink 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 patch new file is not compiled yet, it starts a series necessary to fix some issues with VF devices. Signed-off-by: Nelio Laranjeiro --- drivers/net/mlx5/mlx5_vf.c | 134 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 drivers/net/mlx5/mlx5_vf.c diff --git a/drivers/net/mlx5/mlx5_vf.c b/drivers/net/mlx5/mlx5_vf.c new file mode 100644 index 000000000..357407f56 --- /dev/null +++ b/drivers/net/mlx5/mlx5_vf.c @@ -0,0 +1,134 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2018 6WIND S.A. + * Copyright 2018 Mellanox Technologies, Ltd. + */ + +#include +#include + +#include + +#include "mlx5.h" +#include "mlx5_utils.h" + +/* Data exchanged between Netlink library and PMD. */ +struct mlx5_vf_iface { + struct rte_eth_dev *dev; /**< Pointer to Ethernet device. */ + int iface_idx; /**< Network Interface index. */ +}; + +/** + * Parse Netlink message to retrieve the interface index. + * + * @param nh + * Pointer to Netlink Message Header. + * @param arg + * PMD data register with this callback. + * + * @return + * 0 on success, -1 otherwise. + */ +static int +mlx5_vf_iface_idx_cb(struct nlmsghdr *nh, void *arg) +{ + struct mlx5_vf_iface *data = arg; + struct rte_eth_dev *dev = data->dev; + const struct ether_addr *mac = &dev->data->mac_addrs[0]; + struct ifinfomsg *iface; + struct rtattr *attribute; + int len; + + /** + * Leave right away if the index does not match its initialised value. + * Interface index has already been found. + */ + if (data->iface_idx != -1) + return 0; + iface = NLMSG_DATA(nh); + len = nh->nlmsg_len - NLMSG_LENGTH(sizeof(*iface)); + for (attribute = IFLA_RTA(iface); + RTA_OK(attribute, len); + attribute = RTA_NEXT(attribute, len)) { + if (attribute->rta_type == IFLA_ADDRESS && + !memcmp(RTA_DATA(attribute), mac, ETHER_ADDR_LEN)) { +#ifndef NDEBUG + struct ether_addr m; + + memcpy(&m, RTA_DATA(attribute), ETHER_ADDR_LEN); + DRV_LOG(DEBUG, + "port %u interace %d MAC address" + " %02X:%02X:%02X:%02X:%02X:%02X", + dev->data->port_id, + iface->ifi_index, + m.addr_bytes[0], m.addr_bytes[1], + m.addr_bytes[2], m.addr_bytes[3], + m.addr_bytes[4], m.addr_bytes[5]); +#endif + data->iface_idx = iface->ifi_index; + return 0; + } + } + data->iface_idx = -1; + return 0; +} + +/** + * Retrieve interface Netlink interface index. + * + * @param dev + * Pointer to Ethernet device. + * + * @return + * Interface index, a negative errno value otherwise and rte_errno is set. + */ +static int +mlx5_vf_iface_idx(struct rte_eth_dev *dev) +{ + struct nl_req { + struct nlmsghdr hdr; + struct rtgenmsg gen; + } req = { + .hdr = { + .nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg)), + .nlmsg_type = RTM_GETLINK, + .nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP | NLM_F_ROOT, + }, + .gen = { + .rtgen_family = AF_UNSPEC, + }, + }; + struct mlx5_vf_iface data = { + .dev = dev, + .iface_idx = -1, + }; + int fd; + int ret; + + fd = rte_nl_init(RTMGRP_LINK); + if (fd < 0) { + rte_errno = errno; + goto error; + } + ret = rte_nl_send(fd, &req.hdr); + if (ret == -1) { + rte_errno = errno; + goto error; + } + ret = rte_nl_recv(fd, mlx5_vf_iface_idx_cb, &data); + if (ret == -1) { + rte_errno = errno; + goto error; + } + rte_nl_final(fd); + if (data.iface_idx == -1) { + rte_errno = EAGAIN; + goto error; + } + return data.iface_idx; +error: + if (fd >= 0) + rte_nl_final(fd); + DRV_LOG(DEBUG, "port %u cannot retrieve Netlink Interface index %s", + dev->data->port_id, strerror(rte_errno)); + return -rte_errno; +}