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 5C569A0540; Sun, 19 Jul 2020 12:19:20 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 7496D1C0DB; Sun, 19 Jul 2020 12:18:38 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2087.outbound.protection.outlook.com [40.107.22.87]) by dpdk.org (Postfix) with ESMTP id 067A61C0B2 for ; Sun, 19 Jul 2020 12:18:30 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BJHBbr8FlFu3+KCedUdXDStE4skfcJ2/GbGPYKmKL+hlrMe9QDX2sCKOnt8co/RpHvEFTUOz586YuJpoqM1s/zVvedo24fEzYxt5uT8RCEixxftkCL4N4q6ITWLQNGGKFNiiGg8JX+SGz8XPiUVK03Pkauovmw0AIFhg9X+paqNWClOQx43xN9ai+ma/fNybDwXjGEbURLNHQUfGROSIIOIagbmnq7S3qKYm6aqzm0A4RAsmvdUxbxGMMaGSlBfKovmy0Ltu8oFN+Qvt++mriPL7mxYCgTHYn9Z8ZAfbrzJ5QWTySKjPTreGz/ZtkzVGCzWjBT8J5eRypOfY7NeaCQ== 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=ypso8b9SvczGSyis4h4ycjc6kYUqGG3xDMgrwPn+TpY=; b=a6/VO7iSdJKxPwJL1VE4pTEElO10QcX9GhXTRkIOlPtFW/NE/V3Du8Fgv90+FuPe4MqSuOq4+y0/blliyAjbFc68l7AQzvFMW0DMmosrEB8c0GOisVsw7Y/hDlsPKUFsFowpUIXcUuFJrxuGo1d6QSf7hkXOPCtxUMurv59trhIhxamWrIQWHhkyViFRZKA3NJIjCoWpdUdMMB47TUqVkqEsDT0eJ1YKrSt/r2jtvCI6KLFjFdXDuzZR4c7DBiBsgcrJmWg82iVZBnisXC4iHOXMmFAB3+jE5vdkHwVw3emIm2jk5YxtwkmwcXuqEb3I/s7+HJvQmqZ2Kh2IYZtynQ== 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=ypso8b9SvczGSyis4h4ycjc6kYUqGG3xDMgrwPn+TpY=; b=YivLnOLlEYiPJFER70/08Alg8eSx5JGbkREtfbLMFlwB/sz32oWaH1FWCycLvHmVY+sAgQQRs8mrSFqz4veRmQt8aZCa/zLiiVmiD7wkmLOsHblPI+SI0IixmAYpZjjDWDLKVGFzUjHELZx+OM48VFo6DhNNWjYoH6mBA9WCXZg= 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:30 +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:30 +0000 From: Ophir Munk To: dev@dpdk.org Cc: Raslan Darawsheh , Ophir Munk , Matan Azrad Date: Sun, 19 Jul 2020 10:18:13 +0000 Message-Id: <20200719101816.16406-6-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:29 +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: 06abba54-1f1b-4ce9-c594-08d82bcd153b 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:22; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KEJGruBGVXrn39Ztn243Q2txc+lhKb8fRkd6TB+YEvTXn2G3uz0ai7RpTdtGL+TdTTKHEIvnBbyw2rCiq1uEU6KcL7/o24goUok/6Ul4Ym84QGpv1MZC6yStvFdiFqtFbUJFxo+Y66QShI7IVoTEsSb3D+v3k1F6kZDVRfVndKf7VlZ2tHOtI+MjoiNPpqRAfa1tufK/qc3DduhT2X4yd6sHs4NB+PHhf/5w9pxVmoqIDNvXFqjlJl8OLQUmrdwUEQ9bTQzRhhieePriQ2AN9tQEthNPU60usKr2xoPoB94KGBWvQ6slf+H4/ObK4UFne+5vCAt8r/s0pw2xpZIBnw== 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)(30864003)(6916009)(26005)(478600001)(52116002)(7696005)(107886003)(66556008)(86362001)(66476007)(66946007)(1076003)(55016002)(8936002)(8676002)(8886007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: MORI2RnP6KkGmxRWwmfm2udbLnvCu6zpw+ftQPZwqkFLy4yc1yvJ54EN7kvNLhbKM9w24H8HSMqnZejOHsU4UOGxDcOD/DxtuK/L1Vd18s9NowhE4g+kpuWAOWrlUOK4Gk1cfcm1bgElAeXGH1t6K1YYVrjHQUcUUX9u0nMA4S0SAhbMTxR43lK6wHR+7AF4uHworTQWdyPurfMNSI9QPXEPWuROWX4Hr4qPfeMCG4nMs214Yt/fMwrVETtcxdvI/eQIJTPegm744oOr2nrgpo6BWLd4zkrelaaMMdPlcDd/+OaEPgzAYbKkUNufCFQflTWdejGmgmviVoAVoT6myXQFQ13y33ICewsuZIEqhKH0CXKoOOsgzEczQzgmQRv+btVOqjIQHEVF9yerY1AXIUhF82h4bJZGpgBsEVMLc9SEwA2Evn0mnA0r61IW0K79CBoSW3nNvTbVKhc0elU8M2dHOIOcRg+m9fj++X64CKkyCpgsJUF8M7PbQYKpvLfX X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 06abba54-1f1b-4ce9-c594-08d82bcd153b 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:29.9832 (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: iV/P+OnkAr0rMDJfY7OLAvCV0QPLJ8uD6m2AmlVag7nmVJegSvFOuqdMeuQ4O2dxw/0hSkWxuack6RumBl+P/w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB6324 Subject: [dpdk-dev] [PATCH v3 5/8] net/mlx5: eliminate dependency on Linux in shared header 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 commit eliminates Linux dependencies in shared file mlx5.h. 1. All functions using 'struct ifreq' are moved to file linux/mlx5_ethdev_os.c such that this struct can be removed from mlx5.h. 2. Function mlx5_set_flags() that uses Linux flags (e.g. IFF_UP) is changed to static and its prototype is removed from mlx5.h. 3. Remove redundant member verbs_action from 'struct mlx5_priv'. Signed-off-by: Ophir Munk Acked-by: Matan Azrad --- drivers/net/mlx5/linux/mlx5_ethdev_os.c | 314 +++++++++++++++++++++++++++++++- drivers/net/mlx5/linux/mlx5_os.c | 309 ------------------------------- drivers/net/mlx5/mlx5.h | 15 +- 3 files changed, 318 insertions(+), 320 deletions(-) diff --git a/drivers/net/mlx5/linux/mlx5_ethdev_os.c b/drivers/net/mlx5/linux/mlx5_ethdev_os.c index 6b8a151..e79d576 100644 --- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c +++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c @@ -178,7 +178,7 @@ mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[IF_NAMESIZE]) * @return * 0 on success, a negative errno value otherwise and rte_errno is set. */ -int +static int mlx5_ifreq(const struct rte_eth_dev *dev, int req, struct ifreq *ifr) { int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); @@ -258,7 +258,7 @@ mlx5_set_mtu(struct rte_eth_dev *dev, uint16_t mtu) * @return * 0 on success, a negative errno value otherwise and rte_errno is set. */ -int +static int mlx5_set_flags(struct rte_eth_dev *dev, unsigned int keep, unsigned int flags) { struct ifreq request; @@ -1187,3 +1187,313 @@ int mlx5_get_module_eeprom(struct rte_eth_dev *dev, mlx5_free(eeprom); return ret; } + +/** + * Read device counters table. + * + * @param dev + * Pointer to Ethernet device. + * @param[out] stats + * Counters table output buffer. + * + * @return + * 0 on success and stats is filled, negative errno value otherwise and + * rte_errno is set. + */ +int +mlx5_os_read_dev_counters(struct rte_eth_dev *dev, uint64_t *stats) +{ + struct mlx5_priv *priv = dev->data->dev_private; + struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl; + unsigned int i; + struct ifreq ifr; + unsigned int stats_sz = xstats_ctrl->stats_n * sizeof(uint64_t); + unsigned char et_stat_buf[sizeof(struct ethtool_stats) + stats_sz]; + struct ethtool_stats *et_stats = (struct ethtool_stats *)et_stat_buf; + int ret; + + et_stats->cmd = ETHTOOL_GSTATS; + et_stats->n_stats = xstats_ctrl->stats_n; + ifr.ifr_data = (caddr_t)et_stats; + ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr); + if (ret) { + DRV_LOG(WARNING, + "port %u unable to read statistic values from device", + dev->data->port_id); + return ret; + } + for (i = 0; i != xstats_ctrl->mlx5_stats_n; ++i) { + if (xstats_ctrl->info[i].dev) { + ret = mlx5_os_read_dev_stat(priv, + xstats_ctrl->info[i].ctr_name, + &stats[i]); + /* return last xstats counter if fail to read. */ + if (ret == 0) + xstats_ctrl->xstats[i] = stats[i]; + else + stats[i] = xstats_ctrl->xstats[i]; + } else { + stats[i] = (uint64_t) + et_stats->data[xstats_ctrl->dev_table_idx[i]]; + } + } + return 0; +} + +/** + * Query the number of statistics provided by ETHTOOL. + * + * @param dev + * Pointer to Ethernet device. + * + * @return + * Number of statistics on success, negative errno value otherwise and + * rte_errno is set. + */ +int +mlx5_os_get_stats_n(struct rte_eth_dev *dev) +{ + struct ethtool_drvinfo drvinfo; + struct ifreq ifr; + int ret; + + drvinfo.cmd = ETHTOOL_GDRVINFO; + ifr.ifr_data = (caddr_t)&drvinfo; + ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr); + if (ret) { + DRV_LOG(WARNING, "port %u unable to query number of statistics", + dev->data->port_id); + return ret; + } + return drvinfo.n_stats; +} + +static const struct mlx5_counter_ctrl mlx5_counters_init[] = { + { + .dpdk_name = "rx_port_unicast_bytes", + .ctr_name = "rx_vport_unicast_bytes", + }, + { + .dpdk_name = "rx_port_multicast_bytes", + .ctr_name = "rx_vport_multicast_bytes", + }, + { + .dpdk_name = "rx_port_broadcast_bytes", + .ctr_name = "rx_vport_broadcast_bytes", + }, + { + .dpdk_name = "rx_port_unicast_packets", + .ctr_name = "rx_vport_unicast_packets", + }, + { + .dpdk_name = "rx_port_multicast_packets", + .ctr_name = "rx_vport_multicast_packets", + }, + { + .dpdk_name = "rx_port_broadcast_packets", + .ctr_name = "rx_vport_broadcast_packets", + }, + { + .dpdk_name = "tx_port_unicast_bytes", + .ctr_name = "tx_vport_unicast_bytes", + }, + { + .dpdk_name = "tx_port_multicast_bytes", + .ctr_name = "tx_vport_multicast_bytes", + }, + { + .dpdk_name = "tx_port_broadcast_bytes", + .ctr_name = "tx_vport_broadcast_bytes", + }, + { + .dpdk_name = "tx_port_unicast_packets", + .ctr_name = "tx_vport_unicast_packets", + }, + { + .dpdk_name = "tx_port_multicast_packets", + .ctr_name = "tx_vport_multicast_packets", + }, + { + .dpdk_name = "tx_port_broadcast_packets", + .ctr_name = "tx_vport_broadcast_packets", + }, + { + .dpdk_name = "rx_wqe_err", + .ctr_name = "rx_wqe_err", + }, + { + .dpdk_name = "rx_crc_errors_phy", + .ctr_name = "rx_crc_errors_phy", + }, + { + .dpdk_name = "rx_in_range_len_errors_phy", + .ctr_name = "rx_in_range_len_errors_phy", + }, + { + .dpdk_name = "rx_symbol_err_phy", + .ctr_name = "rx_symbol_err_phy", + }, + { + .dpdk_name = "tx_errors_phy", + .ctr_name = "tx_errors_phy", + }, + { + .dpdk_name = "rx_out_of_buffer", + .ctr_name = "out_of_buffer", + .dev = 1, + }, + { + .dpdk_name = "tx_packets_phy", + .ctr_name = "tx_packets_phy", + }, + { + .dpdk_name = "rx_packets_phy", + .ctr_name = "rx_packets_phy", + }, + { + .dpdk_name = "tx_discards_phy", + .ctr_name = "tx_discards_phy", + }, + { + .dpdk_name = "rx_discards_phy", + .ctr_name = "rx_discards_phy", + }, + { + .dpdk_name = "tx_bytes_phy", + .ctr_name = "tx_bytes_phy", + }, + { + .dpdk_name = "rx_bytes_phy", + .ctr_name = "rx_bytes_phy", + }, + /* Representor only */ + { + .dpdk_name = "rx_packets", + .ctr_name = "vport_rx_packets", + }, + { + .dpdk_name = "rx_bytes", + .ctr_name = "vport_rx_bytes", + }, + { + .dpdk_name = "tx_packets", + .ctr_name = "vport_tx_packets", + }, + { + .dpdk_name = "tx_bytes", + .ctr_name = "vport_tx_bytes", + }, +}; + +static const unsigned int xstats_n = RTE_DIM(mlx5_counters_init); + +/** + * Init the structures to read device counters. + * + * @param dev + * Pointer to Ethernet device. + */ +void +mlx5_os_stats_init(struct rte_eth_dev *dev) +{ + struct mlx5_priv *priv = dev->data->dev_private; + struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl; + struct mlx5_stats_ctrl *stats_ctrl = &priv->stats_ctrl; + unsigned int i; + unsigned int j; + struct ifreq ifr; + struct ethtool_gstrings *strings = NULL; + unsigned int dev_stats_n; + unsigned int str_sz; + int ret; + + /* So that it won't aggregate for each init. */ + xstats_ctrl->mlx5_stats_n = 0; + ret = mlx5_os_get_stats_n(dev); + if (ret < 0) { + DRV_LOG(WARNING, "port %u no extended statistics available", + dev->data->port_id); + return; + } + dev_stats_n = ret; + /* Allocate memory to grab stat names and values. */ + str_sz = dev_stats_n * ETH_GSTRING_LEN; + strings = (struct ethtool_gstrings *) + mlx5_malloc(0, str_sz + sizeof(struct ethtool_gstrings), 0, + SOCKET_ID_ANY); + if (!strings) { + DRV_LOG(WARNING, "port %u unable to allocate memory for xstats", + dev->data->port_id); + return; + } + strings->cmd = ETHTOOL_GSTRINGS; + strings->string_set = ETH_SS_STATS; + strings->len = dev_stats_n; + ifr.ifr_data = (caddr_t)strings; + ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr); + if (ret) { + DRV_LOG(WARNING, "port %u unable to get statistic names", + dev->data->port_id); + goto free; + } + for (i = 0; i != dev_stats_n; ++i) { + const char *curr_string = (const char *) + &strings->data[i * ETH_GSTRING_LEN]; + + for (j = 0; j != xstats_n; ++j) { + if (!strcmp(mlx5_counters_init[j].ctr_name, + curr_string)) { + unsigned int idx = xstats_ctrl->mlx5_stats_n++; + + xstats_ctrl->dev_table_idx[idx] = i; + xstats_ctrl->info[idx] = mlx5_counters_init[j]; + break; + } + } + } + /* Add dev counters. */ + for (i = 0; i != xstats_n; ++i) { + if (mlx5_counters_init[i].dev) { + unsigned int idx = xstats_ctrl->mlx5_stats_n++; + + xstats_ctrl->info[idx] = mlx5_counters_init[i]; + xstats_ctrl->hw_stats[idx] = 0; + } + } + MLX5_ASSERT(xstats_ctrl->mlx5_stats_n <= MLX5_MAX_XSTATS); + xstats_ctrl->stats_n = dev_stats_n; + /* Copy to base at first time. */ + ret = mlx5_os_read_dev_counters(dev, xstats_ctrl->base); + if (ret) + DRV_LOG(ERR, "port %u cannot read device counters: %s", + dev->data->port_id, strerror(rte_errno)); + mlx5_os_read_dev_stat(priv, "out_of_buffer", &stats_ctrl->imissed_base); + stats_ctrl->imissed = 0; +free: + mlx5_free(strings); +} + +/** + * 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; +} + diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c index 1f82f0a..d3ae3ad 100644 --- a/drivers/net/mlx5/linux/mlx5_os.c +++ b/drivers/net/mlx5/linux/mlx5_os.c @@ -68,30 +68,6 @@ #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. @@ -2082,291 +2058,6 @@ mlx5_os_read_dev_stat(struct mlx5_priv *priv, const char *ctr_name, } /** - * Read device counters table. - * - * @param dev - * Pointer to Ethernet device. - * @param[out] stats - * Counters table output buffer. - * - * @return - * 0 on success and stats is filled, negative errno value otherwise and - * rte_errno is set. - */ -int -mlx5_os_read_dev_counters(struct rte_eth_dev *dev, uint64_t *stats) -{ - struct mlx5_priv *priv = dev->data->dev_private; - struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl; - unsigned int i; - struct ifreq ifr; - unsigned int stats_sz = xstats_ctrl->stats_n * sizeof(uint64_t); - unsigned char et_stat_buf[sizeof(struct ethtool_stats) + stats_sz]; - struct ethtool_stats *et_stats = (struct ethtool_stats *)et_stat_buf; - int ret; - - et_stats->cmd = ETHTOOL_GSTATS; - et_stats->n_stats = xstats_ctrl->stats_n; - ifr.ifr_data = (caddr_t)et_stats; - ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr); - if (ret) { - DRV_LOG(WARNING, - "port %u unable to read statistic values from device", - dev->data->port_id); - return ret; - } - for (i = 0; i != xstats_ctrl->mlx5_stats_n; ++i) { - if (xstats_ctrl->info[i].dev) { - ret = mlx5_os_read_dev_stat(priv, - xstats_ctrl->info[i].ctr_name, - &stats[i]); - /* return last xstats counter if fail to read. */ - if (ret == 0) - xstats_ctrl->xstats[i] = stats[i]; - else - stats[i] = xstats_ctrl->xstats[i]; - } else { - stats[i] = (uint64_t) - et_stats->data[xstats_ctrl->dev_table_idx[i]]; - } - } - return 0; -} - -/** - * Query the number of statistics provided by ETHTOOL. - * - * @param dev - * Pointer to Ethernet device. - * - * @return - * Number of statistics on success, negative errno value otherwise and - * rte_errno is set. - */ -int -mlx5_os_get_stats_n(struct rte_eth_dev *dev) -{ - struct ethtool_drvinfo drvinfo; - struct ifreq ifr; - int ret; - - drvinfo.cmd = ETHTOOL_GDRVINFO; - ifr.ifr_data = (caddr_t)&drvinfo; - ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr); - if (ret) { - DRV_LOG(WARNING, "port %u unable to query number of statistics", - dev->data->port_id); - return ret; - } - return drvinfo.n_stats; -} - -static const struct mlx5_counter_ctrl mlx5_counters_init[] = { - { - .dpdk_name = "rx_port_unicast_bytes", - .ctr_name = "rx_vport_unicast_bytes", - }, - { - .dpdk_name = "rx_port_multicast_bytes", - .ctr_name = "rx_vport_multicast_bytes", - }, - { - .dpdk_name = "rx_port_broadcast_bytes", - .ctr_name = "rx_vport_broadcast_bytes", - }, - { - .dpdk_name = "rx_port_unicast_packets", - .ctr_name = "rx_vport_unicast_packets", - }, - { - .dpdk_name = "rx_port_multicast_packets", - .ctr_name = "rx_vport_multicast_packets", - }, - { - .dpdk_name = "rx_port_broadcast_packets", - .ctr_name = "rx_vport_broadcast_packets", - }, - { - .dpdk_name = "tx_port_unicast_bytes", - .ctr_name = "tx_vport_unicast_bytes", - }, - { - .dpdk_name = "tx_port_multicast_bytes", - .ctr_name = "tx_vport_multicast_bytes", - }, - { - .dpdk_name = "tx_port_broadcast_bytes", - .ctr_name = "tx_vport_broadcast_bytes", - }, - { - .dpdk_name = "tx_port_unicast_packets", - .ctr_name = "tx_vport_unicast_packets", - }, - { - .dpdk_name = "tx_port_multicast_packets", - .ctr_name = "tx_vport_multicast_packets", - }, - { - .dpdk_name = "tx_port_broadcast_packets", - .ctr_name = "tx_vport_broadcast_packets", - }, - { - .dpdk_name = "rx_wqe_err", - .ctr_name = "rx_wqe_err", - }, - { - .dpdk_name = "rx_crc_errors_phy", - .ctr_name = "rx_crc_errors_phy", - }, - { - .dpdk_name = "rx_in_range_len_errors_phy", - .ctr_name = "rx_in_range_len_errors_phy", - }, - { - .dpdk_name = "rx_symbol_err_phy", - .ctr_name = "rx_symbol_err_phy", - }, - { - .dpdk_name = "tx_errors_phy", - .ctr_name = "tx_errors_phy", - }, - { - .dpdk_name = "rx_out_of_buffer", - .ctr_name = "out_of_buffer", - .dev = 1, - }, - { - .dpdk_name = "tx_packets_phy", - .ctr_name = "tx_packets_phy", - }, - { - .dpdk_name = "rx_packets_phy", - .ctr_name = "rx_packets_phy", - }, - { - .dpdk_name = "tx_discards_phy", - .ctr_name = "tx_discards_phy", - }, - { - .dpdk_name = "rx_discards_phy", - .ctr_name = "rx_discards_phy", - }, - { - .dpdk_name = "tx_bytes_phy", - .ctr_name = "tx_bytes_phy", - }, - { - .dpdk_name = "rx_bytes_phy", - .ctr_name = "rx_bytes_phy", - }, - /* Representor only */ - { - .dpdk_name = "rx_packets", - .ctr_name = "vport_rx_packets", - }, - { - .dpdk_name = "rx_bytes", - .ctr_name = "vport_rx_bytes", - }, - { - .dpdk_name = "tx_packets", - .ctr_name = "vport_tx_packets", - }, - { - .dpdk_name = "tx_bytes", - .ctr_name = "vport_tx_bytes", - }, -}; - -static const unsigned int xstats_n = RTE_DIM(mlx5_counters_init); - -/** - * Init the structures to read device counters. - * - * @param dev - * Pointer to Ethernet device. - */ -void -mlx5_os_stats_init(struct rte_eth_dev *dev) -{ - struct mlx5_priv *priv = dev->data->dev_private; - struct mlx5_xstats_ctrl *xstats_ctrl = &priv->xstats_ctrl; - struct mlx5_stats_ctrl *stats_ctrl = &priv->stats_ctrl; - unsigned int i; - unsigned int j; - struct ifreq ifr; - struct ethtool_gstrings *strings = NULL; - unsigned int dev_stats_n; - unsigned int str_sz; - int ret; - - /* So that it won't aggregate for each init. */ - xstats_ctrl->mlx5_stats_n = 0; - ret = mlx5_os_get_stats_n(dev); - if (ret < 0) { - DRV_LOG(WARNING, "port %u no extended statistics available", - dev->data->port_id); - return; - } - dev_stats_n = ret; - /* Allocate memory to grab stat names and values. */ - str_sz = dev_stats_n * ETH_GSTRING_LEN; - strings = (struct ethtool_gstrings *) - mlx5_malloc(0, str_sz + sizeof(struct ethtool_gstrings), 0, - SOCKET_ID_ANY); - if (!strings) { - DRV_LOG(WARNING, "port %u unable to allocate memory for xstats", - dev->data->port_id); - return; - } - strings->cmd = ETHTOOL_GSTRINGS; - strings->string_set = ETH_SS_STATS; - strings->len = dev_stats_n; - ifr.ifr_data = (caddr_t)strings; - ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr); - if (ret) { - DRV_LOG(WARNING, "port %u unable to get statistic names", - dev->data->port_id); - goto free; - } - for (i = 0; i != dev_stats_n; ++i) { - const char *curr_string = (const char *) - &strings->data[i * ETH_GSTRING_LEN]; - - for (j = 0; j != xstats_n; ++j) { - if (!strcmp(mlx5_counters_init[j].ctr_name, - curr_string)) { - unsigned int idx = xstats_ctrl->mlx5_stats_n++; - - xstats_ctrl->dev_table_idx[idx] = i; - xstats_ctrl->info[idx] = mlx5_counters_init[j]; - break; - } - } - } - /* Add dev counters. */ - for (i = 0; i != xstats_n; ++i) { - if (mlx5_counters_init[i].dev) { - unsigned int idx = xstats_ctrl->mlx5_stats_n++; - - xstats_ctrl->info[idx] = mlx5_counters_init[i]; - xstats_ctrl->hw_stats[idx] = 0; - } - } - MLX5_ASSERT(xstats_ctrl->mlx5_stats_n <= MLX5_MAX_XSTATS); - xstats_ctrl->stats_n = dev_stats_n; - /* Copy to base at first time. */ - ret = mlx5_os_read_dev_counters(dev, xstats_ctrl->base); - if (ret) - DRV_LOG(ERR, "port %u cannot read device counters: %s", - dev->data->port_id, strerror(rte_errno)); - mlx5_os_read_dev_stat(priv, "out_of_buffer", &stats_ctrl->imissed_base); - stats_ctrl->imissed = 0; -free: - mlx5_free(strings); -} - -/** * Set the reg_mr and dereg_mr call backs * * @param reg_mr_cb[out] diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 24a668b..9fa7e47 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -737,7 +737,6 @@ struct mlx5_priv { LIST_HEAD(ind_tables, mlx5_ind_table_obj) ind_tbls; /* Pointer to next element. */ rte_atomic32_t refcnt; /**< Reference counter. */ - struct ibv_flow_action *verbs_action; /**< Verbs modify header action object. */ uint8_t ft_type; /**< Flow table type, Rx or Tx. */ uint8_t max_lro_msg_size; @@ -820,10 +819,8 @@ int mlx5_hairpin_cap_get(struct rte_eth_dev *dev, int mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[IF_NAMESIZE]); unsigned int mlx5_ifindex(const struct rte_eth_dev *dev); -int mlx5_ifreq(const struct rte_eth_dev *dev, int req, struct ifreq *ifr); +int mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[RTE_ETHER_ADDR_LEN]); int mlx5_get_mtu(struct rte_eth_dev *dev, uint16_t *mtu); -int mlx5_set_flags(struct rte_eth_dev *dev, unsigned int keep, - unsigned int flags); int mlx5_set_mtu(struct rte_eth_dev *dev, uint16_t mtu); int mlx5_read_clock(struct rte_eth_dev *dev, uint64_t *clock); int mlx5_link_update(struct rte_eth_dev *dev, int wait_to_complete); @@ -857,6 +854,11 @@ int mlx5_get_module_info(struct rte_eth_dev *dev, int mlx5_get_module_eeprom(struct rte_eth_dev *dev, struct rte_dev_eeprom_info *info); int mlx5_dev_configure_rss_reta(struct rte_eth_dev *dev); +int mlx5_os_read_dev_stat(struct mlx5_priv *priv, + const char *ctr_name, uint64_t *stat); +int mlx5_os_read_dev_counters(struct rte_eth_dev *dev, uint64_t *stats); +int mlx5_os_get_stats_n(struct rte_eth_dev *dev); +void mlx5_os_stats_init(struct rte_eth_dev *dev); /* mlx5_mac.c */ @@ -1017,11 +1019,6 @@ int mlx5_os_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, struct rte_pci_device *pci_dev); void mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh); void mlx5_os_dev_shared_handler_uninstall(struct mlx5_dev_ctx_shared *sh); -int mlx5_os_read_dev_stat(struct mlx5_priv *priv, - const char *ctr_name, uint64_t *stat); -int mlx5_os_read_dev_counters(struct rte_eth_dev *dev, uint64_t *stats); -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); -- 2.8.4