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 1FF93A0540; Tue, 14 Jul 2020 16:21:43 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D87C91D544; Tue, 14 Jul 2020 16:21:16 +0200 (CEST) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60045.outbound.protection.outlook.com [40.107.6.45]) by dpdk.org (Postfix) with ESMTP id D53201D523 for ; Tue, 14 Jul 2020 16:21:12 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UF51bhjZJiCOGdxWO3RCbI0PP5S5b70cptx6afibv/bPfb2aMg3geAbXprTkhJj5XJMyuagvbF11gljS4EP3kKTms1ielIGRGLXmy58M+leoy/h+fsk+p2mbJYTXO0w0KTN7pVDf3kkaZswxzBEtwWbpFwOHoOhQw7z035ZYEKMu0RdMLmLACmZG8ike4cimBcHSPbtdYKR1UotIZZCUrVs2IR1qTMkHYAN1j2jJyX41PhCVKxp+UevIXdFzyN9EuXe/oOnnQJ/MQaEl4T8F3ngg/CdiCwEGTG6ucdEByPHem/M7FObMunCXUX3vbaNsQVUITUYRu1IvNPlqlKbHlA== 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=piXUODgbXzfVb2+PeQ2YmKNu24wYUwcnORMyYl+F7sQ=; b=epWzcIr2gcFpzJiHNFZzcHvxvFLFlVM3h7zfwQcXEN7QFGmUQxeWKatNuEIqUq3Uo4zaewr6L2L+hQ/4D23/MX/CDjCd2ESnbiW3QRtrtqsTaCXd71d6iDXV8TkvBBIU3+iyCJmbXQOQj2bqMPFN6VwXRg+xwTPHbVxeJweJBY9RwIhI/L31w5S/xk6N8rxO/2mzxOKDwe6j5C82VF6B7a2BuFNca7GymUKZdyFSMsdOIRETmOA/4NDupg3nGwu2won4fUyP0rq7bQNX476XfEejjuALYZ46552qD1W2VtZgQnwqnxot2yHqjLjFk+ovYvAjoCkhs0hAdHxaKl7Qdg== 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=piXUODgbXzfVb2+PeQ2YmKNu24wYUwcnORMyYl+F7sQ=; b=XGIFRfSLGkDLSKZ+lzdSLXrNqm1A9Rs/WHc53He86Ph7hmfsFxL42HU6bHXHiYIaYBfvF1jaHwo+ibQMryamjn2g5V44zOKsXopknBr5/6W/0sbnSTZF0sUEZFFvODv6LF2gSMBqlOc4BjHa6D5CaNtz4lGTSRrwWmCHwE78VAU= 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 AM0PR05MB4625.eurprd05.prod.outlook.com (2603:10a6:208:b6::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.24; Tue, 14 Jul 2020 14:21:12 +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.3174.026; Tue, 14 Jul 2020 14:21:12 +0000 From: Ophir Munk To: dev@dpdk.org Cc: Raslan Darawsheh , Ophir Munk , Matan Azrad Date: Tue, 14 Jul 2020 14:20:57 +0000 Message-Id: <20200714142102.30606-4-ophirmu@mellanox.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20200714142102.30606-1-ophirmu@mellanox.com> References: <20200714142102.30606-1-ophirmu@mellanox.com> Content-Type: text/plain X-ClientProxiedBy: AM3PR05CA0100.eurprd05.prod.outlook.com (2603:10a6:207:1::26) 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 AM3PR05CA0100.eurprd05.prod.outlook.com (2603:10a6:207:1::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:21:11 +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: 2a8653db-e0fe-4331-694b-08d8280128dc X-MS-TrafficTypeDiagnostic: AM0PR05MB4625: 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: glSWHa7p2y7egxQp8Y5mIyBnrZGPEam5TLuVUpWU1TxDwy+o7fZhg4E9IKAefLdNtIzK7eLqCinqeOF+j6uQ+VRU8BbqzewbEuLYwaMr2GUNHvOlkk1mWlZEk2bcWE5f4kamyTYp2s7o1/2+pVaunz4HrJsA+3UDsY053qUYYXlLSQIkQ9Lj0ji758jkttqYUsw2d7ybTTkPK4DSgBNkM76SvG2dofGj0AtU/7YWsYc40pVw9J7EwRE84FrN2ETknIwHCGaT6KqCb5pT8nMqzp5wH9pWMhh0AXZYoXr1jHPLDvipqqH60PugT0TqNtNu 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)(136003)(366004)(376002)(39850400004)(346002)(396003)(36756003)(86362001)(1076003)(8886007)(6666004)(66946007)(316002)(66476007)(52116002)(7696005)(5660300002)(26005)(66556008)(54906003)(478600001)(6916009)(83380400001)(16526019)(8676002)(8936002)(4326008)(956004)(2616005)(107886003)(2906002)(55016002)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: GWoX36eoICQAYqeCXKFGRZ3f8B/ccu7XQR+OZ8Sy7MUW25SDXySNnDz0EjeT1X+JvJOR3Fwalu9QpH8fjgxJOGnHZmxKqmUXsruY1VzXoOEIQfrrbPZKeixG0/QAF1q8zuBj1laH/HtNWWLNdwqMtRoft3hIHkwc4ObYN2qm4HBXvto8Yhw/05LIvlG8aTaHit2fxGumQ/CnyAMis4MVynjwsHtl4DImG50iXlQxt9un3pI91nBlUASc3BFyPZIk4V4cqcSZxDBdVyGZQPtTV95T0/4BAfzahLHwjvoPrsQxKejviu+JpBgpgdppJsHpmsQqncS9CAM00+R4GTPGMlC0xF5iiH72JJMSmNXEy6od297co+jO1z6m16lSJy829rsihjcDMI8zA5GADxJJtHz0XCYDeXh6zqSIn2iLuuBHJgBjAoLjvHvpgjT9gfvH2iuBbfOINiIMw9B5J1B69vDdhx8hk1hQxT8EFVxHs0tuYkLVslzlyJz5e4zOooMo X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2a8653db-e0fe-4331-694b-08d8280128dc X-MS-Exchange-CrossTenant-AuthSource: AM0PR05MB4209.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:21:12.0725 (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: mVgwaTmv4GluJw/P75Yy0hhaSeOHa15mYmDx99i+D8T7m6Oq4zWqhJhaEX50X9L4h6mWMxDBuUEaCvn8q6RDOg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB4625 Subject: [dpdk-dev] [PATCH v1 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 e5f024a..b5993a7 100644 --- a/drivers/net/mlx5/linux/mlx5_os.c +++ b/drivers/net/mlx5/linux/mlx5_os.c @@ -67,6 +67,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. @@ -2274,6 +2298,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; +} + +/** + * Modfiy 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 4323e67..bf1d97a 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -775,7 +775,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); @@ -940,4 +939,10 @@ 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); #endif /* RTE_PMD_MLX5_H_ */ 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