From patchwork Thu Nov 7 16:03:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raslan Darawsheh X-Patchwork-Id: 62677 X-Patchwork-Delegate: rasland@nvidia.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0431EA034E; Thu, 7 Nov 2019 17:03:35 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 733E81BF92; Thu, 7 Nov 2019 17:03:35 +0100 (CET) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80053.outbound.protection.outlook.com [40.107.8.53]) by dpdk.org (Postfix) with ESMTP id 9D9FD1BF91 for ; Thu, 7 Nov 2019 17:03:33 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Sug+EN04hauBvwkNi0hv9XknUabCtbUUrk3iY3sS79f6hMnoK/fzDznMRTP0c70+jyxpm9f1KSZR/WC1eWhVaalCruEr7cMMHntYyAdJXWv9qPtAHaLtXitGduS2s/ZLoQpEv5rav2M8mJxjT7x0tEIOOuLIOPd/Kn+X9q8Vm2KvfSCi0Xvlf3T68Y9hsm5fOZbKKeDcO/xRDT1ggEspbCN/MpqWip+oORaMbYB/WAtHnSQ8waz8okCBsxqcysQVSbZaIWnksX+3RidR4NO5x0vYSvXSESqhDpcB3k6d+lhB1BVRHITGcYbnCKvacNlpyBDjX5My2ORzt00f+q6TAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KuHwtsNzZl1MJBX7bDyYMF7VbkSAYSSZpIKzgPQT8kU=; b=GO1rCJZl+j73NqJxNgyp63ficeoibFdMVBAXDdrC4HxXaviaYaJLBQHzD5tv7tTJfKhaRsfDYOzspeKYVilTazBZUPwflfwVppxtIrR2KhAxlG1aeSmhnkZOWiLdWNYtHg6g5aOLAq8zH3kl8eRF+LAzea2Cu5UpqqPor5PuvlOz5D/KbjBTDul28h3mC8MsACSAsJ4jb9+RS3D9yACZQil4x+YKGsMM8Ir9RZm7wfVGwqAxvL1jwkLBpNGZCpeOwEz9BJiI2QiYSEQhSmKhvQPYr/R2zKt9b6PCEBwtsZNqIPIqYqL5AkbRSwPEVEgjyo6050lzz9peZfcFCtdJNw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=mellanox.com; dmarc=pass action=none header.from=mellanox.com; dkim=pass header.d=mellanox.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KuHwtsNzZl1MJBX7bDyYMF7VbkSAYSSZpIKzgPQT8kU=; b=JVq7OxaHDl1LUsDLAezVxQK0zud8xvW2nL5AOGz7pxdHHHxMrE4kLlKZGHPQEqH2tCQRYmY+2ZmWhZhfGFUR2pozvam+mdMsS87Oyfrk2yqAbt37N42REcjfTpZM5dy/d5lEGuKHCfJltzRksPFv4aX3LpYBFd+dcsFlifvu3z8= Received: from DB3PR0502MB3964.eurprd05.prod.outlook.com (52.134.65.161) by DB3PR0502MB3948.eurprd05.prod.outlook.com (52.134.72.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2408.24; Thu, 7 Nov 2019 16:03:32 +0000 Received: from DB3PR0502MB3964.eurprd05.prod.outlook.com ([fe80::a850:bac9:c90f:f2f5]) by DB3PR0502MB3964.eurprd05.prod.outlook.com ([fe80::a850:bac9:c90f:f2f5%6]) with mapi id 15.20.2408.024; Thu, 7 Nov 2019 16:03:32 +0000 From: Raslan Darawsheh To: Slava Ovsiienko CC: Thomas Monjalon , "dev@dpdk.org" , Asaf Penso Thread-Topic: [PATCH] net/mlx5: set VF MAC address from host Thread-Index: AQHVlYTmNZ/lu37WW0qXxNxQIjvfdA== Date: Thu, 7 Nov 2019 16:03:32 +0000 Message-ID: <1573142599-10735-1-git-send-email-rasland@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.7.4 x-clientproxiedby: LNXP265CA0076.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:76::16) To DB3PR0502MB3964.eurprd05.prod.outlook.com (2603:10a6:8:3::33) authentication-results: spf=none (sender IP is ) smtp.mailfrom=rasland@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [212.29.221.74] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: db30a0db-06d8-47dd-7326-08d7639c0959 x-ms-traffictypediagnostic: DB3PR0502MB3948:|DB3PR0502MB3948: x-ms-exchange-purlcount: 2 x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 0214EB3F68 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(396003)(366004)(136003)(376002)(346002)(39850400004)(199004)(189003)(478600001)(14454004)(8936002)(6636002)(71190400001)(6506007)(476003)(71200400001)(966005)(2906002)(6436002)(6486002)(54906003)(486006)(52116002)(3846002)(2616005)(37006003)(4326008)(6512007)(107886003)(305945005)(186003)(36756003)(26005)(25786009)(66066001)(316002)(256004)(14444005)(99286004)(386003)(6306002)(6116002)(66476007)(66556008)(64756008)(66446008)(8676002)(5660300002)(66946007)(81166006)(81156014)(86362001)(50226002)(6862004)(102836004)(7736002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB3PR0502MB3948; H:DB3PR0502MB3964.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: BZ2P6HMJiuaeux83LHliujScDdbJ7Y/Dot8xRkPRX171GJAKaXxB0zgfv5UfX5ZcF6lP+B4tGTgqx14FKeZA+GF9SIA1pUCbw53CvY+kx+UCLZC72QjbxtZJzZfoSFlxSVGcCsMswKU+Mw5bX/O3p3jB2VheJZiSlV+lA4OHaZsuQ5uIYYW6KgFqfNkV/SuHMuVBcqqhvyjgNIom+muzrsJ5GJFpiqeq5GRtPRmKGymuH5tuMVu9nNoRO5Ak6AAYnRUzedni0PKYUtkjB/tm+0OyQ2UWy5Oi/cuOkxIpUQlSIyzyOSpMBeMArc4ykCp6eVfa88cVf1L8ArEoKcKjAIGQbl0723eAMYUG5dcCS/a5K8tqZ3mY0hQCSs1fok8/1RDbuUs8sxHB2fXn5L48AuXp80DWdixJSSiCTxR2u4OdLK2fOrnWKhHg3Lw8U+bOT59GdXnfWAYQ74sRzEUOTay0WJa0NGcSohXofHz7+NE= MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: db30a0db-06d8-47dd-7326-08d7639c0959 X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Nov 2019 16:03:32.1628 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: +a3KK4HHi9pyVgOFHeazw5XfGcFOdLDefomUyAp6jmMkVWEQSqwi8bsxAgEu7aWobBf66xJ95sgePa0+VKK6Gw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3PR0502MB3948 Subject: [dpdk-dev] [PATCH] net/mlx5: set VF MAC address from host 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" Allow to configure the default MAC address of a VF via its representor port in the host. An API was proposed to specify explicitly the VF as a target: https://patches.dpdk.org/patch/62176/ It has been rejected by the technical board in order to keep compatibility with behavior in Intel PMDs. http://mails.dpdk.org/archives/dev/2019-November/150588.html Signed-off-by: Thomas Monjalon Signed-off-by: Raslan Darawsheh --- drivers/net/mlx5/mlx5.h | 2 + drivers/net/mlx5/mlx5_mac.c | 20 +++++++++ drivers/net/mlx5/mlx5_nl.c | 98 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 119 insertions(+), 1 deletion(-) diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index b56dae1..75e20a9 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -938,6 +938,8 @@ int mlx5_nl_promisc(struct rte_eth_dev *dev, int enable); int mlx5_nl_allmulti(struct rte_eth_dev *dev, int enable); unsigned int mlx5_nl_portnum(int nl, const char *name); unsigned int mlx5_nl_ifindex(int nl, const char *name, uint32_t pindex); +int mlx5_nl_vf_mac_addr_modify(struct rte_eth_dev *dev, + struct rte_ether_addr *mac, int vf_index); int mlx5_nl_switch_info(int nl, unsigned int ifindex, struct mlx5_switch_info *info); diff --git a/drivers/net/mlx5/mlx5_mac.c b/drivers/net/mlx5/mlx5_mac.c index 0ffef5c..ca95bd2 100644 --- a/drivers/net/mlx5/mlx5_mac.c +++ b/drivers/net/mlx5/mlx5_mac.c @@ -197,6 +197,26 @@ mlx5_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, int mlx5_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr) { + uint16_t port_id; + struct mlx5_priv *priv = dev->data->dev_private; + + /* Configuring the VF instead of its representor. */ + if (priv->representor_id != -1) { + DRV_LOG(DEBUG, "VF represented by port %u setting primary MAC address", + dev->data->port_id); + RTE_ETH_FOREACH_DEV_SIBLING(port_id, dev->data->port_id) { + priv = rte_eth_devices[port_id].data->dev_private; + if (priv->master == 1) { + priv = dev->data->dev_private; + return mlx5_nl_vf_mac_addr_modify + (&rte_eth_devices[port_id], + mac_addr, priv->representor_id); + } + } + rte_errno = -ENOTSUP; + return rte_errno; + } + DRV_LOG(DEBUG, "port %u setting primary MAC address", dev->data->port_id); return mlx5_mac_addr_add(dev, mac_addr, 0, 0); diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c index 3e073c6..1eff575 100644 --- a/drivers/net/mlx5/mlx5_nl.c +++ b/drivers/net/mlx5/mlx5_nl.c @@ -42,7 +42,15 @@ #define MLX5_NDA_RTA(r) \ ((struct rtattr *)(((char *)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg)))) #endif - +/* + * Define NLMSG_TAIL as defined in iproute2 sources. + * + * see in iproute2 sources file include/libnetlink.h + */ +#ifndef NLMSG_TAIL +#define NLMSG_TAIL(nmsg) \ + ((struct rtattr *)(((char *)(nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len))) +#endif /* * The following definitions are normally found in rdma/rdma_netlink.h, * however they are so recent that most systems do not expose them yet. @@ -494,6 +502,94 @@ mlx5_nl_mac_addr_modify(struct rte_eth_dev *dev, struct rte_ether_addr *mac, } /** + * Modify the VF MAC address neighbour table with Netlink. + * + * @param dev + * Pointer to Ethernet device. + * @param mac + * MAC address to consider. + * @param vf_index + * VF index. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +int +mlx5_nl_vf_mac_addr_modify(struct rte_eth_dev *dev, + struct rte_ether_addr *mac, int vf_index) +{ + int fd, ret; + struct mlx5_priv *priv = dev->data->dev_private; + unsigned int iface_idx = mlx5_ifindex(dev); + struct { + struct nlmsghdr hdr; + struct ifinfomsg ifm; + struct rtattr vf_list_rta; + struct rtattr vf_info_rta; + struct rtattr vf_mac_rta; + struct ifla_vf_mac ivm; + } req = { + .hdr = { + .nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)), + .nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK, + .nlmsg_type = RTM_BASE, + }, + .ifm = { + .ifi_index = iface_idx, + }, + .vf_list_rta = { + .rta_type = IFLA_VFINFO_LIST, + .rta_len = RTA_ALIGN(RTA_LENGTH(0)), + }, + .vf_info_rta = { + .rta_type = IFLA_VF_INFO, + .rta_len = RTA_ALIGN(RTA_LENGTH(0)), + }, + .vf_mac_rta = { + .rta_type = IFLA_VF_MAC, + }, + }; + uint32_t sn = priv->nl_sn++; + struct ifla_vf_mac ivm = { + .vf = vf_index, + }; + + memcpy(&ivm.mac, mac, RTE_ETHER_ADDR_LEN); + memcpy(RTA_DATA(&req.vf_mac_rta), &ivm, sizeof(ivm)); + + req.vf_mac_rta.rta_len = RTA_LENGTH(sizeof(ivm)); + req.hdr.nlmsg_len = NLMSG_ALIGN(req.hdr.nlmsg_len) + + RTA_ALIGN(req.vf_list_rta.rta_len) + + RTA_ALIGN(req.vf_info_rta.rta_len) + + RTA_ALIGN(req.vf_mac_rta.rta_len); + req.vf_list_rta.rta_len = (char *)NLMSG_TAIL(&req.hdr) - + (char *)&req.vf_list_rta; + req.vf_info_rta.rta_len = (char *)NLMSG_TAIL(&req.hdr) - + (char *)&req.vf_info_rta; + + fd = priv->nl_socket_route; + if (fd < 0) + return -1; + ret = mlx5_nl_send(fd, &req.hdr, sn); + if (ret < 0) + goto error; + ret = mlx5_nl_recv(fd, sn, NULL, NULL); + if (ret < 0) + goto error; + return 0; +error: + DRV_LOG(ERR, + "representor %u cannot set VF MAC address " + "%02X:%02X:%02X:%02X:%02X:%02X : %s", + vf_index, + mac->addr_bytes[0], mac->addr_bytes[1], + mac->addr_bytes[2], mac->addr_bytes[3], + mac->addr_bytes[4], mac->addr_bytes[5], + strerror(rte_errno)); + return -rte_errno; +} + +/** * Add a MAC address. * * @param dev