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 00BB7A0540; Sun, 19 Jul 2020 12:19:02 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E25591C0CD; Sun, 19 Jul 2020 12:18:35 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2046.outbound.protection.outlook.com [40.107.22.46]) by dpdk.org (Postfix) with ESMTP id 4E9401C06D for ; Sun, 19 Jul 2020 12:18:29 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JML2GmZ8yetcdexlIIB5B2yJDdIbB1M2yS5f4iz65N4usef2ZtqkS05M2LGsGxUlmrIDrFjmUaRBLpDPx0h1Hhzcmmths4qvcLfkoYrPIm0vK1kQxxmZ/+c2jFUuCeVckBswCp8mmcQuvl5dzNcTStadCnTsmBECg2f5/3jt9kB08EHo7mqDeu7peDkq6VbuVb1RGxSVbgmHfJD4rWdsfUKhMVCGXxH+UyK+W2KP3I9fUM24a78Hq/lZl818t4+3A7SQnFWj3uu0CxF3e8VtcTPlYK1PsF9KUMdbNePv2FQjtqreiuweHkNczCIKgXMpBJ92jr8joWlyNhDK/Xeg2A== 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=2bNAvab0LizErbpDPK05acsACrs/rLQEur9lY5m2pAo=; b=bQC2m4gFNcH6mO66KnZqzKwYYWZYvZP8zVfND3JUfsz59pI0QdRpFAiyqV7UD4LrNgS26A12TYzMMP2wesC/rXDeHOUtIpt9WA1jhLLQPKLoQoPlL2XiOP5gQUKM4vYQM41XgLEfGlXVFeHd0qo9VxRjx5Bkhl3jufbPohfuQz1UZ985/KxdBKPTEIIHb1BXPUYj891T0Y9H9L0rx09GuKF3Fdei97fNXw+UsZO3MrU51Lh6mXLpuZKbJBLq0UxEIO8qiOLmSIenLcl37aefUxb7GzW6sR7xYJKb9U+sNC4gFXEJPIwzn34H0o34o75xzDQq2wnZuH5Q0xqcMD//wg== 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=2bNAvab0LizErbpDPK05acsACrs/rLQEur9lY5m2pAo=; b=BlZGa5gLmbThPbEcWPjKSiSo8AEvvzJxvzLnmgh+TdRlP2zEnXgwGZ7KZYlBkPsAEQwaTaAbnZn87mRLkm1OnG0NIjkySUFJ0RHh402Pzpas8zlXYW0NrXHFLzFYF7mzbhSZlC3mmoPjNUkWF5u4NmSq2+iHLCUj2Z952VHI63k= 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 AM0PR05MB6324.eurprd05.prod.outlook.com (2603:10a6:208:143::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Sun, 19 Jul 2020 10:18:28 +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 10:18:28 +0000 From: Ophir Munk To: dev@dpdk.org Cc: Raslan Darawsheh , Ophir Munk , Matan Azrad Date: Sun, 19 Jul 2020 10:18:11 +0000 Message-Id: <20200719101816.16406-4-ophirmu@mellanox.com> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20200719101816.16406-1-ophirmu@mellanox.com> References: <20200719071112.8540-9-ophirmu@mellanox.com> <20200719101816.16406-1-ophirmu@mellanox.com> Content-Type: text/plain X-ClientProxiedBy: AM0PR05CA0090.eurprd05.prod.outlook.com (2603:10a6:208:136::30) 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 AM0PR05CA0090.eurprd05.prod.outlook.com (2603:10a6:208:136::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.18 via Frontend Transport; Sun, 19 Jul 2020 10:18:27 +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: 53b93342-df4a-40e2-5a64-08d82bcd1443 X-MS-TrafficTypeDiagnostic: AM0PR05MB6324: 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: n1Ra6si6CxeX024YGQc8cnVjWL3aB6nmXNLl7k5Ela6VV0WAXkNwFrspVDiUH6VPLppWp7RlafEV363yicSPDnVl4SPOpPVWYjmmUj3prXGw7/S6iUi1N3SGd1SuaVVgHQOcHtLfBx3ndksQ36d5ft5MC77YMWgUopiXHAXdNIGqGdD5znixwvaexjjrQudYuYeFG+125MIUYY2ghY/uFHrACisU8dUv1ilAbY4EnprGeiE1invYgvwSjOh4t/nhpZGBvzlN6flKNnBVem/cRh3PRfeKvxg485Q7ggBfs75w02Vem9k0w2GE56CuxNhE 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)(346002)(376002)(136003)(39860400002)(366004)(5660300002)(316002)(2906002)(36756003)(54906003)(186003)(2616005)(6666004)(16526019)(4326008)(83380400001)(956004)(6916009)(26005)(478600001)(52116002)(7696005)(107886003)(66556008)(86362001)(66476007)(66946007)(1076003)(55016002)(8936002)(8676002)(8886007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: /U+lBiGpfUOgiT6D6/8i5DuUrklMMF0/DiNIc0+LSvj6ZCmqGrWwwGLz1TABWwhRZFpuq0c4avF7LXUplDW9rB5jDoMI8tczH/j9s1VsUYkAHV+NmXZMRMAnvtWpZcMfFUCh/Yq4zdyyoc/FAidORF5uECIZ/JWv5M0I0iq5h35E+0gpz6sjgfzOHkOdEIG4BxgFwlE3WxkXRjr1VTmAwUMRkuZ7uFnLY6IhOyc0UcpN7ufupH3FZTfKQpNCpzahWmGmPMsQOi9eVFH6caVrQSgSqDJ9gxVk6XtRbzCa3sLBYBXWcD1tKjb3SMy6sR+xTsvyjAWhOc8yjtAa5zuDCiqRmCO9eCG03yzJlEPQgKTPKdbnrArrZCfCnirVMBVSPKhuxbNbD2BWqo3M9DuPubQIihqQ1my11sA3GxZ6jgrSKPuw8bP4etZX2rl0y9fTooPApgJpf7/ETHhozarvPZNiyvsfXkt6QaQ/oZ2hzBRAEn9e0+WWvviCQsZzn20u X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 53b93342-df4a-40e2-5a64-08d82bcd1443 X-MS-Exchange-CrossTenant-AuthSource: AM0PR05MB4209.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2020 10:18:28.3342 (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: z0TGYxXH6tWQ4N9g0vidqtkujTKmyJzhTesxmScVUYhLiXgVBgnLEwo8nILt64+w/UzJdN7F2kgDVjp/xU+QUQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB6324 Subject: [dpdk-dev] [PATCH v3 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 68420af..9a35ccc 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. @@ -2359,6 +2383,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 3df4149..a3c7824 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -860,7 +860,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); @@ -1025,6 +1024,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