From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 07699A052A; Sun, 19 Jul 2020 09:11:59 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6E8331C065; Sun, 19 Jul 2020 09:11:34 +0200 (CEST) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60072.outbound.protection.outlook.com [40.107.6.72]) by dpdk.org (Postfix) with ESMTP id 5653D1C02A for ; Sun, 19 Jul 2020 09:11:30 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VYdyJeMxP6K5LHXzaLJkFLdqs1V6zCun5+Sepw+WFtUUqbON77HHnOzK3gYVJ9K3AxpVz5RO2uVbTLPu3ijqnYk1SMEOpT7c10bzOQFhNI5JvpmYHMLSQOl9xJQIA/RkawX6yOUDr7SfCKy4Cyjg9iB10m9OB2/D5mkzO55/69k3JMRAMvyzjosUVJZE0QIA8FrXTrXZZm3S/R4stIOO3DjZIgeB59+n8pWD2ToG713OMq9FsH67j8NRj6MD5PkhEuPW38DgM0CPVy1+1Pr/Uow+ZqpazIc5HAJQ7+5q25hGSTDtkYpZrSchqfP5i0xGTWVNTxU9S8NnJYeI6wuIYA== 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=vsGaAdnGdjgeGh89rq6GTOyqtTWLy2y+Qhr0nzSp4fU=; b=fvKdHB+da1ucX6hbx4g8VdFN/ZCNeclJdro2BisQCM3IDoBaMjSI/+6RNO0SHQ7kGMRKbztj0yV48/JO6kbZFLko1NpZ4Ua+PGrD+VWU7GNHrKXz3qBjWizbNy155n4GYDsR9wAh8R1MMGwBg0RbI3vClkgRPpArsGMMuhmZ4uCF7TGutdmNNKkSc9BTEoIkc8B+plOdUALRJAwRv8XsYFo7/oE8GtTcO+N0K8hXGu4xoXINbMOF/LceIviQMuRj3x4+Me+yrDlqA/Lgn3YKNG7buUPah9FBA9uHAD6kgpYL3fJAhFy0eILwZqKZZZjQs62MDEdtBIulZ/QSXZJYPw== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vsGaAdnGdjgeGh89rq6GTOyqtTWLy2y+Qhr0nzSp4fU=; b=SBNux2HExEamlHPpkD7nZBMUEYQrWkU1Kez1eBUcgjmMt97arhlTVUodxfugWodUeyQDj/0BPqDNL2dfe1qhPrav6H4tp8hNPKUQFq803jq5IOp/JXygqUo6u0+wSeUzdY/kFTPjl9Zs6TF1MFP1tFpqn8fO9Lgze4DVO9oemSY= Authentication-Results: dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=none action=none header.from=mellanox.com; Received: from AM0PR05MB4209.eurprd05.prod.outlook.com (2603:10a6:208:61::22) by AM0PR05MB4738.eurprd05.prod.outlook.com (2603:10a6:208:b7::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21; Sun, 19 Jul 2020 07:11:29 +0000 Received: from AM0PR05MB4209.eurprd05.prod.outlook.com ([fe80::3949:70c3:126:3972]) by AM0PR05MB4209.eurprd05.prod.outlook.com ([fe80::3949:70c3:126:3972%7]) with mapi id 15.20.3195.024; Sun, 19 Jul 2020 07:11:29 +0000 From: Ophir Munk To: dev@dpdk.org Cc: Raslan Darawsheh , Ophir Munk , Matan Azrad Date: Sun, 19 Jul 2020 07:11:07 +0000 Message-Id: <20200719071112.8540-4-ophirmu@mellanox.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20200719071112.8540-1-ophirmu@mellanox.com> References: <20200714142102.30606-9-ophirmu@mellanox.com> <20200719071112.8540-1-ophirmu@mellanox.com> Content-Type: text/plain X-ClientProxiedBy: AM0PR04CA0024.eurprd04.prod.outlook.com (2603:10a6:208:122::37) To AM0PR05MB4209.eurprd05.prod.outlook.com (2603:10a6:208:61::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from mellanox.com (37.142.13.130) by AM0PR04CA0024.eurprd04.prod.outlook.com (2603:10a6:208:122::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17 via Frontend Transport; Sun, 19 Jul 2020 07:11:28 +0000 X-Mailer: git-send-email 2.8.4 X-Originating-IP: [37.142.13.130] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d6eef721-7aad-4070-2441-08d82bb2f506 X-MS-TrafficTypeDiagnostic: AM0PR05MB4738: X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtFwd X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2582; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zZ+Y0p91naWu5dvDZI8nCs8T+02DbQ9kr8u19wJbO6PixvHbG6VdrNuRRjWmBTpBuc4whKfqbi3bgCYOw1PQXW3bLPJVbFhHVOs2+TWIDZKIZzawdCWF5h3jyDtckLNXekfV2tfJu5QxVyhnjusDBk4CdcU2lRlfEHGsWLmd0r1GC5R70t2GSWnyFUM7/ircZGlqcwMfmWPMUYotFPsMozydU8pmk3knpYobnQSG2Q4xf9aEOudgddbAd499ocdtwUfqFlLKv2mPKfK1ZH8TSyERVPbFI8c/xhUR9KuuHsXl4AKvD7pjknktKe0kaLpR X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR05MB4209.eurprd05.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(396003)(376002)(39850400004)(346002)(136003)(366004)(52116002)(107886003)(5660300002)(2906002)(316002)(36756003)(8886007)(6666004)(7696005)(6916009)(55016002)(8676002)(478600001)(2616005)(4326008)(66556008)(66476007)(186003)(26005)(66946007)(54906003)(83380400001)(1076003)(86362001)(16526019)(956004)(8936002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: sjz2bN7ZJMJzodZIvWXjacMOfBv+POrzuVZLl8la9vDLqvlMG85KYvcV8c1o7/sGenDZmLfWi7ebmWy82Alpq1XTDV+wdY4VlyOPwZ681AZTIDQLujSCdwnTl5D3+eHHYlHgcbSqBt7PA+omz4uwwC8ZFnB6pcdsAxnRyMm8tbPduva6r8h9JCVz7RacqndHnKuI90E4j0DLTCugF0TSjBEjIDYZ7GqiTaqY/nrnBGy7UhAb4LLyMDTryTA0/VOlU/ayKNVsyukBIpRR84eq73eSKZ7D+NVw57aFwpKZOJr7uemv8Ppkunikx2Z7RAW7VfRuepcYqOAfonwNG6hrl9DrWwz32IoW6oIcPiYJsQ2mnxGS9C8Khc3JqHp7JiPoncTVnWt1ORaEFY1oxyIASAjxZ1uXShbeSn9qka74WYny5sT6RK9hUj7aexF3WnR7go8Ny03/1+zDmivX59/i4O2OkiV1cpNBgcK0H24m1y+wyHTFBDK5aHNGiiy+Sjri X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: d6eef721-7aad-4070-2441-08d82bb2f506 X-MS-Exchange-CrossTenant-AuthSource: AM0PR05MB4209.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2020 07:11:28.9397 (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: iTh9KShMyToDSwy6AaUjCDwkiZB/ututwiqZ9jlQMBZ48Fe4vpKswUlHNpV6LnPLTP61ahQRO/rGw+7aHCbi8Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB4738 Subject: [dpdk-dev] [PATCH v2 3/8] net/mlx5: refactor Linux MAC operations 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" Move OS specific MAC operations add, remove, modify VF into file linux/mlx5_os.c. Remove unused function mlx5_get_mac(). Signed-off-by: Ophir Munk Acked-by: Matan Azrad --- drivers/net/mlx5/linux/mlx5_os.c | 97 ++++++++++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 7 ++- drivers/net/mlx5/mlx5_mac.c | 49 +++----------------- 3 files changed, 110 insertions(+), 43 deletions(-) diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c index 292062e..fda2233 100644 --- a/drivers/net/mlx5/linux/mlx5_os.c +++ b/drivers/net/mlx5/linux/mlx5_os.c @@ -68,6 +68,30 @@ #endif /** + * Get MAC address by querying netdevice. + * + * @param[in] dev + * Pointer to Ethernet device. + * @param[out] mac + * MAC address output buffer. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[RTE_ETHER_ADDR_LEN]) +{ + struct ifreq request; + int ret; + + ret = mlx5_ifreq(dev, SIOCGIFHWADDR, &request); + if (ret) + return ret; + memcpy(mac, request.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN); + return 0; +} + +/** * Get mlx5 device attributes. The glue function query_device_ex() is called * with out parameter of type 'struct ibv_device_attr_ex *'. Then fill in mlx5 * device attributes from the glue out parameter. @@ -2351,6 +2375,79 @@ mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb, *dereg_mr_cb = mlx5_verbs_ops.dereg_mr; } +/** + * Remove a MAC address from device + * + * @param dev + * Pointer to Ethernet device structure. + * @param index + * MAC address index. + */ +void +mlx5_os_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index) +{ + struct mlx5_priv *priv = dev->data->dev_private; + const int vf = priv->config.vf; + + if (vf) + mlx5_nl_mac_addr_remove(priv->nl_socket_route, + mlx5_ifindex(dev), priv->mac_own, + &dev->data->mac_addrs[index], index); +} + +/** + * Adds a MAC address to the device + * + * @param dev + * Pointer to Ethernet device structure. + * @param mac_addr + * MAC address to register. + * @param index + * MAC address index. + * + * @return + * 0 on success, a negative errno value otherwise + */ +int +mlx5_os_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, + uint32_t index) +{ + struct mlx5_priv *priv = dev->data->dev_private; + const int vf = priv->config.vf; + int ret = 0; + + if (vf) + ret = mlx5_nl_mac_addr_add(priv->nl_socket_route, + mlx5_ifindex(dev), priv->mac_own, + mac, index); + return ret; +} + +/** + * Modify a VF MAC address + * + * @param priv + * Pointer to device private data. + * @param mac_addr + * MAC address to modify into. + * @param iface_idx + * Net device interface index + * @param vf_index + * VF index + * + * @return + * 0 on success, a negative errno value otherwise + */ +int +mlx5_os_vf_mac_addr_modify(struct mlx5_priv *priv, + unsigned int iface_idx, + struct rte_ether_addr *mac_addr, + int vf_index) +{ + return mlx5_nl_vf_mac_addr_modify + (priv->nl_socket_route, iface_idx, mac_addr, vf_index); +} + const struct eth_dev_ops mlx5_os_dev_ops = { .dev_configure = mlx5_dev_configure, .dev_start = mlx5_dev_start, diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 9179ad3..ac72e9c 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -859,7 +859,6 @@ int mlx5_dev_configure_rss_reta(struct rte_eth_dev *dev); /* mlx5_mac.c */ -int mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[RTE_ETHER_ADDR_LEN]); void mlx5_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index); int mlx5_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, uint32_t index, uint32_t vmdq); @@ -1024,6 +1023,12 @@ int mlx5_os_get_stats_n(struct rte_eth_dev *dev); void mlx5_os_stats_init(struct rte_eth_dev *dev); void mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb, mlx5_dereg_mr_t *dereg_mr_cb); +void mlx5_os_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index); +int mlx5_os_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, + uint32_t index); +int mlx5_os_vf_mac_addr_modify(struct mlx5_priv *priv, unsigned int iface_idx, + struct rte_ether_addr *mac_addr, + int vf_index); /* mlx5_txpp.c */ diff --git a/drivers/net/mlx5/mlx5_mac.c b/drivers/net/mlx5/mlx5_mac.c index 291f772..2a88086 100644 --- a/drivers/net/mlx5/mlx5_mac.c +++ b/drivers/net/mlx5/mlx5_mac.c @@ -32,30 +32,6 @@ #include "mlx5_rxtx.h" /** - * Get MAC address by querying netdevice. - * - * @param[in] dev - * Pointer to Ethernet device. - * @param[out] mac - * MAC address output buffer. - * - * @return - * 0 on success, a negative errno value otherwise and rte_errno is set. - */ -int -mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[RTE_ETHER_ADDR_LEN]) -{ - struct ifreq request; - int ret; - - ret = mlx5_ifreq(dev, SIOCGIFHWADDR, &request); - if (ret) - return ret; - memcpy(mac, request.ifr_hwaddr.sa_data, RTE_ETHER_ADDR_LEN); - return 0; -} - -/** * Remove a MAC address from the internal array. * * @param dev @@ -66,16 +42,10 @@ mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[RTE_ETHER_ADDR_LEN]) static void mlx5_internal_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index) { - struct mlx5_priv *priv = dev->data->dev_private; - const int vf = priv->config.vf; - MLX5_ASSERT(index < MLX5_MAX_MAC_ADDRESSES); if (rte_is_zero_ether_addr(&dev->data->mac_addrs[index])) return; - if (vf) - mlx5_nl_mac_addr_remove(priv->nl_socket_route, - mlx5_ifindex(dev), priv->mac_own, - &dev->data->mac_addrs[index], index); + mlx5_os_mac_addr_remove(dev, index); memset(&dev->data->mac_addrs[index], 0, sizeof(struct rte_ether_addr)); } @@ -96,9 +66,8 @@ static int mlx5_internal_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, uint32_t index) { - struct mlx5_priv *priv = dev->data->dev_private; - const int vf = priv->config.vf; unsigned int i; + int ret; MLX5_ASSERT(index < MLX5_MAX_MAC_ADDRESSES); if (rte_is_zero_ether_addr(mac)) { @@ -116,14 +85,10 @@ mlx5_internal_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac, rte_errno = EADDRINUSE; return -rte_errno; } - if (vf) { - int ret = mlx5_nl_mac_addr_add(priv->nl_socket_route, - mlx5_ifindex(dev), priv->mac_own, - mac, index); + ret = mlx5_os_mac_addr_add(dev, mac, index); + if (ret) + return ret; - if (ret) - return ret; - } dev->data->mac_addrs[index] = *mac; return 0; } @@ -210,8 +175,8 @@ mlx5_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr) 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 - (priv->nl_socket_route, + return mlx5_os_vf_mac_addr_modify + (priv, mlx5_ifindex(&rte_eth_devices[port_id]), mac_addr, priv->representor_id); } -- 2.8.4