Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1192937ybl; Thu, 22 Aug 2019 10:41:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwDEZd5fHlzdIBTeaWFk1rOtLIpiYnx0I2LkIZA+fxOUr836zIoWQ9XjJ9oG51X6yRUQdSW X-Received: by 2002:a17:902:5a41:: with SMTP id f1mr17213plm.30.1566495679929; Thu, 22 Aug 2019 10:41:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566495679; cv=none; d=google.com; s=arc-20160816; b=NITPloFoUWLkNGLtIcaVEmNpYEFVK++ZSikeQIN0XyO9IMWIciZppvoQM59udBM2jx 3qgYvfxJR+r8tQp84ySLaLgfx2DTvGkTqPIb7Ow4b1xHi3ENsZqYD3yCyIFKgnd5xkHz 6DhSC6/DyBZudVz+hZuIVrAkURehxJlzbWkSTOFeqap2wc0rvJNL8c2Z6h8Ill9Sv0Kz faD1lW16NPd+U9BT7BpmGbFjEot5LHKCPRkgGQRHk2qsvjSxg8f8+bhMP2Xqa4EDQbPa 0uKsMGGZTqflTbpkJIHYkIN7mRpgKc7wTlwtjvHggdYNlxGOvyq0Tk+rfqh2Jf73ydmq ZCYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=nbeFvfoM0HYpQ0PjEi21y6ld+wUysxn87uKX0bt4ziE=; b=XnAqAAsUmGm7Y7XQCrkhrJBAFOMaFWMx5J1JVnnHhIgtHI8mQVCtt4xMHz+Iq166d0 y3fGVZ3mgdzACOLB2yk08M2NdmgD+0IWu/HHaRHD5Oz49AsoxnbrwzbhIjHrxhHNQsZX D5Jb/cmmCpItokaIG0ntLP6tba1rwET3cWxtrytjrf4sf4At3rTBrkihhlUhBjF/1GmB N/sl3Br3j4V7yUEp0buD4Zw44GJlSY2cFwEVRDgzVd7Se36KHwRloznMCwHF5W0k2W/s 2GfV9RJHpPvlIc272HUGyca4gKj8n8x8ZQ9gZBEtNZ14nAVtL1mWfu7igClmuGPO/zeE 4ugg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UK+kYTQM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w18si126666pll.132.2019.08.22.10.41.04; Thu, 22 Aug 2019 10:41:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UK+kYTQM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404946AbfHVRiS (ORCPT + 99 others); Thu, 22 Aug 2019 13:38:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:34614 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392985AbfHVRiQ (ORCPT ); Thu, 22 Aug 2019 13:38:16 -0400 Received: from localhost (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CA63620856; Thu, 22 Aug 2019 17:38:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566495495; bh=1RdMJqxneLcxedqNQefzh8Rya2X6L0fY5oAISMkgdPY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=UK+kYTQMVztH4W3mAUZjJ6Kjzmyf8+T37Y+rX1b6xgR3OljbmcU8sKi4O3CD9FBwb 7w4wDl9KlCf6EiTsNr5cw9Zf1hYzs/UViPb/SyU9kkoyD1laLE1JKekqQem8eam1+T kUkpFprQo01LKQHU9Klek5erL00Q980eaPftiDHY= Date: Thu, 22 Aug 2019 20:38:13 +0300 From: Leon Romanovsky To: Haiyang Zhang Cc: "sashal@kernel.org" , "davem@davemloft.net" , "saeedm@mellanox.com" , "eranbe@mellanox.com" , "lorenzo.pieralisi@arm.com" , "bhelgaas@google.com" , "linux-pci@vger.kernel.org" , "linux-hyperv@vger.kernel.org" , "netdev@vger.kernel.org" , KY Srinivasan , Stephen Hemminger , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH net-next,v4, 3/6] net/mlx5: Add wrappers for HyperV PCIe operations Message-ID: <20190822173813.GM29433@mtr-leonro.mtl.com> References: <1566450236-36757-1-git-send-email-haiyangz@microsoft.com> <1566450236-36757-4-git-send-email-haiyangz@microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1566450236-36757-4-git-send-email-haiyangz@microsoft.com> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 22, 2019 at 05:05:47AM +0000, Haiyang Zhang wrote: > From: Eran Ben Elisha > > Add wrapper functions for HyperV PCIe read / write / > block_invalidate_register operations. This will be used as an > infrastructure in the downstream patch for software communication. > > This will be enabled by default if CONFIG_PCI_HYPERV_INTERFACE is set. > > Signed-off-by: Eran Ben Elisha > Signed-off-by: Saeed Mahameed > Signed-off-by: Haiyang Zhang > --- > drivers/net/ethernet/mellanox/mlx5/core/Makefile | 1 + > drivers/net/ethernet/mellanox/mlx5/core/lib/hv.c | 64 ++++++++++++++++++++++++ > drivers/net/ethernet/mellanox/mlx5/core/lib/hv.h | 22 ++++++++ > 3 files changed, 87 insertions(+) > create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/lib/hv.c > create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/lib/hv.h > > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/Makefile b/drivers/net/ethernet/mellanox/mlx5/core/Makefile > index bcf3655..fd32a5b 100644 > --- a/drivers/net/ethernet/mellanox/mlx5/core/Makefile > +++ b/drivers/net/ethernet/mellanox/mlx5/core/Makefile > @@ -45,6 +45,7 @@ mlx5_core-$(CONFIG_MLX5_ESWITCH) += eswitch.o eswitch_offloads.o eswitch_offlo > mlx5_core-$(CONFIG_MLX5_MPFS) += lib/mpfs.o > mlx5_core-$(CONFIG_VXLAN) += lib/vxlan.o > mlx5_core-$(CONFIG_PTP_1588_CLOCK) += lib/clock.o > +mlx5_core-$(CONFIG_PCI_HYPERV_INTERFACE) += lib/hv.o > > # > # Ipoib netdev > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/hv.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/hv.c > new file mode 100644 > index 0000000..cf08d02 > --- /dev/null > +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/hv.c > @@ -0,0 +1,64 @@ > +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB > +// Copyright (c) 2018 Mellanox Technologies > + > +#include > +#include "mlx5_core.h" > +#include "lib/hv.h" > + > +static int mlx5_hv_config_common(struct mlx5_core_dev *dev, void *buf, int len, > + int offset, bool read) > +{ > + int rc = -EOPNOTSUPP; > + int bytes_returned; > + int block_id; > + > + if (offset % HV_CONFIG_BLOCK_SIZE_MAX || len % HV_CONFIG_BLOCK_SIZE_MAX) > + return -EINVAL; > + > + block_id = offset / HV_CONFIG_BLOCK_SIZE_MAX; > + > + rc = read ? > + hyperv_read_cfg_blk(dev->pdev, buf, > + HV_CONFIG_BLOCK_SIZE_MAX, block_id, > + &bytes_returned) : > + hyperv_write_cfg_blk(dev->pdev, buf, > + HV_CONFIG_BLOCK_SIZE_MAX, block_id); > + > + /* Make sure len bytes were read successfully */ > + if (read) > + rc |= !(len == bytes_returned); Unclear what do you want to achieve here, for read == true, "rc" will have result of hyperv_read_cfg_blk(), which can be an error too. It means that your "rc |= .." will give interesting results. > + > + if (rc) { > + mlx5_core_err(dev, "Failed to %s hv config, err = %d, len = %d, offset = %d\n", > + read ? "read" : "write", rc, len, > + offset); > + return rc; > + } > + > + return 0; > +} > + > +int mlx5_hv_read_config(struct mlx5_core_dev *dev, void *buf, int len, > + int offset) > +{ > + return mlx5_hv_config_common(dev, buf, len, offset, true); > +} > + > +int mlx5_hv_write_config(struct mlx5_core_dev *dev, void *buf, int len, > + int offset) > +{ > + return mlx5_hv_config_common(dev, buf, len, offset, false); > +} > + > +int mlx5_hv_register_invalidate(struct mlx5_core_dev *dev, void *context, > + void (*block_invalidate)(void *context, > + u64 block_mask)) > +{ > + return hyperv_reg_block_invalidate(dev->pdev, context, > + block_invalidate); > +} > + > +void mlx5_hv_unregister_invalidate(struct mlx5_core_dev *dev) > +{ > + hyperv_reg_block_invalidate(dev->pdev, NULL, NULL); > +} > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/hv.h b/drivers/net/ethernet/mellanox/mlx5/core/lib/hv.h > new file mode 100644 > index 0000000..f9a4557 > --- /dev/null > +++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/hv.h > @@ -0,0 +1,22 @@ > +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ > +/* Copyright (c) 2019 Mellanox Technologies. */ > + > +#ifndef __LIB_HV_H__ > +#define __LIB_HV_H__ > + > +#if IS_ENABLED(CONFIG_PCI_HYPERV_INTERFACE) The common way to write it if(IS_ENABLED(CONFIG_FOO)) inside the code and #ifdef CONFIG_FOO for header files. > + > +#include > +#include > + > +int mlx5_hv_read_config(struct mlx5_core_dev *dev, void *buf, int len, > + int offset); > +int mlx5_hv_write_config(struct mlx5_core_dev *dev, void *buf, int len, > + int offset); > +int mlx5_hv_register_invalidate(struct mlx5_core_dev *dev, void *context, > + void (*block_invalidate)(void *context, > + u64 block_mask)); > +void mlx5_hv_unregister_invalidate(struct mlx5_core_dev *dev); > +#endif > + > +#endif /* __LIB_HV_H__ */ > -- > 1.8.3.1 >