0001
0002
0003
0004 #include <linux/hyperv.h>
0005 #include "mlx5_core.h"
0006 #include "lib/hv.h"
0007
0008 static int mlx5_hv_config_common(struct mlx5_core_dev *dev, void *buf, int len,
0009 int offset, bool read)
0010 {
0011 int rc = -EOPNOTSUPP;
0012 int bytes_returned;
0013 int block_id;
0014
0015 if (offset % HV_CONFIG_BLOCK_SIZE_MAX || len != HV_CONFIG_BLOCK_SIZE_MAX)
0016 return -EINVAL;
0017
0018 block_id = offset / HV_CONFIG_BLOCK_SIZE_MAX;
0019
0020 rc = read ?
0021 hyperv_read_cfg_blk(dev->pdev, buf,
0022 HV_CONFIG_BLOCK_SIZE_MAX, block_id,
0023 &bytes_returned) :
0024 hyperv_write_cfg_blk(dev->pdev, buf,
0025 HV_CONFIG_BLOCK_SIZE_MAX, block_id);
0026
0027
0028 if (read && !rc && len != bytes_returned)
0029 rc = -EIO;
0030
0031 if (rc) {
0032 mlx5_core_err(dev, "Failed to %s hv config, err = %d, len = %d, offset = %d\n",
0033 read ? "read" : "write", rc, len,
0034 offset);
0035 return rc;
0036 }
0037
0038 return 0;
0039 }
0040
0041 int mlx5_hv_read_config(struct mlx5_core_dev *dev, void *buf, int len,
0042 int offset)
0043 {
0044 return mlx5_hv_config_common(dev, buf, len, offset, true);
0045 }
0046
0047 int mlx5_hv_write_config(struct mlx5_core_dev *dev, void *buf, int len,
0048 int offset)
0049 {
0050 return mlx5_hv_config_common(dev, buf, len, offset, false);
0051 }
0052
0053 int mlx5_hv_register_invalidate(struct mlx5_core_dev *dev, void *context,
0054 void (*block_invalidate)(void *context,
0055 u64 block_mask))
0056 {
0057 return hyperv_reg_block_invalidate(dev->pdev, context,
0058 block_invalidate);
0059 }
0060
0061 void mlx5_hv_unregister_invalidate(struct mlx5_core_dev *dev)
0062 {
0063 hyperv_reg_block_invalidate(dev->pdev, NULL, NULL);
0064 }