1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 // Copyright (c) 2018 Mellanox Technologies
4 #include <linux/hyperv.h>
8 static int mlx5_hv_config_common(struct mlx5_core_dev *dev, void *buf, int len,
15 if (offset % HV_CONFIG_BLOCK_SIZE_MAX || len != HV_CONFIG_BLOCK_SIZE_MAX)
18 block_id = offset / HV_CONFIG_BLOCK_SIZE_MAX;
21 hyperv_read_cfg_blk(dev->pdev, buf,
22 HV_CONFIG_BLOCK_SIZE_MAX, block_id,
24 hyperv_write_cfg_blk(dev->pdev, buf,
25 HV_CONFIG_BLOCK_SIZE_MAX, block_id);
27 /* Make sure len bytes were read successfully */
28 if (read && !rc && len != bytes_returned)
32 mlx5_core_err(dev, "Failed to %s hv config, err = %d, len = %d, offset = %d\n",
33 read ? "read" : "write", rc, len,
41 int mlx5_hv_read_config(struct mlx5_core_dev *dev, void *buf, int len,
44 return mlx5_hv_config_common(dev, buf, len, offset, true);
47 int mlx5_hv_write_config(struct mlx5_core_dev *dev, void *buf, int len,
50 return mlx5_hv_config_common(dev, buf, len, offset, false);
53 int mlx5_hv_register_invalidate(struct mlx5_core_dev *dev, void *context,
54 void (*block_invalidate)(void *context,
57 return hyperv_reg_block_invalidate(dev->pdev, context,
61 void mlx5_hv_unregister_invalidate(struct mlx5_core_dev *dev)
63 hyperv_reg_block_invalidate(dev->pdev, NULL, NULL);