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 83CB4A0540; Tue, 14 Jul 2020 16:22:09 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 356FE1D59F; Tue, 14 Jul 2020 16:21:20 +0200 (CEST) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60063.outbound.protection.outlook.com [40.107.6.63]) by dpdk.org (Postfix) with ESMTP id 31AAB1D538 for ; Tue, 14 Jul 2020 16:21:15 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ngHelNG9WoijseECUbj4Nv4dG5h8Gy/fGr66DMBnIUtqyJoqQiclTFKm61rp5x1ypxwnC2vS1/L1BX1u3g+cJNtSnc6Va/dMIqbyhQVc36ZP4BJj9/qnxxeqOCEBqK0fytkaAVb8YEV2EQM3ppbXXHLkEuB/zh36lejugBP+flwlpGOIFr3Dnqulwq8M2E7BC3QVXaAgnq17KqFyG+r5iNCxTc27jp/0OS6BOpiAvtlBML63hYDKSrLZVBTqY9zV98kuVkqhRKn8R2VypuTGAYEN2osbCU51q9XqWwiLoPxc3wvms6VeB7hnLJ4yW124Ko2M0mqDy6c0EOZXDwvJjg== 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=iXbiLnlzzFjM3/gYpX2ByQd9OHI31YGToOCHYJLfpV0=; b=KbzZ4Ff1MVbRTxaqAZP5XNxA3FXkCyjqP3dDKeorOPYWctv/kq7h8HCGWlVn+6IX8dj9sFX1tV1K0c4Cwl6CA+pN9CLhZtg9XniONDa+3nYZpLipXnCw7WtAP9uqDJ3O/VmBOw7ZbnfHPDK5O7pgqXfkaWt03Y1y4SO+sz+FGflY8W5S2yx/HEFfuqZ1vXaFsdRdb8XLvjJggl3ESdHRhKMD0YMmAsXpOHNcFpmTFiMtjG3R59r6fKH2we8OwdlsQgz7R96K2lfFQPOeGa2E153VyvDatv28W+LlM3eB6+MIuATp6HxZ3mJzSP+5sNkXEvwCM1imGYXWc0LgedgHVw== 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=iXbiLnlzzFjM3/gYpX2ByQd9OHI31YGToOCHYJLfpV0=; b=aupqjv4wCenvw1geZT0YAGcOrVVd3td4LE/rgwVx/YRgmIZ/ZPSUlrAEyWFGnilpkbgBHdOBNdNZTY2hfbpATiEZLxV3s7DlOljxPeM98elKbdUx8Ohg16jHhyJFxwdmvqaykPq8WGBmGvSkIfvIzB1HUhMhhoHfk0Oh86ImSlc= 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:14 +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:13 +0000 From: Ophir Munk To: dev@dpdk.org Cc: Raslan Darawsheh , Ophir Munk , Matan Azrad Date: Tue, 14 Jul 2020 14:20:59 +0000 Message-Id: <20200714142102.30606-6-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:13 +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: 3b9b3f6f-db51-47b8-77e2-08d8280129f5 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:22; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZPZoresrq4P4Rw5x1GEBsKsXPfnaQj2xkwhb2+H5xBGy3aoU1ZDgdlfag444It7mQHxm34FJT3gKHwJU4EcPkeRED4ff8q+VHW4sS6g7/z1+dnXegqlr0c29yrugaKYRlee7dUoqheHmGZm+TLLNINgPQ63LiskBL9Wqssga78AfRJp8Ds0Sap3mQgBT0E+TBNRx0ZkI2bG8vbpgGhqFNPbylatiMIJG+LnRdVaT7j6FJ4aeq8oBOjFV+n9JkLo5+qM+zGLMGlAY2YRO7mTuS8/F1eeSblic3wF1bPn/yfu/CTARhq8tp2G22WSgqfILaK7jnUZGgMff33WCIPlP0w== 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)(30864003)(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: zdnUrUDi//uXfZxjQYbzIgYQWhpFc34l0nVt97affgSx/VIjaXsVbVa4FBoIN4WhCeA5wzthaOJH8hhiYKXt4VeNXFh2+avw0hmPDkDFRkVz25O4oMgXTRwVnNb3K+cGmB8dYKbIyNI32TlrxeeLyIMUqr4lIeN7yRsePBGFrRfR16qCgd10WlFXSFA5uP9KA7VtAiiBggdUfoQ+FCZ4es/umZz9hDKEEm7TGB1oq5I2y///nkABB/NAhcHgshesGfy3/wo8jKdLZ4CgVdLWDwb0beXGvbqTjxlqVsCDdn8RoFOJR5LG6b/g9Qg8ckzRMw7DRR0tf22dij2q1HpBmzu4ta/8wnI7g88Hcyo9UgNF/sV3Y80kCqedxNnshsYzL36WYrAa1vpkYEdRjZO6bRQUZXfveDd82xICwYkzdahf2oCkNI67lsVzrePen+6VnBLYiwFmWuZuPZdt3T/UiYcsPE773+xgB26UFfS0THARH5E+Ycd7m/eDatrAKPNw X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3b9b3f6f-db51-47b8-77e2-08d8280129f5 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:13.9215 (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: ze79D05xgHMrxrpqLdMBwlpakELRcPFNNmWczeQbhoKWkV670srtMqX6F73MgK+rney2fV3ls8uO5BIQSresDg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB4625 Subject: [dpdk-dev] [PATCH v1 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 701614a..765a521 100644 --- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c +++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c @@ -177,7 +177,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); @@ -257,7 +257,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; @@ -1185,3 +1185,313 @@ int mlx5_get_module_eeprom(struct rte_eth_dev *dev, rte_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 *) + rte_malloc("xstats_strings", + str_sz + sizeof(struct ethtool_gstrings), 0); + 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: + rte_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 7de57a4..a853219 100644 --- a/drivers/net/mlx5/linux/mlx5_os.c +++ b/drivers/net/mlx5/linux/mlx5_os.c @@ -67,30 +67,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. @@ -1997,291 +1973,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 *) - rte_malloc("xstats_strings", - str_sz + sizeof(struct ethtool_gstrings), 0); - 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: - rte_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 f719cfc..a1d4734 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -649,7 +649,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; @@ -735,10 +734,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); @@ -772,6 +769,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 */ @@ -932,11 +934,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